567 #include <yarp/os/all.h>
568 #include <yarp/sig/all.h>
569 #include <yarp/dev/all.h>
570 #include <yarp/dev/MultipleAnalogSensorsInterfaces.h>
576 #define GAZECTRL_SERVER_VER "2.0"
579 using namespace yarp::os;
581 using namespace yarp::sig;
636 PolyDriver *
waitPart(
const Property &partOpt,
const double ping_robot_tmo)
638 string partName=partOpt.find(
"part").asString();
639 PolyDriver *pDrv=
nullptr;
641 double t0=Time::now();
642 while (Time::now()-t0<ping_robot_tmo)
645 pDrv=
new PolyDriver(
const_cast<Property&
>(partOpt));
646 bool ok=pDrv->isValid();
650 yInfo(
"Checking if %s part is active ... yes",partName.c_str());
655 double dt=ping_robot_tmo-(Time::now()-t0);
656 yInfo(
"Checking if %s part is active ... not yet: still %.1f [s] to timeout expiry",
657 partName.c_str(),dt>0.0?dt:0.0);
659 double t1=Time::now();
660 while (Time::now()-t1<1.0)
674 lock_guard<mutex> lg(mutexContext);
675 Context &context=contextMap[contextIdCnt];
704 lock_guard<mutex> lg(mutexContext);
705 auto itr=contextMap.find(
id);
706 if (itr!=contextMap.end())
739 if (contextIdList!=
nullptr)
741 lock_guard<mutex> lg(mutexContext);
742 for (
int i=0; i<contextIdList->size(); i++)
744 int id=contextIdList->get(i).asInt32();
745 auto itr=contextMap.find(
id);
746 if (itr!=contextMap.end())
747 contextMap.erase(itr);
761 Bottle &serverVer=
info.addList();
762 serverVer.addString(
"server_version");
765 Bottle &headVer=
info.addList();
766 headVer.addString(
"head_version");
769 Bottle &minVer=
info.addList();
770 minVer.addString(
"min_allowed_vergence");
773 Bottle &events=
info.addList();
774 events.addString(
"events");
775 Bottle &eventsList=events.addList();
776 eventsList.addString(
"motion-onset");
777 eventsList.addString(
"motion-done");
778 eventsList.addString(
"motion-ongoing");
779 eventsList.addString(
"saccade-onset");
780 eventsList.addString(
"saccade-done");
781 eventsList.addString(
"stabilization-on");
782 eventsList.addString(
"stabilization-off");
783 eventsList.addString(
"closing");
784 eventsList.addString(
"suspended");
785 eventsList.addString(
"resumed");
786 eventsList.addString(
"comm-timeout");
787 eventsList.addString(
"*");
797 lock_guard<mutex> lg(mutexTweak);
798 if (Bottle *pB=options.find(
"camera_intrinsics_left").asList())
800 Matrix Prj=
zeros(3,4);
int w,
h;
804 for (
int i=0; i<pB->size(); i++)
806 Prj(r,c)=pB->get(i).asFloat64();
819 if (Bottle *pB=options.find(
"camera_intrinsics_right").asList())
821 Matrix Prj=
zeros(3,4);
int w,
h;
825 for (
int i=0; i<pB->size(); i++)
827 Prj(r,c)=pB->get(i).asFloat64();
840 if (options.check(
"camera_width_left"))
842 Matrix Prj=
zeros(3,4);
int w,
h;
844 w=options.find(
"camera_width_left").asInt32();
848 if (options.check(
"camera_height_left"))
850 Matrix Prj=
zeros(3,4);
int w,
h;
852 h=options.find(
"camera_height_left").asInt32();
856 if (options.check(
"camera_width_right"))
858 Matrix Prj=
zeros(3,4);
int w,
h;
860 w=options.find(
"camera_width_right").asInt32();
864 if (options.check(
"camera_height_right"))
866 Matrix Prj=
zeros(3,4);
int w,
h;
868 h=options.find(
"camera_height_right").asInt32();
872 bool doMinAllowedVer=
false;
873 if (Bottle *pB=options.find(
"camera_extrinsics_left").asList())
879 for (
int i=0; i<pB->size(); i++)
881 HN(r,c)=pB->get(i).asFloat64();
891 HN(3,0)=HN(3,1)=HN(3,2)=0.0;
899 doMinAllowedVer=
true;
902 if (Bottle *pB=options.find(
"camera_extrinsics_right").asList())
908 for (
int i=0; i<pB->size(); i++)
910 HN(r,c)=pB->get(i).asFloat64();
920 HN(3,0)=HN(3,1)=HN(3,2)=0.0;
928 doMinAllowedVer=
true;
944 lock_guard<mutex> lg(mutexTweak);
945 Bottle &intrinsicsLeft=options.addList();
946 intrinsicsLeft.addString(
"camera_intrinsics_left");
947 Bottle &intrinsicsLeftValues=intrinsicsLeft.addList();
948 Matrix PrjL;
int wL,hL;
950 for (
int r=0; r<PrjL.rows(); r++)
951 for (
int c=0; c<PrjL.cols(); c++)
952 intrinsicsLeftValues.addFloat64(PrjL(r,c));
954 Bottle &widthLeft=options.addList();
955 widthLeft.addString(
"camera_width_left");
956 widthLeft.addInt32(wL);
957 Bottle &heightLeft=options.addList();
958 heightLeft.addString(
"camera_height_left");
959 heightLeft.addInt32(hL);
961 Bottle &intrinsicsRight=options.addList();
962 intrinsicsRight.addString(
"camera_intrinsics_right");
963 Bottle &intrinsicsRightValues=intrinsicsRight.addList();
964 Matrix PrjR;
int wR,hR;
966 for (
int r=0; r<PrjR.rows(); r++)
967 for (
int c=0; c<PrjR.cols(); c++)
968 intrinsicsRightValues.addFloat64(PrjR(r,c));
970 Bottle &widthRight=options.addList();
971 widthRight.addString(
"camera_width_right");
972 widthRight.addInt32(wR);
973 Bottle &heightRight=options.addList();
974 heightRight.addString(
"camera_height_right");
975 heightRight.addInt32(hR);
977 Bottle &extrinsicsLeft=options.addList();
978 extrinsicsLeft.addString(
"camera_extrinsics_left");
979 Bottle &extrinsicsLeftValues=extrinsicsLeft.addList();
982 for (
int r=0; r<HL.rows(); r++)
983 for (
int c=0; c<HL.cols(); c++)
984 extrinsicsLeftValues.addFloat64(HL(r,c));
986 Bottle &extrinsicsRight=options.addList();
987 extrinsicsRight.addString(
"camera_extrinsics_right");
988 Bottle &extrinsicsRightValues=extrinsicsRight.addList();
991 for (
int r=0; r<HR.rows(); r++)
992 for (
int c=0; c<HR.cols(); c++)
993 extrinsicsRightValues.addFloat64(HR(r,c));
1001 Matrix PrjL;
int wL,hL;
1004 Matrix PrjR;
int wR,hR;
1014 string tweakFile=rf->getHomeContextPath();
1016 fout.open(tweakFile.c_str());
1019 if (validIntrinsicsL)
1021 fout<<
"[CAMERA_CALIBRATION_LEFT]"<<endl;
1022 fout<<
"w "<<wL<<endl;
1023 fout<<
"h "<<hL<<endl;
1024 fout<<
"fx "<<PrjL(0,0)<<endl;
1025 fout<<
"fy "<<PrjL(1,1)<<endl;
1026 fout<<
"cx "<<PrjL(0,2)<<endl;
1027 fout<<
"cy "<<PrjL(1,2)<<endl;
1031 if (validIntrinsicsR)
1033 fout<<
"[CAMERA_CALIBRATION_RIGHT]"<<endl;
1034 fout<<
"w "<<wR<<endl;
1035 fout<<
"h "<<hR<<endl;
1036 fout<<
"fx "<<PrjR(0,0)<<endl;
1037 fout<<
"fy "<<PrjR(1,1)<<endl;
1038 fout<<
"cx "<<PrjR(0,2)<<endl;
1039 fout<<
"cy "<<PrjR(1,2)<<endl;
1044 fout<<
"[ALIGN_KIN_LEFT]"<<endl;
1046 for (
int r=0; r<HNL.rows(); r++)
1047 for (
int c=0; c<HNL.cols(); c++)
1048 fout<<HNL(r,c)<<((r==HNL.rows()-1)&&(c==HNL.cols()-1)?
"":
" ");
1052 fout<<
"[ALIGN_KIN_RIGHT]"<<endl;
1054 for (
int r=0; r<HNR.rows(); r++)
1055 for (
int c=0; c<HNR.cols(); c++)
1056 fout<<HNR(r,c)<<((r==HNR.rows()-1)&&(c==HNR.cols()-1)?
"":
" ");
1068 map<iKinLimbVersion,iKinLimbVersion> d;
1079 auto ver_out=d.begin()->second;
1080 if (ver_out!=ver_in)
1082 yWarning(
"Unknown \"head_version\" %s requested => used \"head_version\" %s instead",
1083 ver_in.
get_version().c_str(),ver_out.get_version().c_str());
1094 eyesRefGen{nullptr},
1099 interrupting{false},
1100 doSaveTweakFile{false},
1115 double ping_robot_tmo;
1116 Vector counterRotGain(2);
1122 Bottle &imuGroup=rf.findGroup(
"imu");
1123 Bottle &eyeTiltGroup=rf.findGroup(
"eye_tilt");
1124 Bottle &trajTimeGroup=rf.findGroup(
"trajectory_time");
1125 Bottle &camerasGroup=rf.findGroup(
"cameras");
1126 Bottle &tweakGroup=rf.findGroup(
"tweak");
1129 ctrlName=rf.check(
"name",Value(
"iKinGazeCtrl")).asString();
1130 headName=rf.check(
"head",Value(
"head")).asString();
1131 torsoName=rf.check(
"torso",Value(
"torso")).asString();
1132 neckTime=trajTimeGroup.check(
"neck",Value(0.75)).asFloat64();
1133 eyesTime=trajTimeGroup.check(
"eyes",Value(0.25)).asFloat64();
1134 min_abs_vel=
CTRL_DEG2RAD*fabs(rf.check(
"min_abs_vel",Value(0.0)).asFloat64());
1135 ping_robot_tmo=rf.check(
"ping_robot_tmo",Value(40.0)).asFloat64();
1137 auto head_version=rf.check(
"head_version",Value(
"v1.0")).asString();
1138 if ((head_version.length()<2) || (tolower(head_version[0])!=
'v'))
1140 yWarning(
"Unrecognized \"head_version\" %s; going with default version",head_version.c_str());
1141 head_version=
"v1.0";
1145 commData.
robotName=rf.check(
"robot",Value(
"icub")).asString();
1146 commData.
eyeTiltLim[0]=eyeTiltGroup.check(
"min",Value(-20.0)).asFloat64();
1147 commData.
eyeTiltLim[1]=eyeTiltGroup.check(
"max",Value(15.0)).asFloat64();
1148 commData.
verbose=rf.check(
"verbose");
1149 commData.
saccadesOn=(rf.check(
"saccades",Value(
"on")).asString()==
"on");
1150 commData.
neckPosCtrlOn=(rf.check(
"neck_position_control",Value(
"on")).asString()==
"on");
1151 commData.
stabilizationOn=(imuGroup.check(
"mode",Value(
"on")).asString()==
"on");
1152 commData.
stabilizationGain=imuGroup.check(
"stabilization_gain",Value(11.0)).asFloat64();
1154 commData.
debugInfoEnabled=rf.check(
"debugInfo",Value(
"off")).asString()==
"on";
1158 counterRotGain[0]=imuGroup.check(
"vor",Value(1.0)).asFloat64();
1159 counterRotGain[1]=rf.check(
"ocr",Value(0.0)).asFloat64();
1163 counterRotGain[0]=imuGroup.check(
"vor",Value(0.0)).asFloat64();
1164 counterRotGain[1]=rf.check(
"ocr",Value(1.0)).asFloat64();
1167 if (camerasGroup.check(
"file"))
1169 camerasGroup.check(
"context")?
1170 commData.
rf_cameras.setDefaultContext(camerasGroup.find(
"context").asString()):
1171 commData.
rf_cameras.setDefaultContext(rf.getContext());
1172 commData.
rf_cameras.setDefaultConfigFile(camerasGroup.find(
"file").asString().c_str());
1176 commData.
rf_tweak.setDefaultContext(rf.getContext());
1177 commData.
tweakFile=tweakGroup.check(
"file",Value(
"tweak.ini")).asString();
1178 commData.
tweakOverwrite=(tweakGroup.check(
"overwrite",Value(
"on")).asString()==
"on");
1180 commData.
rf_tweak.configure(0,
nullptr);
1185 string remoteHeadName=
"/"+commData.
robotName+
"/"+headName;
1187 string remoteTorsoName=
"/"+commData.
robotName+
"/"+torsoName;
1189 string remoteInertialName=
"/"+commData.
robotName+
"/head/inertials";
1190 string localInertialName=commData.
localStemName+
"/head/inertials";
1192 float imuTimeout {0.04F};
1194 if (imuGroup.check(
"source_port_name"))
1195 remoteInertialName=imuGroup.find(
"source_port_name").asString();
1196 if (imuGroup.check(
"timeout"))
1197 imuTimeout=imuGroup.find(
"timeout").asFloat32();
1199 Property optTorso(
"(device remote_controlboard)");
1200 optTorso.put(
"remote",remoteTorsoName);
1201 optTorso.put(
"local",localTorsoName);
1202 optTorso.put(
"part",torsoName);
1204 Property optHead(
"(device remote_controlboard)");
1205 optHead.put(
"remote",remoteHeadName);
1206 optHead.put(
"local",localHeadName);
1207 optHead.put(
"part",headName);
1210 optHead.put(
"writeStrict",
"on");
1212 if (torsoName!=
"off")
1214 drvTorso=(ping_robot_tmo>0.0)?
1215 waitPart(optTorso,ping_robot_tmo):
1216 new PolyDriver(optTorso);
1218 if (!drvTorso->isValid())
1220 yWarning(
"Torso device driver not available!");
1221 yWarning(
"Perhaps only the head is running; trying to continue ...");
1229 yWarning(
"Torso device is off!");
1233 drvHead=(ping_robot_tmo>0.0)?
1234 waitPart(optHead,ping_robot_tmo):
1235 new PolyDriver(optHead);
1237 if (!drvHead->isValid())
1239 yError(
"Head device driver not available!");
1245 Property mas_conf{{
"device", Value(
"multipleanalogsensorsclient")},
1246 {
"remote", Value(remoteInertialName)},
1247 {
"local", Value(localInertialName)},
1248 {
"timeout",Value(imuTimeout)}};
1250 if (!(mas_client.open(mas_conf)))
1252 yError(
"Unable to open the MAS client");
1257 if (!(mas_client.view(iGyro)) ||
1258 !(mas_client.view(iAccel))) {
1260 yError(
"View failed of the MAS interfaces");
1265 commData.
iGyro = iGyro;
1266 commData.
iAccel = iAccel;
1269 yWarning(
"IMU data will be not received/used");
1273 yDebug(
"Commands to robot will be also streamed out on debug port");
1277 ctrl=
new Controller(drvTorso,drvHead,&commData,neckTime,eyesTime,min_abs_vel,10);
1279 eyesRefGen=
new EyePinvRefGen(drvTorso,drvHead,&commData,ctrl,counterRotGain,20);
1280 slv=
new Solver(drvTorso,drvHead,&commData,eyesRefGen,loc,ctrl,20);
1286 eyesRefGen->start();
1304 bool respond(
const Bottle &command, Bottle &reply)
override
1306 int ack=Vocab32::encode(
"ack");
1307 int nack=Vocab32::encode(
"nack");
1309 if (command.size()>0)
1311 switch (command.get(0).asVocab32())
1314 case createVocab32(
'g',
'e',
't'):
1316 if (command.size()>1)
1318 int type=command.get(1).asVocab32();
1320 if (type==createVocab32(
'T',
'n',
'e',
'c'))
1322 reply.addVocab32(
ack);
1323 reply.addFloat64(ctrl->
getTneck());
1326 else if (type==createVocab32(
'T',
'e',
'y',
'e'))
1328 reply.addVocab32(
ack);
1329 reply.addFloat64(ctrl->
getTeyes());
1332 else if (type==createVocab32(
'v',
'o',
'r'))
1335 reply.addVocab32(
ack);
1336 reply.addFloat64(gain[0]);
1339 else if (type==createVocab32(
'o',
'c',
'r'))
1342 reply.addVocab32(
ack);
1343 reply.addFloat64(gain[1]);
1346 else if (type==createVocab32(
's',
'a',
'c',
'c'))
1348 reply.addVocab32(
ack);
1352 else if (type==createVocab32(
's',
'i',
'n',
'h'))
1354 reply.addVocab32(
ack);
1358 else if (type==createVocab32(
's',
'a',
'c',
't'))
1360 reply.addVocab32(
ack);
1364 else if (type==createVocab32(
't',
'r',
'a',
'c'))
1366 reply.addVocab32(
ack);
1370 else if (type==createVocab32(
's',
't',
'a',
'b'))
1372 reply.addVocab32(
ack);
1376 else if (type==createVocab32(
'd',
'o',
'n',
'e'))
1378 reply.addVocab32(
ack);
1382 else if (type==createVocab32(
's',
'd',
'o',
'n'))
1384 reply.addVocab32(
ack);
1388 else if (type==createVocab32(
'p',
'i',
't',
'c'))
1390 double min_deg,max_deg;
1393 reply.addVocab32(
ack);
1394 reply.addFloat64(min_deg);
1395 reply.addFloat64(max_deg);
1398 else if (type==createVocab32(
'r',
'o',
'l',
'l'))
1400 double min_deg,max_deg;
1403 reply.addVocab32(
ack);
1404 reply.addFloat64(min_deg);
1405 reply.addFloat64(max_deg);
1408 else if (type==createVocab32(
'y',
'a',
'w'))
1410 double min_deg,max_deg;
1413 reply.addVocab32(
ack);
1414 reply.addFloat64(min_deg);
1415 reply.addFloat64(max_deg);
1418 else if (type==createVocab32(
'e',
'y',
'e',
's'))
1420 reply.addVocab32(
ack);
1424 else if (type==createVocab32(
'n',
't',
'o',
'l'))
1428 reply.addVocab32(
ack);
1429 reply.addFloat64(angle);
1432 else if (type==createVocab32(
'd',
'e',
's'))
1437 reply.addVocab32(
ack);
1438 reply.addList().read(des);
1442 else if (type==createVocab32(
'v',
'e',
'l'))
1447 reply.addVocab32(
ack);
1448 reply.addList().read(vel);
1452 else if ((type==createVocab32(
'p',
'o',
's',
'e')) && (command.size()>2))
1454 string poseSel=command.get(2).asString();
1458 if (ctrl->
getPose(poseSel,
x,stamp))
1460 reply.addVocab32(
ack);
1461 reply.addList().read(
x);
1463 Bottle &bStamp=reply.addList();
1464 bStamp.addInt32(stamp.getCount());
1465 bStamp.addFloat64(stamp.getTime());
1470 else if ((type==createVocab32(
'2',
'D')) && (command.size()>2))
1472 if (Bottle *bOpt=command.get(2).asList())
1477 string eye=bOpt->get(0).asString();
1478 x[0]=bOpt->get(1).asFloat64();
1479 x[1]=bOpt->get(2).asFloat64();
1480 x[2]=bOpt->get(3).asFloat64();
1485 reply.addVocab32(
ack);
1486 reply.addList().read(px);
1492 else if ((type==createVocab32(
'3',
'D')) && (command.size()>3))
1494 int subType=command.get(2).asVocab32();
1495 if (subType==createVocab32(
'm',
'o',
'n',
'o'))
1497 if (Bottle *bOpt=command.get(3).asList())
1501 string eye=bOpt->get(0).asString();
1502 double u=bOpt->get(1).asFloat64();
1503 double v=bOpt->get(2).asFloat64();
1504 double z=bOpt->get(3).asFloat64();
1509 reply.addVocab32(
ack);
1510 reply.addList().read(
x);
1516 else if (subType==createVocab32(
's',
't',
'e',
'r'))
1518 if (Bottle *bOpt=command.get(3).asList())
1522 Vector pxl(2),pxr(2);
1523 pxl[0]=bOpt->get(0).asFloat64();
1524 pxl[1]=bOpt->get(1).asFloat64();
1525 pxr[0]=bOpt->get(2).asFloat64();
1526 pxr[1]=bOpt->get(3).asFloat64();
1531 reply.addVocab32(
ack);
1532 reply.addList().read(
x);
1538 else if (subType==createVocab32(
'p',
'r',
'o',
'j'))
1540 if (Bottle *bOpt=command.get(3).asList())
1545 string eye=bOpt->get(0).asString();
1546 double u=bOpt->get(1).asFloat64();
1547 double v=bOpt->get(2).asFloat64();
1548 plane[0]=bOpt->get(3).asFloat64();
1549 plane[1]=bOpt->get(4).asFloat64();
1550 plane[2]=bOpt->get(5).asFloat64();
1551 plane[3]=bOpt->get(6).asFloat64();
1556 reply.addVocab32(
ack);
1557 reply.addList().read(
x);
1563 else if (subType==createVocab32(
'a',
'n',
'g'))
1565 if (Bottle *bOpt=command.get(3).asList())
1570 string type=bOpt->get(0).asString();
1576 reply.addVocab32(
ack);
1577 reply.addList().read(
x);
1583 else if ((type==createVocab32(
'a',
'n',
'g')) && (command.size()>2))
1585 if (Bottle *bOpt=command.get(2).asList())
1590 x[0]=bOpt->get(0).asFloat64();
1591 x[1]=bOpt->get(1).asFloat64();
1592 x[2]=bOpt->get(2).asFloat64();
1595 reply.addVocab32(
ack);
1596 reply.addList().read(ang);
1601 else if (type==createVocab32(
'p',
'i',
'd'))
1606 reply.addVocab32(
ack);
1607 reply.addList()=options;
1610 else if (type==createVocab32(
'i',
'n',
'f',
'o'))
1615 reply.addVocab32(
ack);
1616 reply.addList()=
info;
1620 else if (type==createVocab32(
't',
'w',
'e',
'a'))
1623 if (tweakGet(options))
1625 reply.addVocab32(
ack);
1626 reply.addList()=options;
1636 case createVocab32(
's',
'e',
't'):
1638 if (command.size()>2)
1640 int type=command.get(1).asVocab32();
1641 if (type==createVocab32(
'T',
'n',
'e',
'c'))
1643 double execTime=command.get(2).asFloat64();
1645 reply.addVocab32(
ack);
1648 else if (type==createVocab32(
'T',
'e',
'y',
'e'))
1650 double execTime=command.get(2).asFloat64();
1652 reply.addVocab32(
ack);
1655 else if (type==createVocab32(
'v',
'o',
'r'))
1658 gain[0]=command.get(2).asFloat64();
1660 reply.addVocab32(
ack);
1663 else if (type==createVocab32(
'o',
'c',
'r'))
1666 gain[1]=command.get(2).asFloat64();
1668 reply.addVocab32(
ack);
1671 else if (type==createVocab32(
's',
'a',
'c',
'c'))
1673 commData.
saccadesOn=(command.get(2).asInt32()>0);
1674 reply.addVocab32(
ack);
1677 else if (type==createVocab32(
's',
'i',
'n',
'h'))
1679 double period=command.get(2).asFloat64();
1681 reply.addVocab32(
ack);
1684 else if (type==createVocab32(
's',
'a',
'c',
't'))
1686 double angle=command.get(2).asFloat64();
1688 reply.addVocab32(
ack);
1691 else if (type==createVocab32(
'n',
't',
'o',
'l'))
1693 double angle=command.get(2).asFloat64();
1695 reply.addVocab32(
ack);
1698 else if (type==createVocab32(
't',
'r',
'a',
'c'))
1700 bool mode=(command.get(2).asInt32()>0);
1702 reply.addVocab32(
ack);
1705 else if (type==createVocab32(
's',
't',
'a',
'b'))
1707 bool mode=(command.get(2).asInt32()>0);
1711 else if (type==createVocab32(
'p',
'i',
'd'))
1713 if (Bottle *bOpt=command.get(2).asList())
1716 reply.addVocab32(
ack);
1720 else if (type==createVocab32(
't',
'w',
'e',
'a'))
1722 if (Bottle *bOpt=command.get(2).asList())
1724 reply.addVocab32(tweakSet(*bOpt)?
ack:
nack);
1734 case createVocab32(
'l',
'o',
'o',
'k'):
1736 if (command.size()>2)
1738 int type=command.get(1).asVocab32();
1739 if (type==createVocab32(
'3',
'D'))
1741 if (Bottle *bOpt=command.get(2).asList())
1746 x[0]=bOpt->get(0).asFloat64();
1747 x[1]=bOpt->get(1).asFloat64();
1748 x[2]=bOpt->get(2).asFloat64();
1752 reply.addVocab32(
ack);
1758 else if (type==createVocab32(
'm',
'o',
'n',
'o'))
1760 if (Bottle *bOpt=command.get(2).asList())
1764 string eye=bOpt->get(0).asString();
1765 double u=bOpt->get(1).asFloat64();
1766 double v=bOpt->get(2).asFloat64();
1770 if (bOpt->get(3).isFloat64())
1772 z=bOpt->get(3).asFloat64();
1775 else if ((bOpt->get(3).asString()==
"ver") && (bOpt->size()>4))
1777 double ver=bOpt->get(4).asFloat64();
1789 reply.addVocab32(
ack);
1797 else if (type==createVocab32(
's',
't',
'e',
'r'))
1799 if (Bottle *bOpt=command.get(2).asList())
1803 Vector pxl(2),pxr(2);
1804 pxl[0]=bOpt->get(0).asFloat64();
1805 pxl[1]=bOpt->get(1).asFloat64();
1806 pxr[0]=bOpt->get(2).asFloat64();
1807 pxr[1]=bOpt->get(3).asFloat64();
1814 reply.addVocab32(
ack);
1821 else if (type==createVocab32(
'a',
'n',
'g'))
1823 if (Bottle *bOpt=command.get(2).asList())
1828 string type=bOpt->get(0).asString();
1836 reply.addVocab32(
ack);
1848 case createVocab32(
's',
't',
'o',
'p'):
1851 reply.addVocab32(
ack);
1856 case createVocab32(
's',
't',
'o',
'r'):
1860 reply.addVocab32(
ack);
1866 case createVocab32(
'r',
'e',
's',
't'):
1868 if (command.size()>1)
1870 int id=command.get(1).asInt32();
1871 if (restoreContext(
id))
1873 reply.addVocab32(
ack);
1882 case createVocab32(
'd',
'e',
'l'):
1884 if (command.size()>1)
1886 Bottle *ids=command.get(1).asList();
1887 if (deleteContexts(ids))
1889 reply.addVocab32(
ack);
1898 case createVocab32(
'b',
'i',
'n',
'd'):
1900 if (command.size()>2)
1902 int joint=command.get(1).asVocab32();
1903 if (joint==createVocab32(
'p',
'i',
't',
'c'))
1905 double min=command.get(2).asFloat64();
1906 double max=command.get(3).asFloat64();
1908 reply.addVocab32(
ack);
1911 else if (joint==createVocab32(
'r',
'o',
'l',
'l'))
1913 double min=command.get(2).asFloat64();
1914 double max=command.get(3).asFloat64();
1916 reply.addVocab32(
ack);
1919 else if (joint==createVocab32(
'y',
'a',
'w'))
1921 double min=command.get(2).asFloat64();
1922 double max=command.get(3).asFloat64();
1924 reply.addVocab32(
ack);
1927 else if (joint==createVocab32(
'e',
'y',
'e',
's'))
1929 double ver=command.get(2).asFloat64();
1931 reply.addVocab32(
ack);
1940 case createVocab32(
'c',
'l',
'e',
'a'):
1942 if (command.size()>1)
1944 int joint=command.get(1).asVocab32();
1945 if (joint==createVocab32(
'p',
'i',
't',
'c'))
1948 reply.addVocab32(
ack);
1951 else if (joint==createVocab32(
'r',
'o',
'l',
'l'))
1954 reply.addVocab32(
ack);
1957 else if (joint==createVocab32(
'y',
'a',
'w'))
1960 reply.addVocab32(
ack);
1963 else if (joint==createVocab32(
'e',
'y',
'e',
's'))
1966 reply.addVocab32(
ack);
1975 case createVocab32(
'r',
'e',
'g',
'i'):
1977 if (command.size()>1)
1979 int type=command.get(1).asVocab32();
1980 if (type==createVocab32(
'o',
'n',
'g',
'o'))
1982 if (command.size()>2)
1984 double checkPoint=command.get(2).asFloat64();
1987 reply.addVocab32(
ack);
1998 case createVocab32(
'u',
'n',
'r',
'e'):
2000 if (command.size()>1)
2002 int type=command.get(1).asVocab32();
2003 if (type==createVocab32(
'o',
'n',
'g',
'o'))
2005 if (command.size()>2)
2007 double checkPoint=command.get(2).asFloat64();
2010 reply.addVocab32(
ack);
2021 case createVocab32(
'l',
'i',
's',
't'):
2023 if (command.size()>1)
2025 int type=command.get(1).asVocab32();
2026 if (type==createVocab32(
'o',
'n',
'g',
'o'))
2028 reply.addVocab32(
ack);
2038 case createVocab32(
's',
'u',
's',
'p'):
2043 reply.addVocab32(
ack);
2048 case createVocab32(
'r',
'u',
'n'):
2053 reply.addVocab32(
ack);
2058 case createVocab32(
's',
't',
'a',
't'):
2060 reply.addVocab32(
ack);
2061 if (ctrl->isSuspended())
2062 reply.addString(
"suspended");
2064 reply.addString(
"running");
2070 return RFModule::respond(command,reply);
2074 reply.addVocab32(
nack);
2084 if (eyesRefGen!=
nullptr)
2093 if (drvTorso!=
nullptr)
2096 if (drvHead!=
nullptr)
2099 if (mas_client.isValid())
2102 if (commData.
port_xd!=
nullptr)
2103 if (!commData.
port_xd->isClosed())
2105 if (rpcPort.asPort().isOpen())
2125 if (commData.
port_xd!=
nullptr)
2126 commData.
port_xd->interrupt();
2127 rpcPort.interrupt();
2148 if (doSaveTweakFile)
2150 lock_guard<mutex> lg(mutexTweak);
2152 doSaveTweakFile=
false;
2164 rf.setDefaultContext(
"iKinGazeCtrl");
2165 rf.setDefaultConfigFile(
"config.ini");
2166 rf.configure(
argc,argv);
2169 if (!
yarp.checkNetwork())
2171 yError(
"YARP server not available!");
2176 return mod.runModule(rf);
bool unregisterMotionOngoingEvent(const double checkPoint)
bool setGazeStabilization(const bool f)
bool getPose(const string &poseSel, Vector &x, Stamp &stamp)
void setTeyes(const double execTime)
bool look(const Vector &x)
void minAllowedVergenceChanged() override
void setTneck(const double execTime)
bool getVelocity(Vector &vel)
bool getDesired(Vector &des)
void findMinimumAllowedVergence()
void setTrackingMode(const bool f)
bool getGazeStabilization() const
bool getTrackingMode() const
Bottle listMotionOngoingEvents()
bool registerMotionOngoingEvent(const double checkPoint)
ResourceFinder rf_cameras
double saccadesActivationAngle
IThreeAxisLinearAccelerometers * iAccel
double gyro_noise_threshold
double saccadesInhibitionPeriod
double minAllowedVergence
IThreeAxisGyroscopes * iGyro
iKinLimbVersion head_version
void minAllowedVergenceChanged() override
Vector getCounterRotGain()
void manageBindEyes(const double ver)
bool bindEyes(const double ver)
void setCounterRotGain(const Vector &gain)
virtual bool getExtrinsicsMatrix(const string &type, Matrix &M)
virtual bool setExtrinsicsMatrix(const string &type, const Matrix &M)
bool restoreContext(const int id)
void storeContext(int *id)
bool configure(ResourceFinder &rf)
bool tweakSet(const Bottle &options)
EyePinvRefGen * eyesRefGen
bool getInfo(Bottle &info)
bool respond(const Bottle &command, Bottle &reply) override
bool deleteContexts(Bottle *contextIdList)
bool updateModule() override
IThreeAxisLinearAccelerometers * iAccel
std::map< int, Context > contextMap
iKinLimbVersion constrainHeadVersion(const iKinLimbVersion &ver_in)
PolyDriver * waitPart(const Property &partOpt, const double ping_robot_tmo)
double getPeriod() override
bool interruptModule() override
IThreeAxisGyroscopes * iGyro
bool tweakGet(Bottle &options)
void getPidOptions(Bottle &options)
bool setIntrinsicsMatrix(const string &type, const Matrix &M, const int w, const int h)
double getDistFromVergence(const double ver)
Vector get3DPoint(const string &type, const Vector &ang)
void setPidOptions(const Bottle &options)
bool getIntrinsicsMatrix(const string &type, Matrix &M, int &w, int &h)
bool triangulatePoint(const Vector &pxl, const Vector &pxr, Vector &x)
bool projectPoint(const string &type, const Vector &x, Vector &px)
Vector getAbsAngles(const Vector &x)
void bindNeckPitch(const double min_deg, const double max_deg)
void getCurNeckYawRange(double &min_deg, double &max_deg)
void getCurNeckPitchRange(double &min_deg, double &max_deg)
double getNeckAngleUserTolerance() const
void bindNeckYaw(const double min_deg, const double max_deg)
void setNeckAngleUserTolerance(const double angle)
void getCurNeckRollRange(double &min_deg, double &max_deg)
void bindNeckRoll(const double min_deg, const double max_deg)
A class for defining the versions of the iCub limbs.
std::string get_version() const
Return the version string.
int main(int argc, char *argv[])
#define GAZECTRL_SERVER_VER
Copyright (C) 2008 RobotCub Consortium.
double saccadesInhibitionPeriod
double saccadesActivationAngle
double neckAngleUserTolerance