21 #include <yarp/os/all.h> 22 #include <yarp/sig/all.h> 39 BufferedPort<Bottle> dumpPort;
53 Recorder() : icubclient(
"actionRecogDataDumper",
"actionRecogDataDumper"), period(0.05), gate(0), logcounter(0) { }
58 agentName=rf.check(
"agent-name",Value(
"partner")).asString();
59 period=rf.check(
"period",Value(0.05)).asDouble();
63 yError() <<
" iCubClient : Some dependencies are not running (OPC?)...";
67 dumpPort.open(
"/actionRecogDataDumper/data/dump:o");
68 rpcPort.open(
"/actionRecogDataDumper/rpc");
88 double dumpTime=Time::now();
89 Bottle &bDump=dumpPort.prepare();
92 bDump.addString(actionTag);
93 bDump.addString(objectTag);
101 if (
Agent *agent=dynamic_cast<Agent*>(e))
103 bDump.addList()=agent->m_body.asBottle();
104 Bottle &bAgent=bDump.addList();
105 bAgent.addString(agent->name());
106 bAgent.addDouble(agent->m_ego_position[0]);
107 bAgent.addDouble(agent->m_ego_position[1]);
108 bAgent.addDouble(agent->m_ego_position[2]);
109 bAgent.addInt(agent->m_present==1.0?1:0);
115 for (list<Entity*>::iterator itEnt=lEntity.begin(); itEnt!=lEntity.end(); itEnt++)
117 string entityName=(*itEnt)->name();
118 string entityType=(*itEnt)->entity_type();
121 if (
Object *
object=dynamic_cast<Object*>(*itEnt))
123 Bottle &bObject=bDump.addList();
124 bObject.addString(object->name());
125 bObject.addDouble(object->m_ego_position[0]);
126 bObject.addDouble(object->m_ego_position[1]);
127 bObject.addDouble(object->m_ego_position[2]);
128 bObject.addInt(object->m_present==1.0?1:0);
135 dumpStamp.update(dumpTime);
136 dumpPort.setEnvelope(dumpStamp);
137 dumpPort.writeStrict();
140 yInfo()<<bDump.toString();
153 int cmd=command.get(0).asVocab();
154 int ack=Vocab::encode(
"ack");
155 int nack=Vocab::encode(
"nack");
157 if (cmd==Vocab::encode(
"start"))
159 if (command.size()>=3)
161 actionTag=command.get(1).asString();
162 objectTag=command.get(2).asString();
164 if (command.size()>=4)
166 int g=command.get(3).asInt();
173 reply.addVocab(nack);
176 else if (cmd==Vocab::encode(
"stop"))
184 else if (cmd==Vocab::encode(
"get"))
187 reply.addString(actionTag);
188 reply.addString(objectTag);
193 return RFModule::respond(command,reply);
201 dumpPort.interrupt();
212 dumpPort.interrupt();
223 if (!yarp.checkNetwork())
225 yError()<<
"YARP network seems unavailable!";
230 rf.configure(argc,argv);
233 return recorder.runModule(rf);
Represent any entity that can be stored within the OPC.
void close()
Close the client ports.
Grants access to high level motor commands (grasp, touch, look, goto, etc) of the robot as well as it...
bool connect(const std::string &opcName="OPC")
Try to connect all functionalities.
Represent any physical entity (including objects and agents) that can be stored within the OPC...
bool respond(const Bottle &command, Bottle &reply)
std::list< Entity * > EntitiesCache() const
Getter of the list of entities stored locally.
Entity * getEntity(const std::string &name, bool forceUpdate=false)
Gets an entity based on its name, but do no create it if it doesn't exist yet.
void close()
Properly closes all ports which were opened.
void interrupt()
Interrupt communications of the client ports.
void checkout(bool updateCache=true)
Poll the OPC for all entities and relations and store them locally.
std::string getPartnerName(bool verbose=true)
Extract the name of the agent interaction with the iCub (present, not iCub nor 'unnamed' partner) ...
bool configure(ResourceFinder &rf)