diff --git a/CMakeLists.txt b/CMakeLists.txt index d6881c52..4f6dbd61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ set( src/services/robot_config.cpp src/services/set_language.cpp src/services/get_language.cpp + src/services/play_audio_file.cpp ) set( diff --git a/CMakeLists_catkin.txt b/CMakeLists_catkin.txt index 7debd6ae..73234d7d 100644 --- a/CMakeLists_catkin.txt +++ b/CMakeLists_catkin.txt @@ -11,6 +11,7 @@ find_package(catkin COMPONENTS image_transport kdl_parser naoqi_bridge_msgs + nao_interaction_msgs naoqi_libqi naoqi_libqicore robot_state_publisher diff --git a/package.xml b/package.xml index f563441f..0ad4a4e7 100644 --- a/package.xml +++ b/package.xml @@ -19,6 +19,7 @@ image_transport kdl_parser naoqi_bridge_msgs + nao_interaction_msgs naoqi_libqi naoqi_libqicore orocos_kdl @@ -27,6 +28,7 @@ rosconsole rosgraph_msgs sensor_msgs + std_msgs tf2_geometry_msgs tf2_msgs tf2_ros diff --git a/src/helpers/driver_helpers.cpp b/src/helpers/driver_helpers.cpp index 05696871..4ec15176 100644 --- a/src/helpers/driver_helpers.cpp +++ b/src/helpers/driver_helpers.cpp @@ -223,6 +223,20 @@ std::string& getLanguage( const qi::SessionPtr& session ) return language; } +/** Function that plays audio file + */ +std_msgs::Empty& playAudioFile( const qi::SessionPtr& session, nao_interaction_msgs::AudioPlaybackRequest req) +{ + std::cout << "Receiving service call of playing audio file" << std::endl; + try{ + qi::AnyObject p_audio_player = session->service("ALAudioPlayer"); + p_audio_player.call("playFile", "/home/nao/" + req.file_path.data); + } + catch(const std::exception& e){ + std::cout << "Error in executing service of playing audio file" << std::endl; + } +} + } // driver } // helpers } // naoqi diff --git a/src/helpers/driver_helpers.hpp b/src/helpers/driver_helpers.hpp index e2b504fe..4af91e11 100644 --- a/src/helpers/driver_helpers.hpp +++ b/src/helpers/driver_helpers.hpp @@ -23,10 +23,15 @@ #include +#include + #include +#include + #include + namespace naoqi { namespace helpers @@ -42,6 +47,8 @@ bool& setLanguage( const qi::SessionPtr& session, naoqi_bridge_msgs::SetStringRe std::string& getLanguage( const qi::SessionPtr& session ); +std_msgs::Empty& playAudioFile( const qi::SessionPtr& session, nao_interaction_msgs::AudioPlaybackRequest req); + } // driver } // helpers } // naoqi diff --git a/src/naoqi_driver.cpp b/src/naoqi_driver.cpp index 1008180b..ceb6b485 100644 --- a/src/naoqi_driver.cpp +++ b/src/naoqi_driver.cpp @@ -71,6 +71,7 @@ #include "services/robot_config.hpp" #include "services/set_language.hpp" #include "services/get_language.hpp" +#include "services/play_audio_file.hpp" /* * RECORDERS @@ -893,6 +894,7 @@ void Driver::registerDefaultServices() registerService( boost::make_shared("get_robot_config", "/naoqi_driver/get_robot_config", sessionPtr_) ); registerService( boost::make_shared("set_language", "/naoqi_driver/set_language", sessionPtr_) ); registerService( boost::make_shared("get_language", "/naoqi_driver/get_language", sessionPtr_) ); + registerService( boost::make_shared("play audio file", "/naoqi_driver/play_audio_file", sessionPtr_) ); } std::vector Driver::getAvailableConverters() diff --git a/src/services/play_audio_file.cpp b/src/services/play_audio_file.cpp new file mode 100644 index 00000000..70c8d832 --- /dev/null +++ b/src/services/play_audio_file.cpp @@ -0,0 +1,28 @@ +#include "play_audio_file.hpp" +#include "../helpers/driver_helpers.hpp" + +namespace naoqi +{ + namespace service + { + + PlayAudioFileService::PlayAudioFileService( const std::string& name, const std::string& topic, const qi::SessionPtr& session ) + : name_(name), + topic_(topic), + session_(session) + {} + + void PlayAudioFileService::reset( ros::NodeHandle& nh ) + { + service_ = nh.advertiseService(topic_, &PlayAudioFileService::callback, this); + } + + bool PlayAudioFileService::callback( nao_interaction_msgs::AudioPlaybackRequest& req, nao_interaction_msgs::AudioPlaybackResponse& resp ) + { + helpers::driver::playAudioFile(session_, req); + return true; + } + + + } +} diff --git a/src/services/play_audio_file.hpp b/src/services/play_audio_file.hpp new file mode 100644 index 00000000..3a920aa6 --- /dev/null +++ b/src/services/play_audio_file.hpp @@ -0,0 +1,49 @@ +#ifndef PLAY_AUDIO_FILE_SERVICE_HPP +#define PLAY_AUDIO_FILE_SERVICE_HPP + +#include + +#include +#include + +#include +#include + +namespace naoqi +{ + namespace service + { + + class PlayAudioFileService + { + public: + PlayAudioFileService( const std::string& name, const std::string& topic, const qi::SessionPtr& session ); + + ~PlayAudioFileService(){}; + + std::string name() const + { + return name_; + } + + std::string topic() const + { + return topic_; + } + + void reset( ros::NodeHandle& nh ); + + bool callback( nao_interaction_msgs::AudioPlaybackRequest& req, nao_interaction_msgs::AudioPlaybackResponse& resp ); + + + private: + const std::string name_; + const std::string topic_; + + const qi::SessionPtr& session_; + ros::ServiceServer service_; + }; + + } // service +} // naoqi +#endif