27 #include <yarp/os/Time.h>
28 #include <yarp/math/Math.h>
29 #include <yarp/math/Rand.h>
42 bool MotorThread::checkOptions(
const Bottle &options,
const string ¶meter)
45 for (
int i=0; i<options.size(); i++)
47 if(options.get(i).asString()==parameter)
60 extForceThresh=initializer.check(
"external_force_thresh",Value(1e9)).asFloat64();
61 samplingRate=initializer.check(
"subsampling_rate",Value(500.0)).asFloat64();
63 damping=initializer.check(
"damping",Value(1e9)).asFloat64();
64 inertia=initializer.check(
"inertia",Value(1e9)).asFloat64();
75 bool MotorThread::storeContext(
const int arm)
79 if (action[arm]!=NULL)
81 ICartesianControl *ctrl=NULL;
82 if (action[arm]->getCartesianIF(ctrl))
86 ctrl->storeContext(&action_context[arm]);
97 bool MotorThread::restoreContext(
const int arm)
101 if (action[arm]!=NULL)
103 ICartesianControl *ctrl=NULL;
104 if (action[arm]->getCartesianIF(ctrl))
109 ctrl->restoreContext(action_context[arm]);
120 bool MotorThread::deleteContext(
const int arm)
124 if (action[arm]!=NULL)
126 ICartesianControl *ctrl=NULL;
127 if (action[arm]->getCartesianIF(ctrl))
131 ctrl->deleteContext(action_context[arm]);
144 if (action==&action[
LEFT])
145 return storeContext(
LEFT);
146 else if (action==&action[
RIGHT])
147 return storeContext(
RIGHT);
155 if (action==&action[
LEFT])
156 return restoreContext(
LEFT);
157 else if (action==&action[
RIGHT])
158 return restoreContext(
RIGHT);
166 if (action==&action[
LEFT])
167 return deleteContext(
LEFT);
168 else if (action==&action[
RIGHT])
169 return deleteContext(
RIGHT);
175 int MotorThread::checkArm(
int arm)
184 int MotorThread::checkArm(
int arm, Vector &xd,
const bool applyOffset)
194 xd[0]+=currentKinematicOffset[armInUse][0];
195 xd[1]+=currentKinematicOffset[armInUse][1];
196 xd[2]+=currentKinematicOffset[armInUse][2];
199 return checkArm(arm);
205 InteractionModeEnum mode=(turn_on?VOCAB_IM_COMPLIANT:VOCAB_IM_STIFF);
206 for(
int i=0; i<5; i++)
208 if(action[
LEFT]!=NULL)
209 int_mode_arm[
LEFT]->setInteractionMode(i,mode);
210 if(action[
RIGHT]!=NULL)
211 int_mode_arm[
RIGHT]->setInteractionMode(i,mode);
214 if (int_mode_torso!=NULL)
216 InteractionModeEnum modes[3]={VOCAB_IM_STIFF, VOCAB_IM_STIFF, VOCAB_IM_STIFF};
217 int_mode_torso->setInteractionModes(modes);
220 status_impedance_on=turn_on;
227 if(action[arm]==NULL)
235 for(
int i=0; i<4; i++)
236 done=
done && ctrl_mode_arm[arm]->setControlMode(i,VOCAB_CM_TORQUE);
238 for(
int i=0; i<3; i++)
239 done=
done && int_mode_torso->setInteractionMode(i,VOCAB_IM_COMPLIANT);
242 done=setImpedance(status_impedance_on);
251 return setStereoToCartesianMode(mode,reply);
261 if (Network::isConnected(disparityPort.getName(),
"/stereoDisparity/rpc"))
264 string tmp=
"[Stereo -> Cartesian]: Disparity";
265 yInfo(
"%s",
tmp.c_str());
266 reply.addString(
tmp);
271 string tmp=
"[Stereo -> Cartesian]: Homography";
272 yInfo(
"%s",
tmp.c_str());
273 reply.addString(
tmp);
280 if (neuralNetworkAvailable)
283 string tmp=
"[Stereo -> Cartesian]: Neural Net";
284 yInfo(
"%s",
tmp.c_str());
285 reply.addString(
tmp);
290 string tmp=
"[Stereo -> Cartesian]: Homography";
291 yInfo(
"%s",
tmp.c_str());
292 reply.addString(
tmp);
300 string tmp=
"[Stereo -> Cartesian]: Homography";
301 yInfo(
"%s",
tmp.c_str());
302 reply.addString(
tmp);
308 if(!bKinOffsets.find(
"left").asList()->check(Vocab32::decode(modeS2C)))
310 Bottle &bKinMode=bKinOffsets.find(
"left").asList()->addList();
311 bKinMode.addString(Vocab32::decode(modeS2C));
312 Bottle &bKinVec=bKinMode.addList();
313 for(
int i=0; i<3; i++)
314 bKinVec.addFloat64(0.0);
317 Bottle *bKinLeft=bKinOffsets.find(
"left").asList()->find(Vocab32::decode(modeS2C)).asList();
318 for(
int i=0; i<3; i++)
319 defaultKinematicOffset[
LEFT][i]=bKinLeft->get(i).asFloat64();
322 if(!bKinOffsets.find(
"right").asList()->check(Vocab32::decode(modeS2C)))
324 Bottle &bKinMode=bKinOffsets.find(
"right").asList()->addList();
325 bKinMode.addString(Vocab32::decode(modeS2C));
326 Bottle &bKinVec=bKinMode.addList();
327 for(
int i=0; i<3; i++)
328 bKinVec.addFloat64(0.0);
331 Bottle *bKinRight=bKinOffsets.find(
"right").asList()->find(Vocab32::decode(modeS2C)).asList();
332 for(
int i=0; i<3; i++)
333 defaultKinematicOffset[
RIGHT][i]=bKinRight->get(i).asFloat64();
344 currentKinematicOffset[
LEFT]=defaultKinematicOffset[
LEFT];
345 currentKinematicOffset[
RIGHT]=defaultKinematicOffset[
RIGHT];
348 if(!found && bTarget!=NULL && bTarget->check(
"cartesian") && bTarget->find(
"cartesian").asList()->size()>=3)
350 Bottle *bCartesian=bTarget->find(
"cartesian").asList();
352 for(
int i=0; i<bCartesian->size(); i++)
353 xd.push_back(bCartesian->get(i).asFloat64());
358 if(!found && bTarget!=NULL && bTarget->check(
"name"))
359 if(opcPort.getCartesianPosition(bTarget->find(
"name").asString(),xd))
362 if(!found && bTarget!=NULL && bTarget->check(
"stereo"))
364 Bottle *bStereo=bTarget->find(
"stereo").asList();
369 for(
int i=0; i<bStereo->size(); i++)
370 stereo.push_back(bStereo->get(i).asFloat64());
372 found=stereoToCartesian(stereo,xd);
376 if(found && bTarget!=NULL && bTarget->check(
"name"))
377 opcPort.getKinematicOffsets(bTarget->find(
"name").asString(),currentKinematicOffset);
390 yWarning(
"System is busy!");
400 ok=stereoToCartesianHomography(stereo,xd);
406 ok=stereoToCartesianDisparity(stereo,xd);
412 ok=stereoToCartesianNetwork(stereo,xd);
421 bool MotorThread::loadExplorationPoses(
const string &file_name)
424 optExpl.fromConfigFile(rf.findFile(file_name));
426 if(!optExpl.check(
"torso") ||!optExpl.check(
"hand") ||!optExpl.check(
"head"))
429 Bottle &tmpTorso=optExpl.findGroup(
"torso");
430 for(
int i=1; i<tmpTorso.size(); i++)
432 Bottle *b=tmpTorso.get(i).asList();
434 for(
int j=0; j<b->size(); j++)
435 v[j]=b->get(j).asFloat64();
436 pos_torsoes.push_back(v);
439 Bottle &tmpHand=optExpl.findGroup(
"hand");
440 for(
int i=1; i<tmpHand.size(); i++)
442 Bottle *b=tmpHand.get(i).asList();
444 for(
int j=0; j<b->size(); j++)
445 v[j]=b->get(j).asFloat64();
446 handPoses.push_back(v);
449 Bottle &tmpHead=optExpl.findGroup(
"head");
450 for(
int i=1; i<tmpHead.size(); i++)
452 Bottle *b=tmpHead.get(i).asList();
454 for(
int j=0; j<b->size(); j++)
455 v[j]=b->get(j).asFloat64();
456 headPoses.push_back(v);
463 Vector MotorThread::eye2root(
const Vector &
out,
bool forehead)
475 Vector eyePos,eyeOrient;
477 ctrl_gaze->getHeadPose(eyePos,eyeOrient);
479 ctrl_gaze->getLeftEyePose(eyePos,eyeOrient);
481 Matrix
T=axis2dcm(eyeOrient);
482 T.setSubcol(eyePos,0,3);
484 Vector
root=
T*out_hom;
490 if (
root[2]<=table_height)
491 root[2]=table_height;
502 bool MotorThread::stereoToCartesianHomography(
const Vector &stereo, Vector &xd)
505 if(stereo[2*dominant_eye]==0.0 && stereo[2*dominant_eye+1]==0.0)
507 if(stereo[2*(1-dominant_eye)]==0.0 && stereo[2*(1-dominant_eye)+1]==0.0)
510 eye_in_use=1-dominant_eye;
513 eye_in_use=dominant_eye;
516 px[0]=stereo[2*eye_in_use];
517 px[1]=stereo[2*eye_in_use+1];
519 ctrl_gaze->get3DPointOnPlane(eye_in_use,px,table,xd);
525 bool MotorThread::stereoToCartesianDisparity(
const Vector &stereo, Vector &xd)
528 bEye.addFloat64(stereo[0]);
529 bEye.addFloat64(stereo[1]);
534 disparityPort.write(bEye,bX);
536 while(bX.size()==0 || bX.get(2).asFloat64()<0.0 );
538 if(bX.size()!=0 && bX.get(2).asFloat64()>0.0 )
541 xd[0]=bX.get(0).asFloat64();
542 xd[1]=bX.get(1).asFloat64();
543 xd[2]=bX.get(2).asFloat64();
546 xd=eye2root(xd,
false);
552 bool MotorThread::stereoToCartesianNetwork(
const Vector &stereo, Vector &xd)
554 if(stereo.size()!=4 || stereo[0]==0.0 || stereo[1]==0.0 || stereo[2]==0.0 || stereo[3]==0.0)
558 enc_head->getEncoders(
h.data());
569 xd=eye2root(net.predict(in),
true);
575 Vector MotorThread::randomDeployOffset()
578 offset[0]=Rand::scalar(-0.01,0.0);
579 offset[1]=Rand::scalar(-0.02,0.02);
586 bool MotorThread::loadKinematicOffsets()
588 ifstream kin_fin(rf.findFile(kinematics_file).c_str());
589 if (!kin_fin.is_open())
591 yError(
"Kinematics file not found!");
596 strstr<<kin_fin.rdbuf();
598 bKinOffsets.fromString(strstr.str());
600 if (!bKinOffsets.check(
"table_height"))
602 Bottle &bKinList=bKinOffsets.addList();
603 bKinList.addString(
"table_height");
604 bKinList.addFloat64(-0.1);
607 table_height=bKinOffsets.find(
"table_height").asFloat64();
610 table[3]=-table_height;
613 table_height+=table_height_tolerance;
615 if (!bKinOffsets.check(
"left"))
617 Bottle &bKinList=bKinOffsets.addList();
618 bKinList.addString(
"left");
623 if (!bKinOffsets.check(
"right"))
625 Bottle &bKinList=bKinOffsets.addList();
626 bKinList.addString(
"right");
633 defaultKinematicOffset[
LEFT].resize(3);
634 defaultKinematicOffset[
RIGHT].resize(3);
640 bool MotorThread::saveKinematicOffsets()
642 string fileName=rf.getHomeContextPath();
643 fileName+=
"/"+kinematics_file;
644 ofstream kin_fout(fileName.c_str());
645 if (!kin_fout.is_open())
647 yError(
"Unable to open file '%s'!",fileName.c_str());
652 kin_fout<<bKinOffsets.toString()<<endl;
659 bool MotorThread::getGeneralOptions(Bottle &b)
661 if (Bottle *pB=b.find(
"home_fixation_point").asList())
663 homeFixCartType=
true;
669 homeFixCartType=(v.asString()==
"xyz");
673 homeFix.resize(pB->size()-offs);
674 for (
size_t i=0; i<homeFix.length(); i++)
675 homeFix[i]=pB->get(offs+i).asFloat64();
680 if (Bottle *pB=b.find(
"reach_above_displacement").asList())
682 reachAboveDisp.resize(pB->size());
684 for (
int i=0; i<pB->size(); i++)
685 reachAboveDisp[i]=pB->get(i).asFloat64();
690 if (Bottle *pB=b.find(
"grasp_above_relief").asList())
692 graspAboveRelief.resize(pB->size());
694 for (
int i=0; i<pB->size(); i++)
695 graspAboveRelief[i]=pB->get(i).asFloat64();
700 if (Bottle *pB=b.find(
"push_above_relief").asList())
702 pushAboveRelief.resize(pB->size());
704 for (
int i=0; i<pB->size(); i++)
705 pushAboveRelief[i]=pB->get(i).asFloat64();
710 go_up_distance=b.check(
"go_up",Value(0.1)).asFloat64();
711 table_height_tolerance=b.find(
"table_height_tolerance").asFloat64();
717 bool MotorThread::getArmOptions(Bottle &b,
const int &arm)
719 if (Bottle *pB=b.find(
"home_position").asList())
721 homePos[arm].resize(pB->size());
723 for (
int i=0; i<pB->size(); i++)
724 homePos[arm][i]=pB->get(i).asFloat64();
729 if (Bottle *pB=b.find(
"home_orientation").asList())
731 homeOrient[arm].resize(pB->size());
733 for (
int i=0; i<pB->size(); i++)
734 homeOrient[arm][i]=pB->get(i).asFloat64();
739 if (Bottle *pB=b.find(
"reach_side_displacement").asList())
741 reachSideDisp[arm].resize(pB->size());
743 for (
int i=0; i<pB->size(); i++)
744 reachSideDisp[arm][i]=pB->get(i).asFloat64();
749 if (Bottle *pB=b.find(
"reach_above_orientation").asList())
751 reachAboveOrient[arm].resize(pB->size());
753 for (
int i=0; i<pB->size(); i++)
754 reachAboveOrient[arm][i]=pB->get(i).asFloat64();
759 if (Bottle *pB=b.find(
"reach_above_calib_table").asList())
761 reachAboveCata[arm].resize(pB->size());
763 for (
int i=0; i<pB->size(); i++)
764 reachAboveCata[arm][i]=pB->get(i).asFloat64();
769 if (Bottle *pB=b.find(
"reach_side_orientation").asList())
771 reachSideOrient[arm].resize(pB->size());
773 for (
int i=0; i<pB->size(); i++)
774 reachSideOrient[arm][i]=pB->get(i).asFloat64();
779 if (Bottle *pB=b.find(
"deploy_position").asList())
781 deployPos[arm].resize(pB->size());
783 for (
int i=0; i<pB->size(); i++)
784 deployPos[arm][i]=pB->get(i).asFloat64();
789 if (Bottle *pB=b.find(
"deploy_orientation").asList())
791 deployOrient[arm].resize(pB->size());
792 for (
int i=0; i<pB->size(); i++)
793 deployOrient[arm][i]=pB->get(i).asFloat64();
796 deployOrient[arm]=reachAboveOrient[arm];
798 if (Bottle *pB=b.find(
"draw_near_position").asList())
800 drawNearPos[arm].resize(pB->size());
802 for (
int i=0; i<pB->size(); i++)
803 drawNearPos[arm][i]=pB->get(i).asFloat64();
808 if (Bottle *pB=b.find(
"draw_near_orientation").asList())
810 drawNearOrient[arm].resize(pB->size());
812 for (
int i=0; i<pB->size(); i++)
813 drawNearOrient[arm][i]=pB->get(i).asFloat64();
818 if (Bottle *pB=b.find(
"shift_position").asList())
820 shiftPos[arm].resize(pB->size());
822 for (
int i=0; i<pB->size(); i++)
823 shiftPos[arm][i]=pB->get(i).asFloat64();
827 shiftPos[arm].resize(3);
831 if (Bottle *pB=b.find(
"expect_position").asList())
833 expectPos[arm].resize(pB->size());
835 for (
int i=0; i<pB->size(); i++)
836 expectPos[arm][i]=pB->get(i).asFloat64();
841 if (Bottle *pB=b.find(
"expect_orientation").asList())
843 expectOrient[arm].resize(pB->size());
845 for (
int i=0; i<pB->size(); i++)
846 expectOrient[arm][i]=pB->get(i).asFloat64();
851 if (Bottle *pB=b.find(
"tool_take_position").asList())
853 takeToolPos[arm].resize(pB->size());
855 for (
int i=0; i<pB->size(); i++)
856 takeToolPos[arm][i]=pB->get(i).asFloat64();
861 if (Bottle *pB=b.find(
"tool_take_orientation").asList())
863 takeToolOrient[arm].resize(pB->size());
865 for (
int i=0; i<pB->size(); i++)
866 takeToolOrient[arm][i]=pB->get(i).asFloat64();
871 extForceThresh[arm]=b.check(
"external_forces_thresh",Value(0.0)).asFloat64();
873 string modelFile(
"grasp_model_");
874 modelFile+=(arm==
LEFT?
"left":
"right");
876 graspFile[arm]=b.check(
"grasp_model_file",Value(modelFile)).asString();
882 void MotorThread::close()
896 delete drv_arm[
LEFT];
899 delete drv_arm[
RIGHT];
902 delete drv_ctrl_gaze;
908 delete action[
RIGHT];
911 disparityPort.interrupt();
912 disparityPort.
close();
917 wrenchPort[
LEFT].interrupt();
918 wrenchPort[
RIGHT].interrupt();
919 wrenchPort[
LEFT].close();
920 wrenchPort[
RIGHT].close();
928 Bottle bMotor=rf.findGroup(
"motor");
931 yError(
"Motor part is missing!");
935 string name=rf.find(
"name").asString();
936 string robot=bMotor.check(
"robot",Value(
"icub")).asString();
937 string partUsed=bMotor.check(
"part_used",Value(
"both_arms")).asString();
938 int actionprimitives_layer=bMotor.check(
"actionprimitives_layer",Value(2)).asInt32();
939 setPeriod((
double)bMotor.check(
"thread_period",Value(100)).asInt32()/1000.0);
941 actions_path=bMotor.check(
"actions",Value(
"actions")).asString();
943 double eyesTrajTime=bMotor.check(
"eyes_traj_time",Value(1.0)).asFloat64();
944 double neckTrajTime=bMotor.check(
"neck_traj_time",Value(2.0)).asFloat64();
946 double kp=bMotor.check(
"stereo_kp",Value(0.001)).asFloat64();
947 double ki=bMotor.check(
"stereo_ki",Value(0.001)).asFloat64();
948 double kd=bMotor.check(
"stereo_kd",Value(0.0)).asFloat64();
950 stereo_track=bMotor.check(
"stereo_track",Value(
"on")).asString()==
"on";
951 dominant_eye=(bMotor.check(
"dominant_eye",Value(
"left")).asString()==
"left")?
LEFT:
RIGHT;
953 Bottle *neckPitchRange=bMotor.find(
"neck_pitch_range").asList();
954 Bottle *neckRollRange=bMotor.find(
"neck_roll_range").asList();
957 disparityPort.open(
"/"+name+
"/disparity:io");
958 wbdPort.open(
"/"+name+
"/wbd:rpc");
959 wrenchPort[
LEFT].open(
"/"+name+
"/left/wrench:o");
960 wrenchPort[
RIGHT].open(
"/"+name+
"/right/wrench:o");
963 Property optHead(
"(device remote_controlboard)");
964 Property optLeftArm(
"(device remote_controlboard)");
965 Property optRightArm(
"(device remote_controlboard)");
966 Property optTorso(
"(device remote_controlboard)");
967 Property optctrl_gaze(
"(device gazecontrollerclient)");
969 optHead.put(
"remote",
"/"+robot+
"/head");
970 optHead.put(
"local",
"/"+name+
"/head");
972 optLeftArm.put(
"remote",
"/"+robot+
"/left_arm");
973 optLeftArm.put(
"local",
"/"+name+
"/left_arm");
975 optRightArm.put(
"remote",
"/"+robot+
"/right_arm");
976 optRightArm.put(
"local",
"/"+name+
"/right_arm");
978 optTorso.put(
"remote",
"/"+robot+
"/torso");
979 optTorso.put(
"local",
"/"+name+
"/torso");
981 optctrl_gaze.put(
"remote",
"/iKinGazeCtrl");
982 optctrl_gaze.put(
"local",
"/"+name+
"/gaze");
984 drv_head=
new PolyDriver;
985 drv_torso=
new PolyDriver;
986 drv_ctrl_gaze=
new PolyDriver;
987 if (!drv_head->open(optHead) ||
988 !drv_torso->open(optTorso) ||
989 !drv_ctrl_gaze->open(optctrl_gaze))
996 drv_head->view(enc_head);
997 drv_torso->view(enc_torso);
998 drv_torso->view(pos_torso);
999 drv_torso->view(vel_torso);
1000 drv_torso->view(ctrl_mode_torso);
1001 drv_torso->view(int_mode_torso);
1002 drv_torso->view(ctrl_impedance_torso);
1004 if(partUsed==
"both_arms" || partUsed==
"left_arm")
1006 drv_arm[
LEFT]=
new PolyDriver;
1007 if(!drv_arm[
LEFT]->open(optLeftArm))
1013 drv_arm[
LEFT]->view(ctrl_mode_arm[
LEFT]);
1014 drv_arm[
LEFT]->view(int_mode_arm[
LEFT]);
1015 drv_arm[
LEFT]->view(ctrl_impedance_arm[
LEFT]);
1016 drv_arm[
LEFT]->view(pos_arm[
LEFT]);
1017 drv_arm[
LEFT]->view(enc_arm[
LEFT]);
1019 Vector vels(16),accs(16);
1020 vels=20.0; accs=6000.0;
1021 pos_arm[
LEFT]->setRefSpeeds(vels.data());
1022 pos_arm[
LEFT]->setRefAccelerations(accs.data());
1025 if(partUsed==
"both_arms" || partUsed==
"right_arm")
1027 drv_arm[
RIGHT]=
new PolyDriver;
1028 if(!drv_arm[
RIGHT]->open(optRightArm))
1036 drv_arm[
RIGHT]->view(ctrl_impedance_arm[
RIGHT]);
1040 Vector vels(16),accs(16);
1041 vels=20.0; accs=6000.0;
1042 pos_arm[
RIGHT]->setRefSpeeds(vels.data());
1043 pos_arm[
RIGHT]->setRefAccelerations(accs.data());
1046 drv_ctrl_gaze->view(ctrl_gaze);
1048 Vector vels(3),accs(3);
1049 vels=5.0; accs=6000.0;
1050 pos_torso->setRefSpeeds(vels.data());
1051 pos_torso->setRefAccelerations(accs.data());
1056 int initial_gaze_context;
1057 ctrl_gaze->storeContext(&initial_gaze_context);
1059 ctrl_gaze->setTrackingMode(
false);
1060 ctrl_gaze->setEyesTrajTime(eyesTrajTime);
1061 ctrl_gaze->setNeckTrajTime(neckTrajTime);
1065 Bottle &bKp=stereoOpt.addList();
1066 bKp.addString(
"Kp");
1067 Bottle &bKpVal=bKp.addList();
1068 bKpVal.addFloat64(kp);
1070 Bottle &bKi=stereoOpt.addList();
1071 bKi.addString(
"Ki");
1072 Bottle &bKiVal=bKi.addList();
1073 bKiVal.addFloat64(ki);
1075 Bottle &bKd=stereoOpt.addList();
1076 bKd.addString(
"Kd");
1077 Bottle &bKdVal=bKd.addList();
1078 bKdVal.addFloat64(kd);
1080 Bottle &bTs=stereoOpt.addList();
1081 bTs.addString(
"Ts");
1082 bTs.addFloat64(0.05);
1084 Bottle &bDominantEye=stereoOpt.addList();
1085 bDominantEye.addString(
"dominantEye");
1086 dominant_eye==
LEFT?bDominantEye.addString(
"left"):bDominantEye.addString(
"right");
1088 ctrl_gaze->setStereoOptions(stereoOpt);
1091 if(neckPitchRange!=NULL && neckPitchRange->size()==1)
1093 double neckPitchBlock=neckPitchRange->get(0).asFloat64();
1094 ctrl_gaze->blockNeckPitch(neckPitchBlock);
1096 else if(neckPitchRange!=NULL && neckPitchRange->size()>1)
1098 double neckPitchMin=neckPitchRange->get(0).asFloat64();
1099 double neckPitchMax=neckPitchRange->get(1).asFloat64();
1100 ctrl_gaze->bindNeckPitch(neckPitchMin,neckPitchMax);
1102 if(neckRollRange!=NULL && neckRollRange->size()==1)
1104 double neckRollBlock=neckRollRange->get(0).asFloat64();
1105 ctrl_gaze->blockNeckRoll(neckRollBlock);
1107 else if(neckRollRange!=NULL && neckRollRange->size()>1)
1109 double neckRollMin=neckRollRange->get(0).asFloat64();
1110 double neckRollMax=neckRollRange->get(1).asFloat64();
1111 ctrl_gaze->bindNeckRoll(neckRollMin,neckRollMax);
1114 if (bMotor.check(
"block_eyes"))
1116 ctrl_gaze->blockEyes(bMotor.find(
"block_eyes").asFloat64());
1117 ctrl_gaze->waitMotionDone();
1121 ctrl_gaze->storeContext(&gaze_context);
1122 ctrl_gaze->restoreContext(initial_gaze_context);
1123 ctrl_gaze->deleteContext(initial_gaze_context);
1124 gazeUnderControl=
false;
1129 string exploration_name=bMotor.find(
"exploration_poses").asString();
1130 if(!loadExplorationPoses(exploration_name))
1132 yError(
"Error while loading exploration poses!");
1138 Property netOptions;
1139 string net_name=bMotor.find(
"net").asString();
1140 netOptions.fromConfigFile(rf.findFile(net_name));
1141 if(net.configure(netOptions))
1143 yInfo(
"Neural network configured successfully");
1144 neuralNetworkAvailable=
true;
1148 yError(
"Error while loading neural network!");
1149 neuralNetworkAvailable=
false;
1153 if(!getGeneralOptions(bMotor))
1155 yError(
"Error extracting general options!");
1161 bArm[
LEFT]=rf.findGroup(
"left_arm");
1162 bArm[
RIGHT]=rf.findGroup(
"right_arm");
1166 for (
int i=1; i<bMotor.size(); i++)
1168 Bottle *pB=bMotor.get(i).asList();
1171 if(pB->get(0).asString()==
"hand_sequences_file")
1173 string hand_seq_name=bMotor.find(
"hand_sequences_file").asString();
1174 option.put(
"hand_sequences_file",rf.findFile(hand_seq_name));
1177 option.put(pB->get(0).asString(),pB->get(1));
1181 yError(
"Error: invalid option!");
1188 vector<double> torso_stiffness(0),torso_damping(0);
1189 Bottle *bImpedanceTorsoStiff=bMotor.find(
"impedence_torso_stiffness").asList();
1190 Bottle *bImpedanceTorsoDamp=bMotor.find(
"impedence_torso_damping").asList();
1192 for(
int i=0; i<bImpedanceTorsoStiff->size(); i++)
1194 torso_stiffness.push_back(bImpedanceTorsoStiff->get(i).asFloat64());
1195 torso_damping.push_back(bImpedanceTorsoDamp->get(i).asFloat64());
1198 for(
int i=0; i<bImpedanceTorsoStiff->size(); i++)
1199 ctrl_impedance_torso->setImpedance(i,torso_stiffness[i],torso_damping[i]);
1202 vector<double> arm_stiffness(0),arm_damping(0);
1203 Bottle *bImpedanceArmStiff=bMotor.find(
"impedence_arm_stiffness").asList();
1204 Bottle *bImpedanceArmDamp=bMotor.find(
"impedence_arm_damping").asList();
1206 for(
int i=0; i<bImpedanceArmStiff->size(); i++)
1208 arm_stiffness.push_back(bImpedanceArmStiff->get(i).asFloat64());
1209 arm_damping.push_back(bImpedanceArmDamp->get(i).asFloat64());
1212 option.put(
"local",name);
1214 default_exec_time=option.check(
"default_exec_time",Value(
"3.0")).asFloat64();
1215 reachingTimeout=
std::max(2.0*default_exec_time,4.0);
1217 string arm_name[]={
"left_arm",
"right_arm"};
1218 for (
int arm=0; arm<2; arm++)
1220 if (partUsed==
"both_arms" || (partUsed==
"left_arm" && arm==
LEFT)
1221 || (partUsed==
"right_arm" && arm==
RIGHT))
1224 if (bArm[arm].isNull())
1226 yError(
"Missing %s parameter list!",arm_name[arm].c_str());
1230 else if(!getArmOptions(bArm[arm],arm))
1232 yError(
"Error extracting %s options!",arm_name[arm].c_str());
1237 Property option_tmp(option);
1238 option_tmp.put(
"part",arm_name[arm]);
1240 string tmpGraspFile=rf.findFile(bArm[arm].find(
"grasp_model_file").asString());
1241 option_tmp.put(
"grasp_model_file",tmpGraspFile);
1243 if (actionprimitives_layer==1)
1245 yInfo(
"***** Instantiating primitives layer 1 for %s",arm_name[arm].c_str());
1250 yInfo(
"***** Instantiating primitives layer 2 for %s",arm_name[arm].c_str());
1253 if (!action[arm]->isValid())
1263 p->setExtForceThres(extForceThresh[arm]);
1266 yInfo(
"***** List of available %s hand sequence keys:",arm_name[arm].c_str());
1267 for (
size_t i=0; i<q.size(); i++)
1272 yInfo(
"***** %s:",q[i].c_str());
1273 yInfo(
"%s",sequence.toString().c_str());
1276 ICartesianControl *tmpCtrl;
1280 tmpCtrl->storeContext(&context);
1282 double armTargetTol=bMotor.check(
"arm_target_tol",Value(0.01)).asFloat64();
1283 tmpCtrl->setInTargetTol(armTargetTol);
1286 tmpCtrl->restoreContext(context);
1287 tmpCtrl->deleteContext(context);
1290 if (Bottle *pB=bArm[arm].find(
"elbow_height").asList())
1294 double height=pB->get(0).asFloat64();
1295 double weight=pB->get(1).asFloat64();
1296 changeElbowHeight(arm,height,weight);
1300 for(
int i=0; i<bImpedanceArmStiff->size(); i++)
1301 ctrl_impedance_arm[arm]->setImpedance(i,arm_stiffness[i],arm_damping[i]);
1308 status_impedance_on=
false;
1309 bool impedance_from_start=bMotor.check(
"impedance",Value(
"off")).asString()==
"on";
1310 setImpedance(impedance_from_start);
1311 yInfo(
"Impedance set to %s",(status_impedance_on?
"on":
"off"));
1314 kinematics_file=bMotor.find(
"kinematics_file").asString();
1315 if(!loadKinematicOffsets())
1322 int starting_modeS2C=bMotor.check(
"stereoTocartesian_mode",Value(
"homography")).asVocab32();
1323 setStereoToCartesianMode(starting_modeS2C);
1326 dragger.init(rf.findGroup(
"dragger"),(
int)(1000.0*this->getPeriod()));
1328 this->avoidTable(
false);
1337 random_pos_y=bMotor.check(
"random_pos_y",Value(0.1)).asFloat64();
1342 this->setWaveing(bMotor.check(
"waveing",Value(
"off")).asString()==
"on");
1357 if (!gazeUnderControl)
1358 gazeUnderControl=
true;
1362 ctrl_gaze->lookAtFixationPoint(
x);
1368 Vector stereo=stereo_target.get();
1369 if(stereo.size()==4)
1375 px[
RIGHT].resize(2);
1377 px[
LEFT][0]=stereo[0];
1378 px[
LEFT][1]=stereo[1];
1379 px[
RIGHT][0]=stereo[2];
1380 px[
RIGHT][1]=stereo[3];
1382 ctrl_gaze->lookAtStereoPixels(px[
LEFT],px[
RIGHT]);
1387 if(stereo[2*dominant_eye]==0.0 && stereo[2*dominant_eye+1]==0.0)
1389 if(stereo[2*(1-dominant_eye)]==0.0 && stereo[2*(1-dominant_eye)+1]==0.0)
1392 eye_in_use=1-dominant_eye;
1395 eye_in_use=dominant_eye;
1398 px[0]=stereo[2*eye_in_use];
1399 px[1]=stereo[2*eye_in_use+1];
1400 ctrl_gaze->lookAtMonoPixel(dominant_eye,px,0.4);
1408 ctrl_gaze->lookAtFixationPoint(track_cartesian_target);
1414 if (!gazeUnderControl)
1415 gazeUnderControl=
true;
1424 Vector wrench, force(3);
1429 p->getExtWrench(wrench);
1436 dragger.ctrl->getPose(
x,o);
1438 if(Time::now()-dragger.t0 > dragger.samplingRate)
1441 Bottle &tmp_action=dragger.actions.addList();
1442 Vector tmp_x=dragger.x0 -
x;
1444 for(
size_t i=0; i<tmp_x.size(); i++)
1445 tmp_action.addFloat64(tmp_x[i]);
1447 for(
size_t i=0; i<o.size(); i++)
1448 tmp_action.addFloat64(o[i]);
1453 dragger.t0=Time::now();
1456 if(
norm(force)>dragger.extForceThresh)
1457 x=
x+0.1*force/
norm(force);
1464 if(!dragger.using_impedance)
1466 Vector wrench, force(3);
1467 double D=dragger.damping;
1472 p->getExtWrench(wrench);
1478 if (
norm(force)<dragger.extForceThresh)
1483 Vector b=force/dragger.inertia;
1484 Vector c=D*dragger.I->get();
1485 Vector a=force/dragger.inertia-D*dragger.I->get();
1489 Vector v=dragger.I->integrate(a);
1490 dragger.ctrl->setTaskVelocities(v,zeros4d);
1502 Vector stereoHand=stereo_target.get();
1503 if(stereoHand.size()==4)
1518 for(
int arm=0; arm<2; arm++)
1520 if(action[arm]!=NULL)
1525 Vector head_x,head_o;
1526 ctrl_gaze->getHeadPose(head_x,head_o);
1528 if(fabs(
x[1]-head_x[1])<0.2)
1529 x[1]=head_x[1]+sign(
x[1]-head_x[1])*0.2;
1531 ICartesianControl *tmp_ctrl;
1533 x[2]=avoid_table_height[arm];
1535 tmp_ctrl->goToPosition(
x);
1554 if(action[
LEFT]!=NULL)
1557 if(action[
RIGHT]!=NULL)
1565 if(checkOptions(options,
"left") || checkOptions(options,
"right"))
1566 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
1572 x[2]+=(std::isnan(
h)?go_up_distance:
h);
1587 if (checkOptions(options,
"left") ||
1588 checkOptions(options,
"right"))
1589 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
1591 Bottle *bTarget=options.find(
"target").asList();
1594 if (!targetToCartesian(bTarget,xd))
1597 arm=checkArm(arm,xd);
1599 if (!checkOptions(options,
"no_head") &&
1600 !checkOptions(options,
"no_gaze"))
1603 options.addString(
"fixate");
1607 bool side=checkOptions(options,
"side");
1608 Vector tmpOrient,tmpDisp;
1612 tmpOrient=reachSideOrient[arm];
1613 tmpDisp=reachSideDisp[arm];
1617 tmpOrient=(checkOptions(options,
"take")?
1618 reachAboveOrient[arm]:
1619 reachAboveCata[arm]);
1620 tmpDisp=reachAboveDisp;
1622 if (checkOptions(options,
"touch"))
1623 xd[2]=
std::min(xd[2],table_height-table_height_tolerance);
1626 restoreContext(arm);
1630 p->enableContactDetection();
1633 wp.
x=xd+tmpDisp; wp.
o=tmpOrient; wp.
oEnabled=
true;
1634 deque<ActionPrimitivesWayPoint> wpList;
1635 wpList.push_back(wp);
1637 wpList.push_back(wp);
1640 if (checkOptions(options,
"pretake_hand"))
1641 action[arm]->
pushAction(wpList,
"pretake_hand");
1650 p->disableContactDetection();
1667 setGraspState(side);
1669 if (!checkOptions(options,
"no_head") &&
1670 !checkOptions(options,
"no_gaze"))
1680 if(checkOptions(options,
"left") || checkOptions(options,
"right"))
1681 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
1683 Bottle *bTarget=options.find(
"target").asList();
1686 if (!targetToCartesian(bTarget,xd))
1691 arm=checkArm(arm,xd,
false);
1692 if (!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
1695 options.addString(
"fixate");
1699 Vector approach_data(4,0.0);
1700 if (options.check(
"approach"))
1702 if (Bottle *bApproach=options.find(
"approach").asList())
1704 size_t sz=
std::min(approach_data.size(),(
size_t)bApproach->size());
1705 for (
size_t i=0; i<sz; i++)
1706 approach_data[i]=bApproach->get(i).asFloat64();
1710 Vector
x=xd.subVector(0,2);
1711 Vector o=xd.subVector(3,6);
1713 Matrix R=axis2dcm(o);
1714 Vector
y=R.getCol(1);
1717 Vector dx=approach_data[0]*R.getCol(0).subVector(0,2);
1718 Vector dy=approach_data[1]*R.getCol(1).subVector(0,2);
1719 Vector dz=approach_data[2]*R.getCol(2).subVector(0,2);
1721 Vector approach_x=
x+dx+dy+dz;
1722 Vector approach_o=dcm2axis(axis2dcm(
y)*R);
1724 restoreContext(arm);
1728 p->enableContactDetection();
1730 action[arm]->
pushAction(approach_x,approach_o,
"pregrasp_hand");
1737 p->disableContactDetection();
1739 return grasp(options);
1746 if (checkOptions(options,
"left") || checkOptions(options,
"right"))
1747 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
1750 if (!targetToCartesian(options.find(
"target").asList(),xd))
1752 arm=checkArm(arm,xd);
1754 if (!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
1757 options.addString(
"fixate");
1762 xd+=pushAboveRelief;
1763 double push_direction=checkOptions(options,
"away")?-1.0:1.0;
1764 Vector tmpDisp=push_direction*reachSideDisp[arm];
1765 Vector tmpOrient=reachSideOrient[arm];
1767 restoreContext(arm);
1770 action[arm]->
pushAction(xd+tmpDisp,tmpOrient);
1773 if (!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
1776 ctrl_gaze->restoreContext(gaze_context);
1777 keepFixation(options);
1778 lookAtHand(options);
1783 p->enableContactDetection();
1784 action[arm]->
pushAction(xd-3*push_direction*reachSideDisp[arm],reachSideOrient[arm]);
1787 p->disableContactDetection();
1789 if (!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
1799 if(checkOptions(options,
"left") || checkOptions(options,
"right"))
1800 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
1802 Bottle *bTarget=options.find(
"target").asList();
1805 if(!targetToCartesian(bTarget,xd))
1808 if(!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
1814 arm=checkArm(arm,xd);
1816 xd[1]+=(arm==
LEFT)?-0.05:0.05;
1819 Matrix R=
zeros(3,3);
1821 R(1,1)=(arm==
LEFT)?-1.0:1.0;
1822 R(2,2)=(arm==
LEFT)?1.0:-1.0;
1824 restoreContext(arm);
1826 Vector od=dcm2axis(R);
1827 action[arm]->
pushAction(xd,od,
"pointing_hand");
1831 if(!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
1834 ctrl_gaze->setTrackingMode(
false);
1844 Bottle *bTarget=options.find(
"target").asList();
1845 if (!targetToCartesian(bTarget,xd))
1849 if (checkOptions(options,
"left"))
1851 else if (checkOptions(options,
"right"))
1854 arm=checkArm(arm,xd);
1856 restoreContext(arm);
1857 ICartesianControl* iarm;
1860 Property requirements;
1861 Bottle point; point.addList().read(xd);
1862 requirements.put(
"point",point.get(0));
1864 Bottle pointing_sequence;
1865 if (action[arm]->getHandSequence(
"pointing_hand",pointing_sequence))
1867 int numWayPoints=pointing_sequence.find(
"numWayPoints").asInt32();
1868 ostringstream wp; wp<<
"wp_"<<numWayPoints-1;
1869 Bottle *poss=pointing_sequence.find(wp.str()).asList()->find(
"poss").asList();
1870 Vector joints(poss->size());
1871 for (
size_t i=0; i<joints.length(); i++)
1872 joints[i]=poss->get(i).asFloat64();
1874 Bottle finger_joints; finger_joints.addList().read(joints);
1875 requirements.put(
"finger-joints",finger_joints.get(0));
1881 if (!checkOptions(options,
"no_head") &&
1882 !checkOptions(options,
"no_gaze"))
1885 options.addString(
"fixate");
1892 if (!checkOptions(options,
"no_head") &&
1893 !checkOptions(options,
"no_gaze"))
1896 ctrl_gaze->setTrackingMode(
false);
1907 ctrl_gaze->restoreContext(gaze_context);
1909 if (checkOptions(options,
"hand"))
1912 if(checkOptions(options,
"left") || checkOptions(options,
"right"))
1913 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
1916 lookAtHand(options);
1921 Bottle *bTarget=options.find(
"target").asList();
1922 if (!targetToCartesian(bTarget,xd))
1925 if (options.check(
"block_eyes"))
1927 ctrl_gaze->blockEyes(options.find(
"block_eyes").asFloat64());
1928 ctrl_gaze->waitMotionDone();
1931 if (checkOptions(options,
"fixate"))
1932 keepFixation(options);
1934 ctrl_gaze->lookAtFixationPointSync(xd);
1935 if (checkOptions(options,
"wait"))
1936 ctrl_gaze->waitMotionDone();
1946 if (checkOptions(options,
"left") || checkOptions(options,
"right"))
1947 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
1950 if (!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
1953 lookAtHand(options);
1956 restoreContext(arm);
1957 action[arm]->
pushAction(takeToolPos[arm],takeToolOrient[arm],
"open_hand");
1962 double force_thresh;
1964 p->getExtForceThres(force_thresh);
1966 bool contact_detected=
false;
1968 double t=Time::now();
1970 while (!contact_detected && (Time::now()-t<5.0))
1973 p->getExtWrench(wrench);
1975 if (
norm(wrench)>force_thresh)
1976 contact_detected=
true;
1981 if (!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
1991 if(checkOptions(options,
"left") || checkOptions(options,
"right"))
1992 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
1996 if(!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
1999 lookAtHand(options);
2002 restoreContext(arm);
2003 action[arm]->
pushAction(expectPos[arm],expectOrient[arm],
"open_hand");
2008 double force_thresh;
2010 p->getExtForceThres(force_thresh);
2012 bool contact_detected=
false;
2014 double t=Time::now();
2015 while(!contact_detected && Time::now()-t<5.0)
2018 p->getExtWrench(wrench);
2020 if(
norm(wrench)>force_thresh)
2021 contact_detected=
true;
2026 if(!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
2036 if(checkOptions(options,
"left") || checkOptions(options,
"right"))
2037 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
2041 if(!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
2044 lookAtHand(options);
2047 restoreContext(arm);
2048 action[arm]->
pushAction(expectPos[arm],expectOrient[arm]);
2056 p->enableContactDetection();
2058 bool contact_detected=
false;
2059 double t=Time::now();
2060 while (!contact_detected && (Time::now()-t<5.0))
2063 p->checkContact(contact_detected);
2068 p->disableContactDetection();
2070 if(!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
2080 ctrl_gaze->setSaccadesMode(
false);
2089 if (checkOptions(options,
"left") || checkOptions(options,
"right"))
2090 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
2097 if (options.size()<2)
2099 yError(
"Too few arguments for HAND command!");
2102 action_type=options.get(1).asString();
2107 if (action[arm]->pushAction(action_type))
2112 *holding=isHolding(options);
2117 yError(
"Unknown hand sequence \"%s\"",action_type.c_str());
2126 if (hand(options,
"close_hand",&holding))
2135 hand(options,
"release_hand");
2141 const double weight)
2144 if (action[arm]!=NULL)
2146 ICartesianControl *ctrl;
2149 ctrl->stopControl();
2152 ctrl->storeContext(&context);
2154 restoreContext(arm);
2156 Bottle tweakOptions;
2157 Bottle &optTask2=tweakOptions.addList();
2158 optTask2.addString(
"task_2");
2159 Bottle &plTask2=optTask2.addList();
2160 plTask2.addInt32(6);
2161 Bottle &posPart=plTask2.addList();
2162 posPart.addFloat64(0.0);
2163 posPart.addFloat64(0.0);
2164 posPart.addFloat64(height);
2165 Bottle &weightsPart=plTask2.addList();
2166 weightsPart.addFloat64(0.0);
2167 weightsPart.addFloat64(0.0);
2168 weightsPart.addFloat64(weight);
2169 ret=ctrl->tweakSet(tweakOptions);
2174 ctrl->restoreContext(context);
2175 ctrl->deleteContext(context);
2186 default_exec_time=execTime;
2187 reachingTimeout=
std::max(2.0*default_exec_time,4.0);
2191 if (action[arm]!=NULL)
2193 ICartesianControl *ctrl;
2196 ctrl->stopControl();
2199 ctrl->storeContext(&context);
2201 restoreContext(arm);
2208 ctrl->restoreContext(context);
2209 ctrl->deleteContext(context);
2221 const Vector &xin,
const Vector &oin)
2223 ICartesianControl *ctrl;
2227 ctrl->stopControl();
2228 ctrl->storeContext(&tmp_ctxt);
2231 ctrl->getDOF(dof); dof=1.0;
2232 ctrl->setDOF(dof,dof);
2234 ctrl->setLimits(0,0.0,0.0);
2235 ctrl->setLimits(1,0.0,0.0);
2236 ctrl->setLimits(2,0.0,0.0);
2238 ctrl->setTrajTime(default_exec_time);
2239 ctrl->setInTargetTol(0.04);
2241 ctrl->goToPoseSync(xin,oin);
2242 ctrl->waitMotionDone(0.1,reachingTimeout);
2244 ctrl->stopControl();
2245 ctrl->restoreContext(tmp_ctxt);
2251 bool head_home=(checkOptions(options,
"head") || checkOptions(options,
"gaze"));
2252 bool arms_home=(checkOptions(options,
"arms") || checkOptions(options,
"arm"));
2253 bool hand_home=(checkOptions(options,
"fingers") || checkOptions(options,
"hands") ||
2254 checkOptions(options,
"hand"));
2257 if (!head_home && !arms_home && !hand_home)
2258 head_home=arms_home=hand_home=
true;
2261 head_home = head_home && !checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze");
2263 bool left_arm=checkOptions(options,
"left") || checkOptions(options,
"both");
2264 bool right_arm=checkOptions(options,
"right") || checkOptions(options,
"both");
2267 if (!left_arm && !right_arm)
2268 left_arm=right_arm=
true;
2273 ctrl_gaze->restoreContext(gaze_context);
2274 ctrl_gaze->setTrackingMode(
true);
2276 if (homeFixCartType)
2277 ctrl_gaze->lookAtFixationPointSync(homeFix);
2279 ctrl_gaze->lookAtAbsAnglesSync(homeFix);
2286 exec_arm[0]=left_arm;
2287 exec_arm[1]=right_arm;
2292 if (exec_arm[0] && exec_arm[1])
2294 if (armInUse==
RIGHT)
2301 for (
size_t i=0; i<2; i++)
2303 if (exec_arm[i] && (action[which_arm[i]]!=NULL))
2306 action[which_arm[i]]->
pushAction(
"open_hand");
2308 goWithTorsoUpright(action[which_arm[i]],homePos[which_arm[i]],homeOrient[which_arm[i]]);
2315 if (waveing && right_arm && (action[
RIGHT]!=NULL))
2318 if (waveing && left_arm && (action[
LEFT]!=NULL))
2332 ctrl_gaze->waitMotionDone(0.1,3.0);
2333 ctrl_gaze->stopControl();
2334 ctrl_gaze->setTrackingMode(
false);
2344 if (checkOptions(options,
"left") || checkOptions(options,
"right"))
2345 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
2352 Bottle *bTarget=options.find(
"target").asList();
2355 if (!targetToCartesian(bTarget,deployZone))
2357 deployZone=deployPos[arm];
2358 if (checkOptions(options,
"away"))
2360 deployZone[0]=-0.15;
2361 deployZone[1]=(arm==
LEFT)?deployZone[1]=-0.35:deployZone[1]=0.35;
2364 deployZone=deployZone+randomDeployOffset();
2365 deployZone[2]=table_height;
2369 arm=checkArm(arm,deployZone);
2370 if (checkOptions(options,
"gently") && !checkOptions(options,
"over"))
2371 deployZone[2]=table_height;
2374 if (!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
2377 ctrl_gaze->restoreContext(gaze_context);
2378 keepFixation(options);
2379 ctrl_gaze->lookAtFixationPoint(deployZone);
2382 Vector tmpOrient=(grasp_state==
GRASP_STATE_SIDE?reachSideOrient[arm]:deployOrient[arm]);
2384 Vector deployOffs(deployZone.length(),0.0);
2385 deployOffs[2]=reachAboveDisp[2];
2387 restoreContext(arm);
2390 action[arm]->
pushAction(deployZone+deployOffs,tmpOrient);
2395 p->enableContactDetection();
2399 wp.
x=deployZone+deployOffs; wp.
o=tmpOrient; wp.
oEnabled=
true;
2400 deque<ActionPrimitivesWayPoint> wpList;
2401 wpList.push_back(wp);
2403 wpList.push_back(wp);
2410 p->disableContactDetection();
2412 if (!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
2413 ctrl_gaze->lookAtFixationPoint(
x);
2423 if (checkOptions(options,
"left") ||
2424 checkOptions(options,
"right"))
2425 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
2428 goWithTorsoUpright(action[arm],drawNearPos[arm],drawNearOrient[arm]);
2430 Bottle look_options;
2431 Bottle &target=look_options.addList();
2432 target.addString(
"target");
2433 Bottle &payLoad=target.addList().addList();
2434 payLoad.addString(
"cartesian");
2435 payLoad.addList().read(drawNearPos[arm]);
2436 look_options.addString(
"wait");
2446 if (checkOptions(options,
"left") ||
2447 checkOptions(options,
"right"))
2448 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
2457 action[arm]->
pushAction(
x,reachAboveOrient[arm],
"close_hand");
2471 Vector x_hand,o_hand,px[2],x_head,o_head;
2472 action[arm]->
getPose(x_hand,o_hand);
2473 ctrl_gaze->get2DPixel(
LEFT,x_hand,px[
LEFT]);
2474 ctrl_gaze->get2DPixel(
RIGHT,x_hand,px[
RIGHT]);
2476 ctrl_gaze->getHeadPose(x_head,o_head);
2478 hand_image_pos.clear();
2479 hand_image_pos.addFloat64(px[
LEFT][0]);
2480 hand_image_pos.addFloat64(px[
LEFT][1]);
2481 hand_image_pos.addFloat64(px[
RIGHT][0]);
2482 hand_image_pos.addFloat64(px[
RIGHT][1]);
2483 hand_image_pos.addFloat64(
norm(x_head-x_hand));
2492 if (checkOptions(options,
"left") ||
2493 checkOptions(options,
"right"))
2494 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
2501 return !in_position;
2508 if(checkOptions(options,
"left") || checkOptions(options,
"right"))
2509 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
2513 Vector deployZone=deployPos[arm];
2514 deployZone=deployZone+randomDeployOffset();
2516 Vector deployPrepare,deployEnd;
2517 deployPrepare=deployEnd=deployZone;
2519 deployPrepare[2]=0.0;
2524 if(!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
2527 ctrl_gaze->restoreContext(gaze_context);
2528 ctrl_gaze->lookAtFixationPoint(deployEnd);
2531 if(isHolding(options))
2534 restoreContext(arm);
2538 p->enableContactDetection();
2541 wp.
x=deployPrepare; wp.
o=reachAboveCata[arm];
2543 deque<ActionPrimitivesWayPoint> wpList;
2544 wpList.push_back(wp);
2546 wpList.push_back(wp);
2553 p->disableContactDetection();
2558 p->checkContact(found);
2565 if(!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
2566 ctrl_gaze->lookAtFixationPoint(
x);
2569 table[3]=-table_height;
2571 bKinOffsets.find(
"table_height")=Value(table_height);
2574 saveKinematicOffsets();
2577 opcPort.setTableHeight(table_height);
2579 yWarning(
"########## Table height found: %f",table_height);
2582 table_height+=table_height_tolerance;
2585 yWarning(
"########## Table height not found!");
2587 if(!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
2598 int currentArm=armInUse;
2600 int handToCalibrate=-1;
2601 if(checkOptions(options,
"left") || checkOptions(options,
"right"))
2602 handToCalibrate=checkOptions(options,
"left")?
LEFT:
RIGHT;
2604 bool no_head=(checkOptions(options,
"no_head"));
2606 bool calibrated=
true;
2607 for(
int arm=0; arm<2; arm++)
2609 if(action[arm]!=NULL && (handToCalibrate==-1 || handToCalibrate==arm))
2614 lookAtHand(options);
2616 Bottle b(arm==
LEFT?
"left":
"right");
2620 Bottle &fng=fingers.addList();
2621 fng.addString(
"index");
2622 fng.addString(
"middle");
2623 fng.addString(
"ring");
2624 fng.addString(
"little");
2627 prop.put(
"finger",fingers.get(0));
2628 graspModel[arm]->calibrate(prop);
2631 prop.put(
"finger",
"thumb");
2632 graspModel[arm]->calibrate(prop);
2635 fout.open((rf.getHomeContextPath()+
"/"+graspFile[arm]).c_str());
2636 graspModel[arm]->toStream(fout);
2639 calibrated=calibrated && graspModel[arm]->isCalibrated();
2642 action[arm]->
pushAction(homePos[arm],homeOrient[arm],
"open_hand");
2650 options.addString(
"head");
2654 setArmInUse(currentArm);
2660 bool MotorThread::avoidTable(
bool avoid)
2662 for(
int arm=0; arm<2; arm++)
2664 if(action[arm]!=NULL)
2670 avoid_table_height[arm]=
x[2];
2682 this->avoidTable(
true);
2685 ctrl_gaze->getInfo(info);
2686 iKinLimbVersion head_version(info.check(
"head_version",Value(
"1.0")).asString());
2689 type<<(dominant_eye==
LEFT?
"left":
"right");
2696 for (
unsigned int i=2; i<iKinTorso.
getN(); i++)
2700 Vector torso_init_joints(3);
2701 enc_torso->getEncoders(torso_init_joints.data());
2705 Vector tmp_joints(2,0.0);
2708 iKinTorso.
setAng(tmp_joints);
2711 Matrix
H=iKinTorso.
getH(3,
true);
2712 Vector cart_init_pos(3);
2713 cart_init_pos[0]=
H[0][3];
2714 cart_init_pos[1]=
H[1][3];
2715 cart_init_pos[2]=
H[2][3];
2719 Vector fixed_target(3);
2720 fixed_target[0]=-0.5;
2721 fixed_target[1]=0.0;
2722 fixed_target[2]=cart_init_pos[2];
2724 double walking_time=20.0;
2725 double step_time=2.0;
2726 double kp_pos_torso=0.6;
2728 vector<int> modes(3,VOCAB_CM_VELOCITY);
2729 ctrl_mode_torso->setControlModes(modes.data());
2731 double init_walking_time=Time::now();
2734 while(this->isRunning() && !interrupted && Time::now()-init_walking_time<walking_time)
2737 Vector random_pos=cart_init_pos;
2738 if (Rand::scalar(0.0,3.0)>2.0)
2739 random_pos[0]+=Rand::scalar(-0.1,-0.05);
2742 double tmp_rnd=Rand::scalar(-random_pos_y,random_pos_y);
2743 if ((tmp_rnd>-0.1) && (tmp_rnd<0.1))
2744 tmp_rnd=0.1*yarp::math::sign(tmp_rnd);
2746 random_pos[1]+=tmp_rnd;
2749 random_pos=(
norm(cart_init_pos)/
norm(random_pos))*random_pos;
2752 double init_step_time=Time::now();
2753 while(this->isRunning() && !interrupted && Time::now()-init_step_time<step_time && Time::now()-init_walking_time<walking_time)
2756 Vector torso_joints(3);
2757 enc_torso->getEncoders(torso_joints.data());
2759 Vector tmp_joints(2,0.0);
2762 iKinTorso.
setAng(tmp_joints);
2765 Matrix
H=iKinTorso.
getH(3,
true);
2767 curr_pos[0]=
H[0][3];
2768 curr_pos[1]=
H[1][3];
2769 curr_pos[2]=
H[2][3];
2771 Vector x_dot=kp_pos_torso*(random_pos-curr_pos);
2772 Matrix J=iKinTorso.
GeoJacobian(3).submatrix(0,2,0,1);
2773 Matrix J_pinv=pinv(J,1
e-06);
2775 double q_dot_mag=
norm(q_dot);
2776 double q_dot_saturation=15.0;
2783 else if (q_dot_mag>q_dot_saturation)
2784 q_dot=(q_dot_saturation/q_dot_mag)*q_dot;
2787 vector<int>
jnts(2);
2790 vel_torso->velocityMove((
int)
jnts.size(),
jnts.data(),q_dot.data());
2796 modes[0]=modes[1]=modes[2]=VOCAB_CM_POSITION;
2797 ctrl_mode_torso->setControlModes(modes.data());
2798 pos_torso->positionMove(torso_init_joints.data());
2800 while (isRunning() && !
done)
2803 pos_torso->checkMotionDone(&
done);
2806 this->avoidTable(
false);
2815 yError(
"Error! The requested arm is busy!");
2820 if(checkOptions(options,
"left") || checkOptions(options,
"right"))
2821 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
2825 if(action[arm]==NULL)
2827 yError(
"Error! requested arm is not working!");
2832 int other_arm=1-arm;
2833 if(!checkOptions(options,
"keep_other_hand_still") && action[other_arm]!=NULL)
2835 action[other_arm]->
pushAction(homePos[other_arm],homeOrient[other_arm]);
2842 Bottle bInterrupt(
"skip");
2843 suspendLearningModeAction(bInterrupt);
2844 suspendLearningModeKinOffset(bInterrupt);
2851 if(!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
2855 lookAtHand(options);
2858 double max_step_time=2.0;
2861 enc_arm[arm]->getAxes(&nJnts);
2863 vector<int> modes(nJnts,VOCAB_CM_POSITION);
2864 ctrl_mode_arm[arm]->setControlModes(modes.data());
2867 Vector destination(nJnts);
2868 for(
unsigned int pose_idx=0; pose_idx<handPoses.size(); pose_idx++)
2870 Vector current_position(nJnts);
2871 enc_arm[arm]->getEncoders(current_position.data());
2874 for(
unsigned int i=0; i<handPoses[pose_idx].size(); i++)
2875 destination[i]=handPoses[pose_idx][i];
2878 for(
int i=handPoses[pose_idx].size(); i<nJnts; i++)
2879 destination[i]=current_position[i];
2881 pos_arm[arm]->positionMove(destination.data());
2883 double init_step_time=Time::now();
2884 while(!this->interrupted && Time::now()-init_step_time<max_step_time)
2886 enc_arm[arm]->getEncoders(current_position.data());
2889 for(
size_t i=0; i<handPoses[pose_idx].size(); i++)
2890 if(fabs(destination[i]-current_position[i])>3.0)
2900 if (!checkOptions(options,
"no_head") && !checkOptions(options,
"no_gaze"))
2904 if(action[arm]!=NULL)
2918 yError(
"Error: The requested arm is busy!");
2922 string action_name=options.find(
"action_name").asString();
2926 yError(
"action name not specified!");
2931 if(checkOptions(options,
"left") || checkOptions(options,
"right"))
2932 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
2936 string arm_name=(arm==
LEFT?
"left":
"right");
2938 string fileName=rf.findFile(actions_path+
"/"+arm_name+
"/"+action_name+
".action");
2939 if(!fileName.empty())
2941 yWarning(
"Action '%s' already learned... stopping",action_name.c_str());
2945 dragger.actionName=action_name;
2946 dragger.actions.clear();
2952 if(dragger.ctrl==NULL)
2954 yError(
"Could not find the cartesian arm interface!");
2961 dragger.ctrl->getPose(
x,o);
2964 if(!setTorque(
true,arm))
2966 yError(
"Could not set torque control mode!");
2970 dragger.t0=Time::now();
2982 string arm_name=(dragger.arm==
LEFT?
"left":
"right");
2985 bool skip=checkOptions(options,
"skip");
2989 if (!actions_path.empty())
2991 string fileName=rf.getHomeContextPath();
2992 fileName+=
"/"+actions_path+
"/"+arm_name+
"/"+dragger.actionName+
".action";
2993 ofstream action_fout(fileName.c_str());
2994 if(!action_fout.is_open())
2996 yError(
"Unable to open file '%s' for action %s!",(actions_path+
"/"+arm_name+
"/"+dragger.actionName+
".action").c_str(),dragger.actionName.c_str());
3000 action_fout << dragger.actions.toString();
3003 success = opcPort.setAction(dragger.actionName, &(dragger.actions));
3021 if(checkOptions(options,
"left") || checkOptions(options,
"right"))
3022 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
3026 string arm_name=arm==
LEFT?
"left":
"right";
3027 string action_name=options.find(
"action_name").asString();
3030 string fileName=rf.findFile(actions_path+
"/"+arm_name+
"/"+action_name+
".action");
3031 if (!fileName.empty())
3033 ifstream action_fin(fileName.c_str());
3034 if(!action_fin.is_open())
3037 stringstream strstr;
3038 strstr << action_fin.rdbuf();
3039 actions.fromString(strstr.str());
3041 else if (!opcPort.getAction(action_name, &actions))
3044 restoreContext(arm);
3046 ICartesianControl *ctrl;
3050 ctrl->getDOF(newPos);
3051 newPos[0]=newPos[1]=0.0; newPos[2]=1.0;
3052 ctrl->setDOF(newPos,newPos);
3053 ctrl->setInTargetTol(0.01);
3054 ctrl->setTrajTime(0.75);
3056 Vector init_x,init_o;
3057 ctrl->getPose(init_x,init_o);
3059 for(
int i=0; i<actions.size(); i++)
3061 Bottle *b=actions.get(i).asList();
3063 for(
int j=0; j<3; j++)
3064 x[j]=b->get(j).asFloat64();
3066 for(
int j=0; j<4; j++)
3067 o[j]=b->get(j+3).asFloat64();
3069 ctrl->goToPoseSync(init_x-
x,o);
3073 ctrl->waitMotionDone(0.1,reachingTimeout);
3074 restoreContext(arm);
3087 if(checkOptions(options,
"left") || checkOptions(options,
"right"))
3088 arm=checkOptions(options,
"left")?
LEFT:
RIGHT;
3090 dragger.arm=checkArm(arm);
3096 if(dragger.ctrl==NULL)
3098 yError(
"Could not find the arm controller!");
3103 dragger.using_impedance=setTorque(
true,dragger.arm);
3104 if (!dragger.using_impedance)
3105 yWarning(
"Impedance control not available. Using admittance control!");
3108 bool specifiedTarget=
false;
3109 if (Bottle *b0=options.find(
"target").asList())
3111 if (Bottle *b1=b0->find(
"cartesian").asList())
3113 size_t n=
std::min(
x.length(),(
size_t)b1->size());
3114 for (
size_t i=0; i<
n; i++)
3115 x[i]=b1->get(i).asFloat64();
3116 specifiedTarget=
true;
3120 if (!specifiedTarget)
3123 dragger.ctrl->getPose(
x,o);
3127 dragger.t0=Time::now();
3128 yInfo(
"Learning kinematic offset against %s target (%s)",
3129 specifiedTarget?
"specified":
"retrieved",
3130 dragger.x0.toString(3,3).c_str());
3134 Bottle look_options;
3135 look_options.addString(
"hand");
3136 look_options.addString(dragger.arm==
LEFT?
"left":
"right");
3148 bool skip=checkOptions(options,
"skip");
3154 dragger.ctrl->getPose(
x,o);
3156 if (options.size()>=4)
3157 opcPort.getKinematicOffsets(options.get(3).asString(),currentKinematicOffset);
3158 currentKinematicOffset[dragger.arm]=
x-(dragger.x0-currentKinematicOffset[dragger.arm]);
3161 if(options.size()<4 || !opcPort.setKinematicOffsets(options.get(3).asString(),currentKinematicOffset))
3163 defaultKinematicOffset[dragger.arm]=currentKinematicOffset[dragger.arm];
3167 for(
int i=0; i<3; i++)
3168 bOffset.addFloat64(defaultKinematicOffset[dragger.arm][i]);
3170 string arm_name=(dragger.arm==
LEFT?
"left":
"right");
3171 *bKinOffsets.find(arm_name).asList()->find(Vocab32::decode(modeS2C)).asList()=bOffset;
3173 saveKinematicOffsets();
3191 Bottle &gaze=status.addList();
3192 gaze.addString(
"gaze");
3195 gaze.addString(
"busy");
3197 gaze.addString(
"idle");
3199 Bottle &control_mode=status.addList();
3200 control_mode.addString(
"control mode");
3201 control_mode.addString(status_impedance_on?
"impedance":
"velocity");
3203 Bottle &left_arm=status.addList();
3204 left_arm.addString(
"left_arm");
3206 if(action[
LEFT]!=NULL)
3212 left_arm.addString(
"busy");
3214 left_arm.addString(
"idle");
3217 left_arm.addString(
"unavailable");
3220 Bottle &right_arm=status.addList();
3221 right_arm.addString(
"right_arm");
3223 if(action[
RIGHT]!=NULL)
3229 right_arm.addString(
"busy");
3231 right_arm.addString(
"idle");
3234 right_arm.addString(
"unavailable");
3238 Bottle &statusS2C=status.addList();
3239 statusS2C.addString(
"[Stereo -> Cartesian] mode: ");
3245 statusS2C.addString(
"homography");
3251 statusS2C.addString(
"disparity");
3257 statusS2C.addString(
"network");
3266 if(opcPort.isUpdateNeeded())
3268 opcPort.getTableHeight(table_height);
3270 table.resize(4,0.0);
3272 table[3]=-table_height;
3275 table_height+=table_height_tolerance;
3284 disparityPort.interrupt();
3287 Bottle bInterrupt(
"skip");
3288 suspendLearningModeAction(bInterrupt);
3289 suspendLearningModeKinOffset(bInterrupt);
3291 if (ctrl_gaze!=NULL)
3294 ctrl_gaze->stopControl();
3297 if(action[
LEFT]!=NULL)
3304 if(action[
RIGHT]!=NULL)
3315 if(action[
LEFT]!=NULL)
3321 if(action[
RIGHT]!=NULL)
3327 disparityPort.resume();
#define HEAD_MODE_TRACK_TEMP
#define ARM_MODE_LEARN_ACTION
#define HEAD_MODE_TRACK_HAND
#define HEAD_MODE_TRACK_CART
#define ARM_MODE_LEARN_KINOFF
#define ARM_MODE_FINE_REACHING
#define HEAD_MODE_TRACK_FIX
bool push(Bottle &options)
bool targetToCartesian(Bottle *target, Vector &xd)
bool calibTable(Bottle &options)
bool powerGrasp(Bottle &options)
bool startLearningModeAction(Bottle &options)
virtual bool threadInit()
bool reach(Bottle &options)
bool grasp(const Bottle &options)
bool drawNear(Bottle &options)
bool isHolding(const Bottle &options)
bool stereoToCartesian(const Vector &stereo, Vector &xd)
bool clearIt(Bottle &options)
void getStatus(Bottle &status)
bool point(Bottle &options)
bool startLearningModeKinOffset(Bottle &options)
bool hand(const Bottle &options, const string &type="", bool *holding=NULL)
bool give(Bottle &options)
bool point_far(Bottle &options)
bool imitateAction(Bottle &options)
bool exploreHand(Bottle &options)
virtual void threadRelease()
bool look(Bottle &options)
bool deploy(Bottle &options)
bool suspendLearningModeKinOffset(Bottle &options)
bool exploreTorso(Bottle &options)
bool changeElbowHeight(const int arm, const double height, const double weight)
bool suspendLearningModeAction(Bottle &options)
bool setTorque(bool turn_on, int arm=ARM_IN_USE)
bool setImpedance(bool turn_on)
bool changeExecTime(const int arm, const double execTime)
bool release(const Bottle &options)
bool takeTool(Bottle &options)
bool calibFingers(Bottle &options)
bool shiftAndGrasp(Bottle &options)
bool getHandImagePosition(Bottle &hand_image_pos)
bool goHome(Bottle &options)
int setStereoToCartesianMode(const int mode, Bottle &reply)
bool goUp(Bottle &options, const double h=std::numeric_limits< double >::quiet_NaN())
bool expect(Bottle &options)
A derived class defining a first abstraction layer on top of actionPrimitives father class.
A class that inherits from ActionPrimitivesLayer1 and integrates the force-torque sensing in order to...
The base class defining actions.
virtual bool areFingersInPosition(bool &f)
Query if fingers are in position (cumulative response).
virtual bool lockActions()
Disable the possibility to yield any new action.
virtual bool syncCheckInterrupt(const bool disable=false)
Suddenly interrupt any blocking call that is pending on querying the action status.
virtual bool enableReachingTimeout(const double tmo)
Enable timeout while reaching.
virtual bool setTrackingMode(const bool f)
Set the task space controller in tracking or non-tracking mode.
virtual bool unlockActions()
Enable the possibility to yield new actions.
virtual bool getPose(yarp::sig::Vector &x, yarp::sig::Vector &o) const
Get the current arm pose.
virtual void close()
Deallocate the object.
virtual bool getHandSequence(const std::string &handSeqKey, yarp::os::Bottle &sequence)
Return a hand sequence.
virtual bool stopControl()
Stop any ongoing arm/hand movements.
virtual bool setDefaultExecTime(const double execTime)
Set the default arm movement execution time.
virtual bool getGraspModel(perception::Model *&model) const
Return the model used internally to detect external contacts.
virtual bool getCartesianIF(yarp::dev::ICartesianControl *&ctrl) const
Return the cartesian interface used internally to control the limb.
virtual bool pushAction(const yarp::sig::Vector &x, const yarp::sig::Vector &o, const std::string &handSeqKey, const double execTime=ACTIONPRIM_DISABLE_EXECTIME, ActionPrimitivesCallback *clb=NULL)
Insert a combination of arm and hand primitive actions in the actions queue.
std::deque< std::string > getHandSeqList()
Return the list of available hand sequence keys.
virtual bool enableArmWaving(const yarp::sig::Vector &restPos)
Enable the waving mode that keeps on moving the arm around a predefined position.
virtual bool syncCheckReinstate()
Reinstate the blocking feature for future calls with sync switch on.
virtual bool checkActionsDone(bool &f, const bool sync=false)
Check whether all the actions in queue are accomplished.
virtual bool pushWaitState(const double tmo, ActionPrimitivesCallback *clb=NULL)
Insert a wait state in the actions queue.
A class for defining a saturated integrator based on Tustin formula: .
A class for defining the iCub Eye.
yarp::sig::Matrix getH(const unsigned int i, const bool allLink=false)
Returns the rigid roto-translation matrix from the root reference frame to the ith frame in Denavit-H...
yarp::sig::Matrix GeoJacobian(const unsigned int i)
Returns the geometric Jacobian of the ith link.
bool releaseLink(const unsigned int i)
Releases the ith Link.
bool setBlockingValue(const unsigned int i, double Ang)
Changes the value of the ith blocked Link.
yarp::sig::Vector setAng(const yarp::sig::Vector &q)
Sets the free joint angles to values of q[i].
unsigned int getN() const
Returns the number of Links belonging to the Chain.
bool blockLink(const unsigned int i, double Ang)
Blocks the ith Link at the a certain value of its joint angle.
A class for defining the versions of the iCub limbs.
double norm(const yarp::sig::Matrix &M, int col)
Returns the norm of the vector given in the form: matrix(:,col).
constexpr double CTRL_RAD2DEG
180/PI.
constexpr double CTRL_DEG2RAD
PI/180.
void init(Bottle &initializer, double thread_rate)
static bool compute(yarp::dev::ICartesianControl *iarm, const yarp::os::Property &requirements, yarp::sig::Vector &q, yarp::sig::Vector &x)
static bool point(yarp::dev::ICartesianControl *iarm, const yarp::sig::Vector &q, const yarp::sig::Vector &x)
Struct for defining way points used for movements in the operational space.
yarp::sig::Vector o
The 4x1 Vector specifying the orientation of the waypoint in axis-angle representation.
yarp::sig::Vector x
The 3x1 Vector specifyng the position of the waypoint [m].
bool oEnabled
If this flag is set to true then orientation will be taken into account.
double duration
The time duration [s] to achieve the waypoint.