Remind.cpp
Go to the documentation of this file.
00001 #include "Remind.h"
00002 
00003 #include "ActionFactory.h"
00004 
00005 #include "CallGUI.h"
00006 
00007 #include "bwi_kr_execution/AspFluent.h"
00008 
00009 #include <bwi_kr_execution/UpdateFluents.h>
00010 
00011 #include <ros/ros.h>
00012 #include <sound_play/sound_play.h>
00013 
00014 #include <string>
00015 #include <iostream>
00016 
00017 using namespace std;
00018 
00019 namespace bwi_krexec {
00020 
00021 Remind::Remind() : 
00022             person_to_remind(),
00023             meeting(),
00024             room(),
00025             done(false){
00026             }
00027 
00028 ros::Publisher Remind::remind_pub;
00029 bool Remind::pub_set(false);
00030 
00031 void Remind::run() {
00032 
00033   ros::NodeHandle n;
00034   if (!pub_set) { 
00035     remind_pub = n.advertise<sound_play::SoundRequest>("robotsound", 1000);
00036     pub_set = true;
00037   }
00038 
00039   ros::ServiceClient krClient = n.serviceClient<bwi_kr_execution::UpdateFluents> ( "update_fluents" );
00040   krClient.waitForExistence();
00041 
00042   if (remind_pub.getNumSubscribers() == 0) return; //if the subscriber is not connected, sleep
00043 
00044   //speak
00045   sound_play::SoundRequest sound_req;
00046   sound_req.sound = sound_play::SoundRequest::SAY;
00047   sound_req.command = sound_play::SoundRequest::PLAY_ONCE;
00048   std::stringstream ss;
00049   
00050   ss << "Hi " << person_to_remind << "!\n";
00051   ss << "You have a meeting right now.\n";
00052   ss << "Please come to room " << room << " .\n";
00053   sound_req.arg = ss.str();
00054 
00055   remind_pub.publish(sound_req);
00056 
00057   ss.str("");
00058   ss << "Hi " << person_to_remind << "!\n";
00059   ss << "This is a friendly reminder that you have a meeting right now: \n";
00060   ss << "Meeting name: " << meeting << "\n";
00061   ss << "Meeting room: " << room;
00062 
00063   vector<string> options;
00064   options.push_back("Okay, I'll come soon.");
00065 
00066   CallGUI remindPerson("remindPerson", CallGUI::CHOICE_QUESTION, ss.str(), 60.0, options);
00067   remindPerson.run();
00068 
00069   bwi_kr_execution::UpdateFluents uf;
00070   bwi_kr_execution::AspFluent fluent;
00071 
00072   fluent.timeStep = 0;
00073   fluent.variables.push_back(person_to_remind);
00074   fluent.variables.push_back(meeting);
00075 
00076   fluent.name = "inmeeting";
00077 
00078   uf.request.fluents.push_back(fluent);
00079   krClient.call(uf);
00080 
00081   CallGUI thank("thank", CallGUI::DISPLAY,  "Thank you!");
00082   thank.run();
00083 
00084   done = true;
00085 }
00086 
00087 actasp::Action* Remind::cloneAndInit(const actasp::AspFluent& fluent) const {
00088   Remind *newAction = new Remind();
00089   newAction->person_to_remind = fluent.getParameters().at(0);
00090   newAction->meeting = fluent.getParameters().at(1);
00091   newAction->room = fluent.getParameters().at(2);
00092   
00093   return newAction;
00094 }
00095 
00096 std::vector<std::string> Remind::getParameters() const {
00097   vector<string> param;
00098   param.push_back(person_to_remind);
00099   param.push_back(meeting);
00100   param.push_back(room);
00101   return param;
00102 }
00103 
00104 
00105 ActionFactory RemindFactory(new Remind());
00106   
00107 }


bwi_kr_execution
Author(s): Matteo Leonetti, Piyush Khandelwal
autogenerated on Fri Aug 28 2015 10:14:46