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));
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";
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")?
1172 commData.
rf_cameras.setDefaultConfigFile(camerasGroup.find(
"file").asString().c_str());
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")
1216 new PolyDriver(optTorso);
1220 yWarning(
"Torso device driver not available!");
1221 yWarning(
"Perhaps only the head is running; trying to continue ...");
1229 yWarning(
"Torso device is off!");
1235 new PolyDriver(optHead);
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)}};
1252 yError(
"Unable to open the MAS client");
1260 yError(
"View failed of the MAS interfaces");
1269 yWarning(
"IMU data will be not received/used");
1273 yDebug(
"Commands to robot will be also streamed out on debug port");
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);
1326 else if (type==createVocab32(
'T',
'e',
'y',
'e'))
1328 reply.addVocab32(
ack);
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();
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'))
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'))
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())
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();
1873 reply.addVocab32(
ack);
1882 case createVocab32(
'd',
'e',
'l'):
1884 if (command.size()>1)
1886 Bottle *ids=command.get(1).asList();
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);