icub-client
subSystem_SAM.cpp
Go to the documentation of this file.
1 #include <tuple>
2 #include <yarp/os/all.h>
4 
6  if(yarp::os::Network::isConnected(portRPC.getName(), "/sam/rpc:i")) {
7  return true;
8  } else {
9  return yarp::os::Network::connect(portRPC.getName(), "/sam/rpc:i");
10  }
11 }
12 
13 icubclient::SubSystem_SAM::SubSystem_SAM(const std::string &masterName) : SubSystem(masterName), attentionSAM(true) {
14  portRPC.open(("/" + m_masterName + "/sam:rpc").c_str());
16 }
17 
19  portRPC.interrupt();
20  portRPC.close();
21 }
22 
23 bool icubclient::SubSystem_SAM::attentionModulation(const std::string &mode) {
24  if (mode == "stop" || mode == "continue")
25  {
26  yarp::os::Bottle bReq, bResp;
27  bReq.addString("attentionModulation " + mode);
28  portRPC.write(bReq, bResp);
29  if (bResp.toString() == "ack")
30  {
31  if (mode == "stop")
32  {
33  attentionSAM = false;
34  yInfo()<<"Received ack. Attention off";
35  }
36  else if(mode == "continue")
37  {
38  attentionSAM = true;
39  yInfo()<<"Received ack. Attention on";
40  }
41  return true;
42  }
43  else
44  {
45  yError()<<bResp.toString();
46  return false;
47  }
48  }
49  else
50  {
51  yError()<<"mode can be 'stop' or 'continue'. Received: "+ mode;
52  return false;
53  }
54 }
55 
56 yarp::os::Bottle icubclient::SubSystem_SAM::askXLabel(const std::string &model) {
57  yarp::os::Bottle bReq, bResp, bRet;
58  bReq.addString("ask_" + model + "_label");
59  portRPC.write(bReq, bResp);
60  if (bResp.get(0).toString() == "ack")
61  {
62  std::string classification = bResp.get(1).toString();
63  yInfo()<<model + " Classification = " + classification;
64  bRet.addString("true");
65  bRet.addString(classification);
66  return bRet;
67  }
68  else
69  {
70  yError()<<bResp.toString();
71  bRet.addString("false");
72  bRet.addString("nack");
73  return bRet;
74  }
75 }
std::string m_type
Definition: subSystem.h:47
yarp::os::Bottle askXLabel(const std::string &model)
Method to trigger a classification from SAM.
SubSystem_SAM(const std::string &masterName)
Default constructor.
yarp::os::RpcClient portRPC
Definition: subSystem.h:48
#define SUBSYSTEM_SAM
Definition: subSystem_SAM.h:22
Abstract class to handle sub-systems of the icub-client.
Definition: subSystem.h:43
bool attentionModulation(const std::string &mode)
Method to switch attention modes for SAM.
virtual void Close()
Clean up resources.
std::string m_masterName
Definition: subSystem.h:46