20 #include <iCub/utils.h>
32 if(this->getOutputCount()==0)
36 Bottle bAsk,bGet,bReply;
37 bAsk.addVocab32(
"ask");
38 Bottle &bTempAsk=bAsk.addList().addList();
39 bTempAsk.addString(
"name");
40 bTempAsk.addString(
"==");
41 bTempAsk.addString(obj_name);
43 this->
write(bAsk,bReply);
45 if(bReply.size()==0 ||
46 bReply.get(0).asVocab32()!=Vocab32::encode(
"ack") ||
47 bReply.get(1).asList()->check(
"id")==
false ||
48 bReply.get(1).asList()->find(
"id").asList()->size()==0)
51 bGet.addVocab32(
"get");
52 Bottle &bTempGet=bGet.addList().addList();
53 bTempGet.addString(
"id");
54 bTempGet.addInt32(bReply.get(1).asList()->find(
"id").asList()->get(0).asInt32());
56 this->
write(bGet,bReply);
58 if(bReply.size()==0 || bReply.get(0).asVocab32()!=Vocab32::encode(
"ack"))
61 if(!bReply.get(1).asList()->check(
"position_2d_left") && !bReply.get(1).asList()->check(
"position_2d_right"))
67 if(bReply.get(1).asList()->check(
"position_2d_left"))
69 Bottle *bStereo=bReply.get(1).asList()->find(
"position_2d_left").asList();
71 stereo[0]=0.5*(bStereo->get(0).asFloat64()+bStereo->get(2).asFloat64());
72 stereo[1]=0.5*(bStereo->get(1).asFloat64()+bStereo->get(3).asFloat64());
75 if(bReply.get(1).asList()->check(
"position_2d_right"))
77 Bottle *bStereo=bReply.get(1).asList()->find(
"position_2d_right").asList();
79 stereo[2]=0.5*(bStereo->get(0).asFloat64()+bStereo->get(2).asFloat64());
80 stereo[3]=0.5*(bStereo->get(1).asFloat64()+bStereo->get(3).asFloat64());
90 if(this->getOutputCount()==0)
94 Bottle bAsk,bGet,bReply;
95 bAsk.addVocab32(
"ask");
96 Bottle &bTempAsk=bAsk.addList().addList();
97 bTempAsk.addString(
"name");
98 bTempAsk.addString(
"==");
99 bTempAsk.addString(obj_name);
101 this->
write(bAsk,bReply);
103 if(bReply.size()==0 ||
104 bReply.get(0).asVocab32()!=Vocab32::encode(
"ack") ||
105 bReply.get(1).asList()->check(
"id")==
false ||
106 bReply.get(1).asList()->find(
"id").asList()->size()==0)
109 bGet.addVocab32(
"get");
110 Bottle &bTempGet=bGet.addList().addList();
111 bTempGet.addString(
"id");
112 bTempGet.addInt32(bReply.get(1).asList()->find(
"id").asList()->get(0).asInt32());
114 this->
write(bGet,bReply);
116 if(bReply.size()==0 || bReply.get(0).asVocab32()!=Vocab32::encode(
"ack"))
120 if(!bReply.get(1).asList()->check(
"position_3d"))
125 if(bReply.get(1).asList()->check(
"position_3d"))
127 Bottle *bX=bReply.get(1).asList()->find(
"position_3d").asList();
129 for(
int i=0; i<bX->size(); i++)
130 x[i]=bX->get(i).asFloat64();
142 if(this->getOutputCount()==0)
146 Bottle bAsk,bGet,bReply;
147 bAsk.addVocab32(
"ask");
148 Bottle &bTempAsk=bAsk.addList().addList();
149 bTempAsk.addString(
"name");
150 bTempAsk.addString(
"==");
151 bTempAsk.addString(obj_name);
153 this->
write(bAsk,bReply);
155 if(bReply.size()==0 ||
156 bReply.get(0).asVocab32()!=Vocab32::encode(
"ack") ||
157 bReply.get(1).asList()->check(
"id")==
false ||
158 bReply.get(1).asList()->find(
"id").asList()->size()==0)
161 bGet.addVocab32(
"get");
162 Bottle &bTempGet=bGet.addList().addList();
163 bTempGet.addString(
"id");
164 bTempGet.addInt32(bReply.get(1).asList()->find(
"id").asList()->get(0).asInt32());
166 this->
write(bGet,bReply);
169 if(bReply.size()==0 || bReply.get(0).asVocab32()!=Vocab32::encode(
"ack"))
173 if(bReply.get(1).asList()->check(
"kinematic_offset_left"))
175 kinematic_offset[
LEFT].resize(3);
176 Bottle *bCartesianOffset=bReply.get(1).asList()->find(
"kinematic_offset_left").asList();
177 for(
int i=0; i<bCartesianOffset->size(); i++)
178 kinematic_offset[
LEFT][i]=bCartesianOffset->get(i).asFloat64();
181 if(bReply.get(1).asList()->check(
"kinematic_offset_right"))
183 kinematic_offset[
RIGHT].resize(3);
184 Bottle *bCartesianOffset=bReply.get(1).asList()->find(
"kinematic_offset_right").asList();
185 for(
int i=0; i<bCartesianOffset->size(); i++)
186 kinematic_offset[
RIGHT][i]=bCartesianOffset->get(i).asFloat64();
196 if(this->getOutputCount()==0)
200 Bottle bAsk,bSet,bReply;
201 bAsk.addVocab32(
"ask");
202 Bottle &bTempAsk=bAsk.addList().addList();
203 bTempAsk.addString(
"name");
204 bTempAsk.addString(
"==");
205 bTempAsk.addString(obj_name);
207 this->
write(bAsk,bReply);
209 if(bReply.size()==0 ||
210 bReply.get(0).asVocab32()!=Vocab32::encode(
"ack") ||
211 bReply.get(1).asList()->check(
"id")==
false ||
212 bReply.get(1).asList()->find(
"id").asList()->size()==0)
215 bSet.addVocab32(
"set");
216 Bottle &bTempSet=bSet.addList();
218 Bottle &bTempSetId=bTempSet.addList();
219 bTempSetId.addString(
"id");
220 bTempSetId.addInt32(bReply.get(1).asList()->find(
"id").asList()->get(0).asInt32());
223 Bottle &bTempSetKinematicOffsetLeft=bTempSet.addList();
224 bTempSetKinematicOffsetLeft.addString(
"kinematic_offset_left");
225 Bottle &bTempSetVectorLeft=bTempSetKinematicOffsetLeft.addList();
226 for(
size_t i=0; i<kinematic_offset[
LEFT].size(); i++)
227 bTempSetVectorLeft.addFloat64(kinematic_offset[
LEFT][i]);
230 Bottle &bTempSetKinematicOffsetRight=bTempSet.addList();
231 bTempSetKinematicOffsetRight.addString(
"kinematic_offset_right");
232 Bottle &bTempSetVectorRight=bTempSetKinematicOffsetRight.addList();
233 for(
size_t i=0; i<kinematic_offset[
RIGHT].size(); i++)
234 bTempSetVectorRight.addFloat64(kinematic_offset[
RIGHT][i]);
236 this->
write(bSet,bReply);
238 return bReply.get(0).asVocab32()==Vocab32::encode(
"ack");
248 if(this->getOutputCount()==0)
252 Bottle bAsk,bGet,bReply;
253 bAsk.addVocab32(
"ask");
254 Bottle &bTempAsk=bAsk.addList().addList();
255 bTempAsk.addString(
"entity");
256 bTempAsk.addString(
"==");
257 bTempAsk.addString(
"table");
259 this->
write(bAsk,bReply);
261 if(bReply.size()==0 ||
262 bReply.get(0).asVocab32()!=Vocab32::encode(
"ack") ||
263 bReply.get(1).asList()->check(
"id")==
false ||
264 bReply.get(1).asList()->find(
"id").asList()->size()==0)
267 bGet.addVocab32(
"get");
268 Bottle &bTempGet=bGet.addList().addList();
269 bTempGet.addString(
"id");
270 bTempGet.addInt32(bReply.get(1).asList()->find(
"id").asList()->get(0).asInt32());
272 this->
write(bGet,bReply);
274 if(bReply.size()==0 || bReply.get(0).asVocab32()!=Vocab32::encode(
"ack"))
277 if(!bReply.get(1).asList()->check(
"height"))
280 table_height=bReply.get(1).asList()->find(
"height").asFloat64();
288 if(this->getOutputCount()==0)
293 bAsk.addVocab32(
"ask");
294 Bottle &bTempAsk=bAsk.addList().addList();
295 bTempAsk.addString(
"entity");
296 bTempAsk.addString(
"==");
297 bTempAsk.addString(
"table");
299 this->
write(bAsk,bReply);
301 if(bReply.size()==0 ||
302 bReply.get(0).asVocab32()!=Vocab32::encode(
"ack") ||
303 bReply.get(1).asList()->check(
"id")==
false)
307 if(bReply.get(1).asList()->find(
"id").asList()->size()==0)
310 bAdd.addVocab32(
"add");
311 Bottle &bTempAdd=bAdd.addList();
313 Bottle &bEntity=bTempAdd.addList();
314 bEntity.addString(
"entity"); bEntity.addString(
"table");
316 Bottle &bHeight=bTempAdd.addList();
317 bHeight.addString(
"height"); bHeight.addFloat64(table_height);
319 this->
write(bAdd,bReply);
324 bSet.addVocab32(
"set");
325 Bottle &bTempSet=bSet.addList();
327 Bottle &bTempSetId=bTempSet.addList();
328 bTempSetId.addString(
"id");
329 bTempSetId.addInt32(bReply.get(1).asList()->find(
"id").asList()->get(0).asInt32());
331 Bottle &bTableHeight=bTempSet.addList();
332 bTableHeight.addString(
"height");
333 bTableHeight.addFloat64(table_height);
335 this->
write(bSet,bReply);
338 return bReply.get(0).asVocab32()==Vocab32::encode(
"ack");
344 if(this->getOutputCount()==0)
348 bAdd.addVocab32(
"add");
349 Bottle &bTempAdd=bAdd.addList();
351 Bottle &bEntity=bTempAdd.addList();
352 bEntity.addString(
"entity"); bEntity.addString(
"action");
354 Bottle &bName=bTempAdd.addList();
355 bName.addString(
"name"); bName.addString(act_name);
356 Bottle &bTraj= bTempAdd.addList();
357 bTraj.addString(
"trajectory"); bTraj.addList()=*trajectory;
359 this->
write(bAdd,bReply);
360 return bReply.get(0).asVocab32()==Vocab32::encode(
"ack");
364 if(this->getOutputCount()==0)
367 Bottle bAsk,bGet,bReply;
368 bAsk.addVocab32(
"ask");
369 Bottle &bTempAsk=bAsk.addList().addList();
370 bTempAsk.addString(
"name");
371 bTempAsk.addString(
"==");
372 bTempAsk.addString(act_name);
374 this->
write(bAsk,bReply);
376 if(bReply.size()==0 ||
377 bReply.get(0).asVocab32()!=Vocab32::encode(
"ack") ||
378 bReply.get(1).asList()->check(
"id")==
false ||
379 bReply.get(1).asList()->find(
"id").asList()->size()==0)
382 bGet.addVocab32(
"get");
383 Bottle &bTempGet=bGet.addList().addList();
384 bTempGet.addString(
"id");
385 bTempGet.addInt32(bReply.get(1).asList()->find(
"id").asList()->get(0).asInt32());
387 this->
write(bGet,bReply);
389 if(bReply.size()==0 || bReply.get(0).asVocab32()!=Vocab32::encode(
"ack"))
392 if(!bReply.get(1).asList()->check(
"trajectory"))
395 *trajectory = *(bReply.get(1).asList()->find(
"trajectory").asList());
bool getStereoPosition(const string &obj_name, Vector &stereo)
bool getKinematicOffsets(const string &obj_name, Vector *kinematic_offset)
bool getTableHeight(double &table_height)
bool setTableHeight(const double table_height)
bool getCartesianPosition(const string &obj_name, Vector &x)
bool getAction(const string &act_name, Bottle *trajectory)
bool setKinematicOffsets(const string &obj_name, const Vector *kinematic_offset)
bool setAction(const string &act_name, const Bottle *trajectory)
bool write(const std::string filename, const FullRegulation ®)