12 string moduleName = rf.check(
"name", Value(
"opcPopulator")).asString().c_str();
13 setName(moduleName.c_str());
15 yInfo() << moduleName <<
" : finding configuration files...";
16 period = rf.check(
"period", Value(0.1)).asDouble();
19 bool isRFVerbose =
false;
20 iCub =
new ICubClient(moduleName,
"opcPopulator",
"client.ini", isRFVerbose);
21 iCub->opc->isVerbose =
false;
24 yInfo() <<
" iCubClient : Some dependencies are not running...";
27 rpc.open((
"/" + moduleName +
"/rpc").c_str());
30 Bottle &bRFInfo = rf.findGroup(
"populateSpecific");
32 X_obj = bRFInfo.check(
"X_obj", Value(-0.4)).asDouble();
33 Y_obj = bRFInfo.check(
"Y_obj", Value(0.5)).asDouble();
34 Z_obj = bRFInfo.check(
"Z_obj", Value(0.1)).asDouble();
35 X_ag = bRFInfo.check(
"X_ag", Value(-0.4)).asDouble();
36 Y_ag = bRFInfo.check(
"Y_ag", Value(0.5)).asDouble();
37 Z_ag = bRFInfo.check(
"Z_ag", Value(0.5)).asDouble();
38 noise = bRFInfo.check(
"noise", Value(5.1)).asDouble();
40 yInfo() <<
"X_obj " << X_obj;
41 yInfo() <<
"Y_obj " << Y_obj;
42 yInfo() <<
"Z_obj " << Z_obj;
43 yInfo() <<
"X_ag " << X_ag;
44 yInfo() <<
"Y_ag " << Y_ag;
45 yInfo() <<
"Z_ag " << Z_ag;
46 yInfo() <<
"noise " << noise;
50 yInfo() <<
"\n \n" <<
"----------------------------------------------" <<
"\n \n" << moduleName <<
" ready ! \n \n ";
66 string helpMessage = string(getName().c_str()) +
70 "populateEntityRandom entity_type entity_name \n" +
71 "populateSpecific \n" +
72 "populateTwoUnknowns \n" +
73 "populateRedBall \n" +
74 "addUnknownEntity entity_type\n" +
75 "setSaliencyEntity entity_name saliency_value\n" +
76 "setValueEntity entity_name value_value\n";
81 if (command.get(0).asString() ==
"quit") {
82 reply.addString(
"quitting");
85 else if (command.get(0).asString() ==
"populateRedBall") {
86 yInfo() <<
" populateRedBall";
87 (populateRedBall()) ? reply.addString(
"populateRedBall done !") : reply.addString(
"populateRedBall failed !");
89 else if (command.get(0).asString() ==
"populateEntityRandom") {
90 yInfo() <<
" populateEntityRandom";
91 (populateEntityRandom(command)) ? reply.addString(
"populateSpecific done !") : reply.addString(
"populateSpecific failed !");
93 else if (command.get(0).asString() ==
"populateSpecific") {
94 yInfo() <<
" populateSpecific";
95 (populateSpecific()) ? reply.addString(
"populateSpecific done !") : reply.addString(
"populateSpecific failed !");
97 else if (command.get(0).asString() ==
"populateTwoUnknowns") {
98 yInfo() <<
" populateTwoUnknowns";
99 (populateTwoUnknowns()) ? reply.addString(
"populated 2 objects !") : reply.addString(
"populateSpecific failed !");
101 else if (command.get(0).asString() ==
"addUnknownEntity") {
102 yInfo() <<
" addUnknownEntity";
103 (addUnknownEntity(command)) ? reply.addString(
"addUnknownEntity done !") : reply.addString(
"addUnknownEntity failed !");
105 else if (command.get(0).asString() ==
"setSaliencyEntity") {
106 yInfo() <<
" setSaliencyEntity";
107 (setAttributeEntity(command, std::mem_fn(&Object::setSaliency))) ? reply.addString(
"setSaliencyEntity done !") : reply.addString(
"setSaliencyEntity failed !");
109 else if (command.get(0).asString() ==
"setValueEntity") {
110 yInfo() <<
" setValueEntity";
111 (setAttributeEntity(command, std::mem_fn(&Object::setValue))) ? reply.addString(
"setValueEntity done !") : reply.addString(
"setValueEntity failed !");
113 else if (command.get(0).asString() ==
"clear") {
114 yInfo() <<
" clearing OPC";
117 reply.addString(
"clearing OPC");
120 yInfo() << helpMessage;
121 reply.addString(
"wrong command");
122 reply.addString(helpMessage);
135 if (bInput.size() != 3)
137 yWarning() <<
" in opcPopulator::populateEntityRandom | wrong number of input";
140 string sName = bInput.get(2).toString();
144 Agent* agent = iCub->opc->addOrRetrieveEntity<
Agent>(sName);
149 agent->
m_color[0] = Random::uniform(0, 80);
150 agent->
m_color[1] = Random::uniform(180, 250);
151 agent->
m_color[2] = Random::uniform(80, 180);
152 iCub->opc->commit(agent);
156 Object* obj = iCub->opc->addOrRetrieveEntity<
Object>(sName);
161 obj->
m_color[0] = Random::uniform(100, 180);
162 obj->
m_color[1] = Random::uniform(0, 80);
163 obj->
m_color[2] = Random::uniform(180, 250);
165 yDebug() <<
"value: " << obj->
m_value;
166 iCub->opc->commit(obj);
170 yError() <<
"Entity type not supported";
180 if (bInput.size() != 2)
182 yWarning() <<
" in opcPopulator::addUnknownEntity | wrong number of input";
186 iCub->opc->checkout();
187 string sName =
"unknown";
188 yInfo() <<
" to be added: " << bInput.get(1).toString() <<
" called " << sName;
193 Agent* agent = iCub->opc->addEntity<
Agent>(sName);
198 agent->
m_color[0] = Random::uniform(0, 80);
199 agent->
m_color[1] = Random::uniform(180, 250);
200 agent->
m_color[2] = Random::uniform(80, 180);
201 iCub->opc->commit(agent);
210 obj->
m_color[0] = Random::uniform(100, 180);
211 obj->
m_color[1] = Random::uniform(0, 80);
212 obj->
m_color[2] = Random::uniform(180, 250);
213 iCub->opc->commit(obj);
217 yError() << bInput.get(1).toString() <<
" unknown kind of entity";
226 if (bInput.size() != 3) {
227 yWarning() <<
" in opcPopulator::setAttributeEntity| wrong number of input";
231 string sName = bInput.get(1).toString();
232 double target = bInput.get(2).asDouble();
234 iCub->opc->checkout();
236 Entity *e = iCub->opc->getEntity(sName);
238 f_setter(dynamic_cast<Object*>(e), target);
241 yError() <<
"Cannot change value of the non-object entity: " << sName;
252 double errorMargin = noise;
254 Object* obj1 = iCub->opc->addOrRetrieveEntity<
Object>(
"bottom_left");
255 obj1->
m_ego_position[0] = X_obj + errorMargin * (Random::uniform() - 0.5);
256 obj1->
m_ego_position[1] = -1.* Y_obj + errorMargin * (Random::uniform() - 0.5);
257 obj1->
m_ego_position[2] = Z_obj + errorMargin * (Random::uniform() - 0.5);
259 obj1->
m_color[0] = Random::uniform(0, 80);
260 obj1->
m_color[1] = Random::uniform(80, 180);
261 obj1->
m_color[2] = Random::uniform(180, 250);
262 iCub->opc->commit(obj1);
264 Object* obj2 = iCub->opc->addOrRetrieveEntity<
Object>(
"top_left");
265 obj2->
m_ego_position[0] = X_ag + errorMargin * (Random::uniform() - 0.5);
266 obj2->
m_ego_position[1] = -1.* Y_ag + errorMargin * (Random::uniform() - 0.5);
267 obj2->
m_ego_position[2] = Z_ag + errorMargin * (Random::uniform() - 0.5);
269 obj2->
m_color[0] = Random::uniform(0, 180);
270 obj2->
m_color[1] = Random::uniform(0, 80);
271 obj2->
m_color[2] = Random::uniform(180, 250);
272 iCub->opc->commit(obj2);
274 Object* obj3 = iCub->opc->addOrRetrieveEntity<
Object>(
"top_right");
275 obj3->
m_ego_position[0] = X_ag + errorMargin * (Random::uniform() - 0.5);
276 obj3->
m_ego_position[1] = Y_ag + errorMargin * (Random::uniform() - 0.5);
277 obj3->
m_ego_position[2] = Z_ag + errorMargin * (Random::uniform() - 0.5);
279 obj3->
m_color[0] = Random::uniform(100, 180);
280 obj3->
m_color[1] = Random::uniform(80, 180);
281 obj3->
m_color[2] = Random::uniform(0, 80);
282 iCub->opc->commit(obj3);
284 Object* obj4 = iCub->opc->addOrRetrieveEntity<
Object>(
"bottom_right");
285 obj4->
m_ego_position[0] = X_obj + errorMargin * (Random::uniform() - 0.5);
286 obj4->
m_ego_position[1] = Y_obj + errorMargin * (Random::uniform() - 0.5);
287 obj4->
m_ego_position[2] = Z_obj + errorMargin * (Random::uniform() - 0.5);
289 obj4->
m_color[0] = Random::uniform(100, 180);
290 obj4->
m_color[1] = Random::uniform(0, 80);
291 obj4->
m_color[2] = Random::uniform(180, 250);
292 iCub->opc->commit(obj4);
301 Object* obj1 = iCub->opc->addOrRetrieveEntity<
Object>(
"unknown_1");
306 obj1->
m_color[0] = Random::uniform(0, 80);
307 obj1->
m_color[1] = Random::uniform(80, 180);
308 obj1->
m_color[2] = Random::uniform(180, 250);
309 iCub->opc->commit(obj1);
311 Object* obj2 = iCub->opc->addOrRetrieveEntity<
Object>(
"unknown_2");
316 obj2->
m_color[0] = Random::uniform(100, 180);
317 obj2->
m_color[1] = Random::uniform(0, 80);
318 obj2->
m_color[2] = Random::uniform(180, 250);
319 iCub->opc->commit(obj2);
327 Object* obj1 = iCub->opc->addOrRetrieveEntity<
Object>(
"red_ball");
336 iCub->opc->commit(obj1);
bool populateSpecific()
populateSpecific populate four objects ("bottom_left", "bottom_right", according to X_obj...
yarp::sig::VectorOf< double > m_color
Mean color of the object (r,g,b) used mainly for debugging/displaying purposes in the iCubGUI...
bool populateEntityRandom(const yarp::os::Bottle &bInput)
populateEntityRandom populate entity from Bottle
Represent any entity that can be stored within the OPC.
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...
bool respond(const yarp::os::Bottle &cmd, yarp::os::Bottle &reply)
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...
bool setAttributeEntity(const yarp::os::Bottle &bInput, std::function< void(icubclient::Object *, double)> f_setter)
setAttributeEntity set an attribute of an object
bool addUnknownEntity(const yarp::os::Bottle &bInput)
addUnknownEntity populate object / agent at pseudo-random location, pseudo-randomly colored ...
bool populateRedBall()
populateRedBall populate object with name "red_ball" at location (-0.4, 0.25, 0.0); is_present=0...
bool populateTwoUnknowns()
populateTwoUnknowns populate two objects: "unknown_1" at (-0.4, 0.25, 0.0) and "unknown_2" at (-0...
double m_value
A measurement of the object subjective value [0,1].
bool configure(yarp::os::ResourceFinder &rf)
std::string entity_type() const
Return the specific type of an entity.