icub-client
tagging.cpp
Go to the documentation of this file.
1 #include "tagging.h"
2 
3 using namespace std;
4 using namespace yarp::os;
5 using namespace icubclient;
6 
8  external_port_name = "/proactiveTagging/rpc";
9  from_sensation_port_name = "/opcSensation/unknown_entities:o";
10 }
11 
12 void Tagging::run(const Bottle &args) {
13  yInfo() << "Tagging::run";
14  yDebug() << "send rpc to proactiveTagging";
15  string type, target;
16  Bottle cmd;
17  Bottle rply;
18  if (args.size()!=0){
19  if(args.size()<=2){
20  yDebug()<<args.toString() << args.size();
21  target = args.get(0).asList()->get(0).asString();
22  type = args.get(0).asList()->get(1).asString();
23  yDebug() << "Object selected: " << target << "Type: "<<type;
24  list<Entity*> lEntities = iCub->opc->EntitiesCache();
25  for (auto& entity: lEntities)
26  {
27  string sName = entity->name();
28  if (sName == target) {
29  yDebug() << "Entity found: "<<target;
30  if (entity->entity_type() == "object")
31  {
32  Object* o = dynamic_cast<Object*>(iCub->opc->getEntity(sName));
33  yInfo() << "I found the entity in the opc: " << sName;
34  if(o && o->m_present==1.0) {
35  return;
36  }
37  }
38  }
39  }
40 
41  yInfo() << "I need to explore by name!";
42  yInfo() << "send rpc to proactiveTagging";
43  cmd.addString("searchingEntity");
44  cmd.addString(type);
45  cmd.addString(target);
46  rpc_out_port.write(cmd,rply);
47  yDebug() << rply.toString();
48  } else {
49  yError()<<"[Tagging::run]! Input not valid!!";
50  }
51  } else {
52  Bottle *sensation = sensation_port_in.read();
53  int id = yarp::os::Random::uniform(0, sensation->size()-1);
54 
55  // If there are unknown agents, prioritise tagging it.
56  for (unsigned int i = 0; i < sensation->size(); i++) {
57  string type = sensation->get(i).asList()->get(0).asString();
58  string target = sensation->get(i).asList()->get(1).asString();
59 
60  if ((type == ICUBCLIENT_OPC_ENTITY_AGENT) && (target == "partner"))
61  {
62  id = i;
63  break;
64  }
65  }
66  type=sensation->get(id).asList()->get(0).asString();
67  target=sensation->get(id).asList()->get(1).asString();
68  yDebug() << "Object selected: " << target << "Type: "<<type;
69  //If there is an unknown object (to see with agents and objects), add it to the rpc_command bottle, and return true
70 
71  cmd.clear();
72  cmd.addString("exploreUnknownEntity");
73  cmd.addString(type);
74  cmd.addString(target);
75  yInfo() << "Proactively tagging:" << cmd.toString();
76  }
77 
78  rpc_out_port.write(cmd, rply);
79 
80  if(type=="bodypart" && target.find("unknown_self") == 0) {
81  iCub->opc->checkout();
82  yarp::sig::VectorOf<double> lHandVec = iCub->getPartnerBodypartLoc(ICUBCLIENT_OPC_BODY_PART_TYPE_HAND_L);
83 
84  iCub->lookAtPartner();
85  if(lHandVec.size()==0) {
86  iCub->say("Although I know our hands look the same I cannot point at your hand because I cannot see it right now.");
87  iCub->home();
88  } else {
89  iCub->say("Look, because our hands look the same I know this is your hand.");
90  iCub->look(lHandVec);
91  iCub->point(lHandVec);
92  iCub->home();
93  }
94  }
95 
96  yInfo() << "Proactive tagging ends";
97 
98 }
void run(const yarp::os::Bottle &args)
Definition: tagging.cpp:12
#define ICUBCLIENT_OPC_BODY_PART_TYPE_HAND_L
Definition: tags.h:79
double m_present
Is the object present in the scene A value of 1.0 means that the object currently is in the scene A v...
Definition: object.h:69
STL namespace.
Represent any physical entity (including objects and agents) that can be stored within the OPC...
Definition: object.h:35
virtual std::string toString() const
Return a human readable description of the entity.
Definition: object.cpp:213
#define ICUBCLIENT_OPC_ENTITY_AGENT
Definition: tags.h:40
void configure()
Definition: tagging.cpp:7