icub-client
recognitionOrder.cpp
Go to the documentation of this file.
1 #include "recognitionOrder.h"
2 
3 using namespace std;
4 using namespace yarp::os;
5 
7  from_sensation_port_name = "None";
8 
9  homeoPort = "/homeostasis/rpc";
10 
11  port_to_homeo_name = "/"+behaviorName+"/toHomeo:o";
12  port_to_homeo.open(port_to_homeo_name);
13 }
14 
15 void RecognitionOrder::run(const Bottle &/*args*/) {
16  yInfo() << "recognitionOrder::run";
17 
18  if (!Network::isConnected(port_to_homeo_name,homeoPort)){
19  if (!Network::connect(port_to_homeo_name,homeoPort)){
20  yWarning()<<"Port to Homeostasis not available. Could not freeze the drives...";
21  }
22  }
23  if (Network::isConnected(port_to_homeo_name,homeoPort)){
24  yInfo()<<"freezing drives";
25  Bottle cmd;
26  Bottle rply;
27  cmd.addString("freeze");
28  cmd.addString("all");
29 
30  port_to_homeo.write(cmd, rply);
31  }
32 
33  yDebug() << "send rpc to SAM";
34  string toSay;
35  if (iCub->getSAMClient())
36  {
37  Bottle SAMreply = iCub->getSAMClient()->askXLabel("action");
38  if(SAMreply.get(0).asString() == "true") {
39  toSay = SAMreply.get(1).asString();
40  } else {
41  toSay = "Sorry. I did not recognise that action.";
42  }
43  } else {
44  toSay = "Sorry. It seems like I have difficulties recognising actions today.";
45  }
46  iCub->lookAtPartner();
47  iCub->say(toSay);
48  iCub->home();
49  yInfo() << "Recognising ends";
50 
51  if (!manual && Network::isConnected(port_to_homeo_name, homeoPort)){
52  yInfo()<<"unfreezing drives";
53  Bottle cmd;
54  Bottle rply;
55  cmd.addString("unfreeze");
56  cmd.addString("all");
57  port_to_homeo.write(cmd, rply);
58  }
59 }
void run(const yarp::os::Bottle &args)
STL namespace.