144 double start_time = yarp::os::Time::now();
148 double current_time = yarp::os::Time::now();
158 _dd =
new PolyDriver(options);
159 bool connected =_dd->isValid();
162 if (connected)
break;
165 if (current_time-start_time > 60.0)
167 yError(
"It is not possible to instantiate the device driver. I tried %d times!\n", trials);
171 yarp::os::Time::delay(5);
173 yWarning(
"Unable to connect the device driver, trying again...\n");
177 IEncoders *encs =
nullptr;
178 IControlMode *ctrlMode =
nullptr;
179 IImpedanceControl *imp =
nullptr;
180 ITorqueControl *tqs =
nullptr;
183 ok =
ok & _dd->view(encs);
184 ok =
ok & _dd->view(ctrlMode);
185 ok =
ok & _dd->view(imp);
186 ok =
ok & _dd->view(tqs);
189 yError(
"One or more devices has not been viewed\nreturning...");
198 string fwdSlash =
"/";
201 name =
"gravityCompensator";
203 if (rf.check(
"period"))
204 rate = rf.find(
"period").asInt32();
207 if (rf.check(
"rate"))
209 yError (
"'rate' parameter is deprecated. Use 'period' instead");
215 if (rf.check(
"robot"))
216 robot_name = rf.find(
"robot").asString();
217 else robot_name =
"icub";
221 if (rf.check(
"headV2"))
223 yInfo(
"'headV2' option found. Using icubV2 head kinematics.\n");
227 if (rf.check(
"headV2.6"))
229 yInfo(
"'headV2.6' option found. Using icubV2.6 head kinematics.\n");
234 if (rf.check(
"headV2.7"))
236 yInfo(
"'headV2.7' option found. Using icubV2.7 head kinematics.\n");
242 if (rf.check(
"no_legs"))
245 yInfo(
"'no_legs' option found. Legs will be disabled.\n");
248 if (rf.check(
"no_left_arm"))
250 left_arm_enabled=
false;
251 yInfo(
"'no_left_arm' option found. Left arm will be disabled.\n");
254 if (rf.check(
"no_right_arm"))
256 right_arm_enabled=
false;
257 yInfo(
"'no_right_arm' option found. Right arm will be disabled.\n");
260 if (rf.check(
"no_torso_legs"))
262 torso_enabled=
false;
264 yInfo(
"no_torso_legs' option found. Torso and legs will be disabled.\n");
266 if (rf.check(
"no_torso"))
268 torso_enabled=
false;
269 yInfo(
"'no_torso' option found. Torso will be disabled.\n");
272 if (rf.check(
"no_head"))
275 yInfo(
"'no_head' option found. Head will be disabled.\n");
280 OptionsHead.put(
"device",
"remote_controlboard");
281 OptionsHead.put(
"local",
"/gravityCompensator/head/client");
282 OptionsHead.put(
"remote",
"/"+robot_name+
"/head");
286 yError(
"unable to create head device driver...quitting\n");
291 if (left_arm_enabled)
293 OptionsLeftArm.put(
"device",
"remote_controlboard");
294 OptionsLeftArm.put(
"local",
"/gravityCompensator/left_arm/client");
295 OptionsLeftArm.put(
"remote",
"/"+robot_name+
"/left_arm");
298 yError(
"unable to create left arm device driver...quitting\n");
303 if (right_arm_enabled)
305 OptionsRightArm.put(
"device",
"remote_controlboard");
306 OptionsRightArm.put(
"local",
"/gravityCompensator/right_arm/client");
307 OptionsRightArm.put(
"remote",
"/"+robot_name+
"/right_arm");
310 yError(
"unable to create right arm device driver...quitting\n");
317 OptionsLeftLeg.put(
"device",
"remote_controlboard");
318 OptionsLeftLeg.put(
"local",
"/gravityCompensator/left_leg/client");
319 OptionsLeftLeg.put(
"remote",
"/"+robot_name+
"/left_leg");
322 yError(
"unable to create left leg device driver...quitting\n");
326 OptionsRightLeg.put(
"device",
"remote_controlboard");
327 OptionsRightLeg.put(
"local",
"/gravityCompensator/right_leg/client");
328 OptionsRightLeg.put(
"remote",
"/"+robot_name+
"/right_leg");
331 yError(
"unable to create right leg device driver...quitting\n");
338 OptionsTorso.put(
"device",
"remote_controlboard");
339 OptionsTorso.put(
"local",
"/gravityCompensator/torso/client");
340 OptionsTorso.put(
"remote",
"/"+robot_name+
"/torso");
344 yError(
"unable to create torso device driver...quitting\n");
349 yInfo(
"device driver created\n");
351 rpcPort.open(
"/"+name+
"/rpc");
355 std::string wholeBodyName =
"wholeBodyDynamics";
356 if (rf.check(
"wholebody_name"))
358 wholeBodyName = rf.find(
"wholebody_name").asString();
359 yInfo(
"'wholeBodyName' option found. Using /%s prefix for connections.\n", wholeBodyName.c_str());
363 bool inertial_enabled=
true;
364 if (rf.check(
"no_inertial"))
366 inertial_enabled=
false;
367 yInfo(
"'no_inertial' option found. Disabling inertial measurment.\n");
372 g_comp =
new gravityCompensatorThread(wholeBodyName, rate, dd_left_arm, dd_right_arm, dd_head, dd_left_leg, dd_right_leg, dd_torso, icub_type, inertial_enabled);
373 yInfo(
"ft thread istantiated...\n");
375 yInfo(
"thread started\n");
378 if (rf.check(
"gravity_on"))
382 if (rf.check(
"gravity_off"))
386 if (rf.check(
"external_on"))
390 if (rf.check(
"external_off"))
402 bool respond(
const Bottle& command, Bottle& reply)
override
404 reply.addVocab32(
"many");
405 reply.addString(
"Available commands:");
406 reply.addString(
"calib all");
409 string helpMessage = getName() +
410 " commands are: \n" +
411 "help to display this message\n" +
412 "gravity_on to enable the gravity compensation \n" +
413 "gravity_off to disbale the gravity compensation \n" +
414 "external_on to enable the external input torque \n" +
415 "external_off to disable the external input torque \n";
418 if (command.get(0).asString()==
"help")
421 reply.addVocab32(
"many");
422 reply.addString(
" commands are: \n" );
423 reply.addString(helpMessage.c_str());
425 else if (command.get(0).asString()==
"gravity_on")
430 reply.addString(
"gravity compensation on");
433 else if (command.get(0).asString()==
"gravity_off")
438 reply.addString(
"gravity compensation off");
441 else if (command.get(0).asString()==
"external_on")
446 reply.addString(
"external input on");
449 else if (command.get(0).asString()==
"external_off")
454 reply.addString(
"external input off");
459 reply.addString(
"unknown command. type help.");