message_delivery.cpp
Go to the documentation of this file.
00001 #include "bwi_kr_execution/ExecutePlanAction.h"
00002 #include <actionlib/client/simple_action_client.h>
00003 #include <boost/regex.hpp>
00004 #include <boost/lexical_cast.hpp>
00005 #include <ros/ros.h>
00006 #include <string>
00007 
00008 typedef actionlib::SimpleActionClient<bwi_kr_execution::ExecutePlanAction> Client;
00009 
00010 std::string location;
00011 std::string message;
00012 
00013 int32_t speed;
00014 std::string voice;
00015 int32_t pitch;
00016 
00017 void goToLocation() {  
00018   /*from go_to_location*/
00019   Client client("action_executor/execute_plan", true);
00020   client.waitForServer();
00021     
00022   bwi_kr_execution::ExecutePlanGoal goal;
00023     
00024   bwi_kr_execution::AspRule rule;
00025   bwi_kr_execution::AspFluent fluent;
00026   fluent.name = "not at";
00027     
00028   fluent.variables.push_back(location);
00029    
00030   rule.body.push_back(fluent);
00031   goal.aspGoal.push_back(rule);
00032     
00033   ROS_INFO("sending goal");
00034   client.sendGoal(goal);
00035     
00036   ros::Rate wait_rate(10);
00037   while(ros::ok() && !client.getState().isDone())
00038     wait_rate.sleep();
00039       
00040   if (!client.getState().isDone()) {
00041     ROS_INFO("Canceling goal");
00042     client.cancelGoal();
00043       //and wait for canceling confirmation
00044     for(int i = 0; !client.getState().isDone() && i < 50; ++i)
00045       wait_rate.sleep();
00046   }
00047   if (client.getState() == actionlib::SimpleClientGoalState::ABORTED) {
00048     ROS_INFO("Aborted");
00049   }
00050   else if (client.getState() == actionlib::SimpleClientGoalState::PREEMPTED) {
00051     ROS_INFO("Preempted");
00052   }
00053   else if (client.getState() == actionlib::SimpleClientGoalState::SUCCEEDED) {
00054     ROS_INFO("Succeeded!");
00055   }
00056   else
00057     ROS_INFO("Terminated");
00058 }
00059 
00060 void deliverMessage() { 
00061   std::string string_speed = boost::lexical_cast<std::string>(speed);
00062   std::string string_pitch = boost::lexical_cast<std::string>(pitch);
00063 
00064   boost::regex sanitizeVoice("[^a-z-]");
00065   std::string voiceReplacement = "";
00066   std::string clean_voice = boost::regex_replace(voice, sanitizeVoice, voiceReplacement);
00067 
00068   boost::regex sanitizeMessage("[^a-zA-Z\?!.,0-9-]");
00069   std::string messageReplacement = " ";
00070   std::string clean_message = boost::regex_replace(message, sanitizeMessage, messageReplacement);
00071 
00072   std::string command = "espeak -v " + clean_voice + " -s " 
00073       + string_speed + " -p " + string_pitch + " \"" + clean_message + "\"";
00074   
00075   system(command.c_str());
00076 }
00077 
00078 int main(int argc, char** argv) {
00079   //initialize the node
00080   ros::init(argc, argv, "message_delivery");
00081 
00082   ros::NodeHandle privateNode("~");
00083 
00084   privateNode.param<std::string>("location",location, /*default*/ ""); 
00085   privateNode.param<std::string>("message",message,"");
00086   privateNode.param<int32_t>("speed",speed,160);
00087   privateNode.param<std::string>("voice",voice,"default");
00088   privateNode.param<int32_t>("pitch",pitch,50);
00089 
00090   if (location.compare("") != 0) {
00091     goToLocation();
00092     deliverMessage();
00093   }
00094 }


bwi_tasks
Author(s): Matteo Leonetti, Shiqi Zhang
autogenerated on Thu Jun 6 2019 17:58:00