From c269bffbfa3dbaf9b149c8181cff38ab83dfd665 Mon Sep 17 00:00:00 2001 From: Kanae Kochigami Date: Thu, 8 Feb 2018 17:11:18 +0900 Subject: [PATCH] add fading/ resetting leds services --- CMakeLists.txt | 2 + src/helpers/driver_helpers.cpp | 18 +++++++++ src/helpers/driver_helpers.hpp | 8 ++++ src/naoqi_driver.cpp | 4 ++ src/services/fade_leds.cpp | 45 +++++++++++++++++++++++ src/services/fade_leds.hpp | 67 ++++++++++++++++++++++++++++++++++ src/services/reset_leds.cpp | 46 +++++++++++++++++++++++ src/services/reset_leds.hpp | 67 ++++++++++++++++++++++++++++++++++ 8 files changed, 257 insertions(+) create mode 100644 src/services/fade_leds.cpp create mode 100644 src/services/fade_leds.hpp create mode 100644 src/services/reset_leds.cpp create mode 100644 src/services/reset_leds.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d6881c52..57d8565b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,8 @@ set( src/services/robot_config.cpp src/services/set_language.cpp src/services/get_language.cpp + src/services/fade_leds.cpp + src/services/reset_leds.cpp ) set( diff --git a/src/helpers/driver_helpers.cpp b/src/helpers/driver_helpers.cpp index 05696871..950a0f28 100644 --- a/src/helpers/driver_helpers.cpp +++ b/src/helpers/driver_helpers.cpp @@ -223,6 +223,24 @@ std::string& getLanguage( const qi::SessionPtr& session ) return language; } +/** Function that fades eye leds + */ +std_msgs::Empty& fadeLeds( const qi::SessionPtr& session, naoqi_bridge_msgs::FadeLedsRequest req ) +{ + std::cout << "Receiving service call of fading leds" << std::endl; + qi::AnyObject p_leds = session->service("ALLeds"); + p_leds.call("fadeRGB", req.fade_rgb.led_name, req.fade_rgb.color.r, req.fade_rgb.color.g, req.fade_rgb.color.b, req.fade_rgb.fade_duration.toSec()); +} + +/** Function that reset leds color + */ +std_msgs::Empty& resetLeds( const qi::SessionPtr& session, naoqi_bridge_msgs::SetStringRequest req ) +{ + std::cout << "Receiving service call of resetting leds" << std::endl; + qi::AnyObject p_leds = session->service("ALLeds"); + p_leds.call("reset", req.data); +} + } // driver } // helpers } // naoqi diff --git a/src/helpers/driver_helpers.hpp b/src/helpers/driver_helpers.hpp index e2b504fe..3ce0b83e 100644 --- a/src/helpers/driver_helpers.hpp +++ b/src/helpers/driver_helpers.hpp @@ -23,8 +23,12 @@ #include +#include + #include +#include + #include namespace naoqi @@ -42,6 +46,10 @@ bool& setLanguage( const qi::SessionPtr& session, naoqi_bridge_msgs::SetStringRe std::string& getLanguage( const qi::SessionPtr& session ); +std_msgs::Empty& fadeLeds( const qi::SessionPtr& session, naoqi_bridge_msgs::FadeLedsRequest req ); + +std_msgs::Empty& resetLeds( const qi::SessionPtr& session, naoqi_bridge_msgs::SetStringRequest req ); + } // driver } // helpers } // naoqi diff --git a/src/naoqi_driver.cpp b/src/naoqi_driver.cpp index ff98f1d4..9cf7e8f9 100644 --- a/src/naoqi_driver.cpp +++ b/src/naoqi_driver.cpp @@ -71,6 +71,8 @@ #include "services/robot_config.hpp" #include "services/set_language.hpp" #include "services/get_language.hpp" +#include "services/fade_leds.hpp" +#include "services/reset_leds.hpp" /* * RECORDERS @@ -893,6 +895,8 @@ void Driver::registerDefaultServices() registerService( boost::make_shared("robot config service", "/naoqi_driver/get_robot_config", sessionPtr_) ); registerService( boost::make_shared("set language service", "/naoqi_driver/set_language", sessionPtr_) ); registerService( boost::make_shared("get language service", "/naoqi_driver/get_language", sessionPtr_) ); + registerService( boost::make_shared("fade leds service", "/naoqi_driver/fade_leds", sessionPtr_) ); + registerService( boost::make_shared("reset leds service", "/naoqi_driver/reset_leds", sessionPtr_) ); } std::vector Driver::getAvailableConverters() diff --git a/src/services/fade_leds.cpp b/src/services/fade_leds.cpp new file mode 100644 index 00000000..6750af50 --- /dev/null +++ b/src/services/fade_leds.cpp @@ -0,0 +1,45 @@ +/* + * Copyright 2018 Aldebaran + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "fade_leds.hpp" +#include "../helpers/driver_helpers.hpp" + +namespace naoqi +{ +namespace service +{ + + FadeLedsService::FadeLedsService( const std::string& name, const std::string& topic, const qi::SessionPtr& session ) + : name_(name), + topic_(topic), + session_(session) + {} + + void FadeLedsService::reset( ros::NodeHandle& nh ) + { + service_ = nh.advertiseService(topic_, &FadeLedsService::callback, this); + } + + bool FadeLedsService::callback( naoqi_bridge_msgs::FadeLedsRequest& req, naoqi_bridge_msgs::FadeLedsResponse& resp ) + { + helpers::driver::fadeLeds(session_, req); + return true; + } + + +} +} diff --git a/src/services/fade_leds.hpp b/src/services/fade_leds.hpp new file mode 100644 index 00000000..9db1bf87 --- /dev/null +++ b/src/services/fade_leds.hpp @@ -0,0 +1,67 @@ +/* + * Copyright 2018 Aldebaran + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef FADE_LEDS_SERVICE_HPP +#define FADE_LEDS_SERVICE_HPP + +#include + +#include +#include + +#include +#include + +namespace naoqi +{ +namespace service +{ + +class FadeLedsService +{ +public: + FadeLedsService( const std::string& name, const std::string& topic, const qi::SessionPtr& session ); + + ~FadeLedsService(){}; + + std::string name() const + { + return name_; + } + + std::string topic() const + { + return topic_; + } + + void reset( ros::NodeHandle& nh ); + + bool callback( naoqi_bridge_msgs::FadeLedsRequest& req, naoqi_bridge_msgs::FadeLedsResponse& resp ); + + +private: + const std::string name_; + const std::string topic_; + + const qi::SessionPtr& session_; + ros::ServiceServer service_; +}; + +} // service +} // naoqi +#endif diff --git a/src/services/reset_leds.cpp b/src/services/reset_leds.cpp new file mode 100644 index 00000000..ad288cf1 --- /dev/null +++ b/src/services/reset_leds.cpp @@ -0,0 +1,46 @@ +/* + * Copyright 2018 Aldebaran + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "reset_leds.hpp" +#include "../helpers/driver_helpers.hpp" + +namespace naoqi +{ +namespace service +{ + + ResetLedsService::ResetLedsService( const std::string& name, const std::string& topic, const qi::SessionPtr& session ) + : name_(name), + topic_(topic), + session_(session) + {} + + void ResetLedsService::reset( ros::NodeHandle& nh ) + { + service_ = nh.advertiseService(topic_, &ResetLedsService::callback, this); + } + + bool ResetLedsService::callback( naoqi_bridge_msgs::SetStringRequest& req, naoqi_bridge_msgs::SetStringResponse& resp ) + { + helpers::driver::resetLeds(session_, req); + resp.success = true; + return true; + } + + +} +} diff --git a/src/services/reset_leds.hpp b/src/services/reset_leds.hpp new file mode 100644 index 00000000..5d2d7fde --- /dev/null +++ b/src/services/reset_leds.hpp @@ -0,0 +1,67 @@ +/* + * Copyright 2018 Aldebaran + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef RESET_LEDS_SERVICE_HPP +#define RESET_LEDS_SERVICE_HPP + +#include + +#include +#include + +#include +#include + +namespace naoqi +{ +namespace service +{ + +class ResetLedsService +{ +public: + ResetLedsService( const std::string& name, const std::string& topic, const qi::SessionPtr& session ); + + ~ResetLedsService(){}; + + std::string name() const + { + return name_; + } + + std::string topic() const + { + return topic_; + } + + void reset( ros::NodeHandle& nh ); + + bool callback( naoqi_bridge_msgs::SetStringRequest& req, naoqi_bridge_msgs::SetStringResponse& resp ); + + +private: + const std::string name_; + const std::string topic_; + + const qi::SessionPtr& session_; + ros::ServiceServer service_; +}; + +} // service +} // naoqi +#endif