11 bool isRFVerbose =
false;
12 iCub =
new ICubClient(
"opcSensation",
"sensation",
"client.ini",isRFVerbose);
13 iCub->opc->isVerbose =
false;
14 while (!iCub->connect())
16 cout<<
"iCubClient : Some dependencies are not running..."<<endl;
20 homeoPort.open(
"/opcSensation/toHomeo:o");
21 unknown_entities_port.open(
"/opcSensation/unknown_entities:o");
22 known_entities_port.open(
"/opcSensation/known_entities:o");
24 yInfo() <<
"Configuration done.";
30 Bottle res = handleEntities();
32 if (!Network::isConnected(
"/opcSensation/toHomeo:o",
"/homeostasis/fromSensations:i"))
33 Network::connect(
"/opcSensation/toHomeo:o",
"/homeostasis/fromSensations:i");
34 yarp::os::Bottle &bot = homeoPort.prepare();
38 key.addString(
"unknown");
39 key.addInt(res.get(0).asInt());
42 key.addString(
"known");
43 key.addInt(res.get(2).asInt());
48 yarp::os::Bottle &unkn = unknown_entities_port.prepare();
50 unkn.append(*res.get(1).asList());
51 unknown_entities_port.write();
53 yarp::os::Bottle &kn = known_entities_port.prepare();
55 kn.append(*res.get(3).asList());
56 known_entities_port.write();
59 void OpcSensation::addToEntityList(Bottle& list,
string type,
string name) {
63 list.addList() = item;
66 Bottle OpcSensation::handleEntities()
68 LockGuard lg(m_entity_bottles);
69 iCub->opc->checkout();
70 list<Entity*> lEntities = iCub->opc->EntitiesCache();
79 for (
auto& entity : lEntities)
81 if(entity->entity_type() ==
"object") {
88 if (entity->name().find(
"unknown") == 0) {
89 if (entity->entity_type() ==
"object")
93 addToEntityList(up_entities, entity->entity_type(), entity->name());
95 addToEntityList(u_entities, entity->entity_type(), entity->name());
97 else if(entity->entity_type() ==
"bodypart") {
98 addToEntityList(u_entities, entity->entity_type(), entity->name());
99 addToEntityList(up_entities, entity->entity_type(), entity->name());
102 else if (entity->entity_type() ==
"object")
106 addToEntityList(kp_entities, entity->entity_type(), entity->name());
108 addToEntityList(k_entities, entity->entity_type(), entity->name());
110 else if (entity->name() ==
"partner" && entity->entity_type() ==
"agent") {
113 addToEntityList(up_entities, entity->entity_type(), entity->name());
115 addToEntityList(u_entities, entity->entity_type(), entity->name());
118 if (entity->entity_type() ==
"bodypart")
123 addToEntityList(u_entities, entity->entity_type(), entity->name());
124 addToEntityList(up_entities, entity->entity_type(), entity->name());
130 if (o && o->m_present == 1.0)
132 addToEntityList(p_entities, entity->entity_type(), entity->name());
137 out.addInt(up_entities.size());
138 out.addList()=up_entities;
139 out.addInt(kp_entities.size());
140 out.addList()=kp_entities;
147 LockGuard lg(m_entity_bottles);
149 bool check_position=
false;
151 if (property ==
"known")
155 else if (property ==
"unknown")
159 else if (property ==
"present")
170 yDebug()<<
"Checking object position"<<name<<property;
171 for (
unsigned int i=0;i<b.size();i++)
174 if (b.get(i).asList()->get(0).asString()==property)
176 yDebug() <<
"check_position, name==any, return 1";
180 if (b.get(i).asList()->get(1).asString()==name && b.get(i).asList()->get(0).asString()==property)
182 yDebug() <<
"check_position, name!=any, return 1 " << b.toString();
187 yDebug() <<
"check_position, return 0";
192 yDebug() <<
"not check_position, name==any, return 1";
195 yDebug() <<
"not check_position, name==any, return 0";
199 for (
unsigned int i=0;i<b.size();i++)
201 if (b.get(i).asList()->get(1).asString()==name)
203 yDebug() <<
"not check_position, name!=any, return 1";
207 yDebug() <<
"not check_position, name!=any, return 0";
214 unknown_entities_port.interrupt();
215 unknown_entities_port.close();
216 homeoPort.interrupt();
218 known_entities_port.interrupt();
219 known_entities_port.close();
std::string objectAreaAsString() const
int get_property(std::string name, std::string property)
get_property quickly answers a boolean query
Grants access to high level motor commands (grasp, touch, look, goto, etc) of the robot as well as it...
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...
int m_tactile_number
Tactile number of the represented body part.
Represent any physical entity (including objects and agents) that can be stored within the OPC...
void publish()
send sensation data to port
Represents a body part of the robot.