18 #include <yarp/os/all.h> 19 #include <yarp/sig/all.h> 20 #include <yarp/dev/all.h> 37 string moduleName = rf.check(
"name", Value(
"guiUpdater"),
"module name (string)").asString().c_str();
38 string opcName = rf.check(
"OPCname", Value(
"OPC"),
"OPC name (string)").asString().c_str();
40 setName(moduleName.c_str());
42 displaySkeleton = rf.check(
"displaySkeletons");
43 yInfo() <<
"Display skeleton status:" << displaySkeleton;
46 opc->connect(opcName);
47 opc->isVerbose =
false;
48 if(opc->isConnected()) {
49 iCub = opc->addOrRetrieveEntity<
Agent>(
"icub");
51 yError() <<
"Could not connect to OPC, abort";
56 toGui.open(
"/" + getName() +
"/gui:o");
60 toGuiBase.open(
"/" + getName() +
"/guiBase:o");
63 if (!handlerPort.open(
"/" + getName() +
"/rpc")) {
64 yError() << getName() <<
": Unable to open port " << handlerPort.getName();
74 handlerPort.interrupt();
77 toGuiBase.interrupt();
84 handlerPort.interrupt();
94 toGuiBase.interrupt();
104 string helpMessage = string(getName().c_str()) +
105 " commands are: \n" +
112 if (command.get(0).asString()==
"quit") {
113 reply.addString(
"quitting");
116 else if (command.get(0).asString()==
"help") {
117 yInfo() << helpMessage;
118 reply.addString(
"ok");
119 reply.addString(helpMessage);
121 else if (command.get(0).asString()==
"reset") {
124 reply.addString(
"ok");
136 if (opc->isConnected())
139 iCub = opc->addOrRetrieveEntity<
Agent>(
"icub");
145 list<shared_ptr<Entity>> entities = opc->EntitiesCacheCopy();
146 if (oldEntities.size() != entities.size()) {
149 list<shared_ptr<Entity>>::iterator e_new, e_old;
150 for(e_new = entities.begin(), e_old = oldEntities.begin();
151 e_new != entities.end() && e_old != oldEntities.end();
153 if((*e_new)->name() != (*e_old)->name()) {
159 oldEntities = entities;
161 for(
auto& entity : entities) {
162 if( isDisplayable(entity.get()) ) {
165 yError() <<
"Could not cast " << entity->
name();
169 ostringstream guiTag;
170 guiTag << o->
name() <<
"(" << o->
opc_id() <<
")";
173 deleteObject(guiTag.str(), o);
175 if (o->
name() !=
"icub") {
200 cmd.addString(
"delete");
201 cmd.addString(opcTag.c_str());
210 yError() <<
"Could not cast to agent";
213 while (i < a->m_body.m_parts.size())
215 ostringstream opcTagPart;
216 opcTagPart << o->
opc_id() <<
"_" << i;
218 cmd.addString(
"delete");
219 cmd.addString(opcTagPart.str().c_str());
234 Vector inCurrentRootReference = iCub->getSelfRelativePosition(part.second);
236 ostringstream opcTagPart;
237 opcTagPart<<o->
opc_id() <<
"_" << i;
239 cmd.addString(
"object");
240 cmd.addString(opcTagPart.str().c_str());
243 cmd.addDouble(0.05 *1000.0);
244 cmd.addDouble(0.05 *1000.0);
245 cmd.addDouble(0.05 *1000.0);
246 cmd.addDouble(inCurrentRootReference[0] *1000.0);
247 cmd.addDouble(inCurrentRootReference[1] *1000.0);
248 cmd.addDouble(inCurrentRootReference[2] *1000.0);
252 cmd.addInt((
int)o->
m_color[0]);
253 cmd.addInt((
int)o->
m_color[1]);
254 cmd.addInt((
int)o->
m_color[2]);
262 Vector inCurrentRootReference = iCub->getSelfRelativePosition(o->
m_ego_position);
263 ostringstream opcTagPart;
264 opcTagPart << o->
name() <<
"(" << o->
opc_id() <<
")";
266 cmd.addString(
"object");
267 cmd.addString(opcTagPart.str().c_str());
270 cmd.addDouble(0.15 *1000.0);
271 cmd.addDouble(0.15 *1000.0);
272 cmd.addDouble(0.25 *1000.0);
273 cmd.addDouble(inCurrentRootReference[0] *1000.0);
274 cmd.addDouble(inCurrentRootReference[1] *1000.0);
275 cmd.addDouble(inCurrentRootReference[2] *1000.0);
276 cmd.addDouble(0 - iCub->m_ego_orientation[0]);
277 cmd.addDouble(0 - iCub->m_ego_orientation[1]);
278 cmd.addDouble(0 - iCub->m_ego_orientation[2]);
279 cmd.addInt((
int)o->
m_color[0]);
280 cmd.addInt((
int)o->
m_color[1]);
281 cmd.addInt((
int)o->
m_color[2]);
290 Vector inCurrentRootReference = iCub->getSelfRelativePosition(o->
m_ego_position);
292 ostringstream guiTag;
293 guiTag << o->
name() <<
"(" << o->
opc_id() <<
")";
296 cmd.addString(
"object");
297 cmd.addString(guiTag.str());
302 cmd.addDouble(inCurrentRootReference[0] *1000.0);
303 cmd.addDouble(inCurrentRootReference[1] *1000.0);
304 cmd.addDouble(inCurrentRootReference[2] *1000.0);
308 cmd.addInt((
int)o->
m_color[0]);
309 cmd.addInt((
int)o->
m_color[1]);
310 cmd.addInt((
int)o->
m_color[2]);
324 toGuiBase.write(cmd);
332 cmd.addString(
"reset");
int opc_id() const
Return the id of an entity (which has to be unique within the OPC) Typically, modules should employ t...
yarp::sig::VectorOf< double > m_color
Mean color of the object (r,g,b) used mainly for debugging/displaying purposes in the iCubGUI...
Represent any entity that can be stored within the OPC.
yarp::sig::VectorOf< double > m_ego_orientation
Orientation of the Object, in the initial ego-centered reference frame of the agent mainting the OPC ...
virtual bool isType(std::string _entityType) const
Test if an entity is inheriting a given type.
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...
void deleteObject(const string &opcTag, Object *o=nullptr)
Deletes an object with name opcTag from the OPC.
bool isDisplayable(Entity *entity)
Checks whether an Entity can be displayed in the GUI.
void resetGUI()
Send a request to the iCubGUI to remove all items.
Represent any physical entity (including objects and agents) that can be stored within the OPC...
yarp::sig::VectorOf< double > m_ego_position
Position of the Object, in the initial ego-centered reference frame of the agent mainting the OPC (in...
virtual bool isType(std::string _entityType) const
Test if an entity is inheriting a given type.
void addiCub(Agent *a)
Adds the iCub the the iCubGUI.
yarp::sig::VectorOf< double > m_dimensions
Dimensions of the Object, in meters.
void addAgent(Agent *a)
Adds an agent to the iCubGUI.
An OPC client using the datastructures defined within the icub-client library.
void addObject(Object *o)
Adds an object to the iCubGUI.
std::string name() const
Return the name of an entity (which has to be unique within the OPC)
bool respond(const yarp::os::Bottle &command, yarp::os::Bottle &reply)
std::string entity_type() const
Return the specific type of an entity.
std::map< std::string, yarp::sig::VectorOf< double > > m_parts
bool configure(yarp::os::ResourceFinder &rf)