190 #include <yarp/os/ResourceFinder.h>
191 #include <yarp/os/RFModule.h>
192 #include <yarp/os/Log.h>
193 #include <yarp/os/LogStream.h>
198 #define NUMBER_OF_AVAILABLE_STANDARD_DATA_TO_DUMP 17
199 #define NUMBER_OF_AVAILABLE_DEBUG_DATA_TO_DUMP 3
205 if (!rf.check(
"rate"))
209 Value& rate = rf.find(
"rate");
216 if (!rf.check(
"joints"))
218 yError(
"Missing option 'joints' in given config file\n");
221 Value& joints = rf.find(
"joints");
222 Bottle *pJoints = joints.asList();
225 yError(
"Error in option 'joints'\n");
235 if (!rf.check(
"joints"))
237 yError(
"Missing option 'joints' in given config file\n");
241 Value& joints = rf.find(
"joints");
242 Bottle *pJoints = joints.asList();
245 yError(
"Error in option 'joints'\n");
248 if (pJoints->size()!=
n)
250 yError(
"The 'nJoints' and 'joints' params are incompatible");
254 for (
int i = 0; i <
n; i++)
256 thetaMap[i] = pJoints->get(i).asInt32();
263 if (!rf.check(
"nConstr"))
265 yError(
"Missing option 'nConstr' in given config file\n");
268 Value& nJoints = rf.find(
"nConstr");
269 n = nJoints.asInt32();
275 if (rf.check(
"dataToDumpAll"))
281 if (!rf.check(
"dataToDump"))
283 yError(
"Missing option 'dataToDump' in given config file\n");
287 Value& list = rf.find(
"dataToDump");
288 Bottle *pList = list.asList();
291 yError(
"Error in option 'dataToDump'\n");
298 int getDataToDump(ResourceFinder &rf, std::string *listOfData,
int n,
bool *needDebug)
306 availableDataToDump[0] =
"getEncoders";
307 availableDataToDump[1] =
"getEncoderSpeeds";
308 availableDataToDump[2] =
"getEncoderAccelerations";
309 availableDataToDump[3] =
"getPositionErrors";
310 availableDataToDump[4] =
"getOutputs";
311 availableDataToDump[5] =
"getCurrents";
312 availableDataToDump[6] =
"getTorques";
313 availableDataToDump[7] =
"getTorqueErrors";
314 availableDataToDump[8] =
"getPosPidReferences";
315 availableDataToDump[9] =
"getTrqPidReferences";
316 availableDataToDump[10] =
"getControlModes";
317 availableDataToDump[11] =
"getInteractionModes";
318 availableDataToDump[12] =
"getMotorEncoders";
319 availableDataToDump[13] =
"getMotorSpeeds";
320 availableDataToDump[14] =
"getMotorAccelerations";
321 availableDataToDump[15] =
"getTemperatures";
322 availableDataToDump[16] =
"getMotorsPwm";
324 availableDebugDataToDump[0] =
"getRotorPositions";
325 availableDebugDataToDump[1] =
"getRotorSpeeds";
326 availableDebugDataToDump[2] =
"getRotorAccelerations";
328 if (rf.check(
"dataToDumpAll"))
330 for (
int i = 0; i <
n; i++)
331 listOfData[i] = availableDataToDump[i];
336 if (!rf.check(
"dataToDump"))
338 yError(
"Missing option 'dataToDump' in given config file\n");
342 Value& list = rf.find(
"dataToDump");
343 Bottle *pList = list.asList();
345 for (
int i = 0; i <
n; i++)
347 listOfData[i] = pList->get(i).toString();
351 if (listOfData[i] == (availableDataToDump[j]))
357 if (listOfData[i] == (availableDebugDataToDump[j]))
366 yError(
"Illegal values for 'dataToDump': %s does not exist!\n",listOfData[i].c_str());
378 Property fileOptions;
379 Property ddBoardOptions;
380 Property ddDebugOptions;
382 std::string configFileRobotPart;
383 std::string portPrefix;
393 std::string *dataToDump;
399 IPreciselyTimed *istmp;
409 IMotorEncoders *imotenc;
419 IAmplifierControl *iamp;
423 ITorqueControl *itrq;
429 IInteractionMode *iimod;
449 if (!rf.check(
"robot") || !rf.check(
"part"))
451 printf(
"Missing either --robot or --part options. Quitting!\n");
455 std::string dumpername;
457 if (rf.check(
"name"))
459 dumpername = rf.find(
"name").asString();
464 dumpername =
"/controlBoardDumper/";
467 Value& robot = rf.find(
"robot");
468 Value& part = rf.find(
"part");
469 configFileRobotPart =
"config_";
470 configFileRobotPart = configFileRobotPart + robot.asString();
471 configFileRobotPart = configFileRobotPart +
"_";
472 configFileRobotPart = configFileRobotPart + part.asString();
473 configFileRobotPart = configFileRobotPart +
".ini";
481 thetaMap =
new int[nJoints];
489 dataToDump =
new std::string[nData];
490 if (
getDataToDump(rf, dataToDump, nData, &useDebugClient) == 0)
494 yInfo(
"Running with the following configuration:\n");
495 yInfo(
"Selected rate is: %d\n", rate);
496 yInfo(
"Data selected to be dumped are:\n");
497 for (
int i = 0; i < nData; i++)
498 yInfo(
"\t%s \n", dataToDump[i].c_str());
501 ddBoardOptions.put(
"device",
"remote_controlboard");
502 ddDebugOptions.put(
"device",
"debugInterfaceClient");
504 std::string localPortName = name;
505 std::string localDebugPortName = name;
506 localPortName = localPortName + dumpername;
507 localDebugPortName = localPortName +
"debug/";
509 localPortName = localPortName + part.asString();
510 localDebugPortName = localDebugPortName + part.asString();
511 ddBoardOptions.put(
"local", localPortName);
512 ddDebugOptions.put(
"local", localDebugPortName);
514 std::string remotePortName =
"/";
515 std::string remoteDebugPortName;
516 remotePortName = remotePortName + robot.asString();
517 remotePortName = remotePortName +
"/";
518 remotePortName = remotePortName + part.asString();
519 ddBoardOptions.put(
"remote", remotePortName);
521 remoteDebugPortName = remotePortName +
"/debug";
522 ddDebugOptions.put(
"remote", remoteDebugPortName);
525 ddBoard.open(ddBoardOptions);
526 if (!ddBoard.isValid()) {
527 printf(
"Device not available.\n");
533 ddDebug.open(ddDebugOptions);
534 if (!ddDebug.isValid())
536 yError(
"\n-----------------------------------------\n");
537 yError(
"Debug Interface is mandatory to run this module with the '--dataToDumpAll' option or to dump any of the getRotorxxx data.\n");
538 yError(
"Please Verify the following 2 conditions are satisfied:\n\n");
539 yError(
"1) Check 'debugInterfaceClient' is available using 'yarpdev --list' command\n");
542 std::string deviceList, myDev;
544 deviceList.append(Drivers::factory().
toString());
545 myDev =
"debugInterfaceClient";
546 if(deviceList.find(myDev) != std::string::npos)
547 yError(
"\t--> Seems OK\n");
549 yError(
"\t--> Seems NOT OK. The device was not found, please activate the compilation using the corrisponding CMake flag.\n");
551 yError(
"\n2) Check if the robot has the 'debugInterfaceWrapper' device up and running. \n You should see from 'yarp name list' output, a port called\n");
552 yError(
"\t/robotName/part_name/debug/rpc:i\n If not, fix the robot configuration files to instantiate the 'debugInterfaceWrapper' device.\n");
553 yError(
"\nQuickFix: If you set the --dataToDumpAll and do not need the advanced debug feature (getRotorxxx) just remove this option. See help for more information.\n");
554 yError(
"------------- END ERROR MESSAGE ---------------\n\n");
559 bool logToFile =
false;
560 if (rf.check(
"logToFile")) logToFile =
true;
562 portPrefix= dumpername + part.asString() +
"/";
568 for (
int i = 0; i < nData; i++)
570 if (dataToDump[i] ==
"getEncoders" )
572 if (ddBoard.view(ienc))
574 yInfo(
"Initializing a getEncs thread\n");
575 myDumper[i].
setDevice(&ddBoard, &ddDebug, rate, portPrefix, dataToDump[i], logToFile);
578 if (ddBoard.view(istmp))
580 yInfo(
"getEncoders::The time stamp initalization interfaces was successfull! \n");
584 yError(
"Problems getting the time stamp interfaces \n");
588 else if (dataToDump[i] ==
"getEncoderSpeeds")
590 if (ddBoard.view(ienc))
592 yInfo(
"Initializing a getSpeeds thread\n");
593 myDumper[i].
setDevice(&ddBoard, &ddDebug, rate, portPrefix, dataToDump[i], logToFile);
596 if (ddBoard.view(istmp))
598 yInfo(
"getEncodersSpeed::The time stamp initalization interfaces was successfull! \n");
602 yError(
"Problems getting the time stamp interfaces \n");
606 else if (dataToDump[i] ==
"getEncoderAccelerations")
608 if (ddBoard.view(ienc))
610 yInfo(
"Initializing a getAccs thread\n");
611 myDumper[i].
setDevice(&ddBoard, &ddDebug, rate, portPrefix, dataToDump[i], logToFile);
614 if (ddBoard.view(istmp))
616 yInfo(
"getEncoderAccelerations::The time stamp initalization interfaces was successfull! \n");
620 yError(
"Problems getting the time stamp interfaces \n");
624 else if (dataToDump[i] ==
"getPosPidReferences")
626 if (ddBoard.view(ipid))
628 yInfo(
"Initializing a getErrs thread\n");
629 myDumper[i].
setDevice(&ddBoard, &ddDebug, rate, portPrefix, dataToDump[i], logToFile);
632 if (ddBoard.view(istmp))
634 yInfo(
"getPosPidReferences::The time stamp initalization interfaces was successfull! \n");
638 yError(
"Problems getting the time stamp interfaces \n");
642 else if (dataToDump[i] ==
"getTrqPidReferences")
644 if (ddBoard.view(itrq))
646 yInfo(
"Initializing a getErrs thread\n");
647 myDumper[i].
setDevice(&ddBoard, &ddDebug, rate, portPrefix, dataToDump[i], logToFile);
650 if (ddBoard.view(istmp))
652 yInfo(
"getTrqPidReferences::The time stamp initalization interfaces was successfull! \n");
656 yError(
"Problems getting the time stamp interfaces \n");
660 else if (dataToDump[i] ==
"getControlModes")
662 if (ddBoard.view(icmod))
664 yInfo(
"Initializing a getErrs thread\n");
665 myDumper[i].
setDevice(&ddBoard, &ddDebug, rate, portPrefix, dataToDump[i], logToFile);
668 if (ddBoard.view(istmp))
670 yInfo(
"getControlModes::The time stamp initalization interfaces was successfull! \n");
674 yError(
"Problems getting the time stamp interfaces \n");
675 myDumper[i].
setGetter(&myGetControlModes);
678 else if (dataToDump[i] ==
"getInteractionModes")
680 if (ddBoard.view(iimod))
682 yInfo(
"Initializing a getErrs thread\n");
683 myDumper[i].
setDevice(&ddBoard, &ddDebug, rate, portPrefix, dataToDump[i], logToFile);
686 if (ddBoard.view(istmp))
688 yInfo(
"getInteractionModes::The time stamp initalization interfaces was successfull! \n");
689 myGetInteractionModes.
setStamp(istmp);
692 yError(
"Problems getting the time stamp interfaces \n");
693 myDumper[i].
setGetter(&myGetInteractionModes);
696 else if (dataToDump[i] ==
"getPositionErrors")
698 if (ddBoard.view(ipid))
700 yInfo(
"Initializing a getErrs thread\n");
701 myDumper[i].
setDevice(&ddBoard, &ddDebug, rate, portPrefix, dataToDump[i], logToFile);
704 if (ddBoard.view(istmp))
706 yInfo(
"getPositionErrors::The time stamp initalization interfaces was successfull! \n");
710 yError(
"Problems getting the time stamp interfaces \n");
714 else if (dataToDump[i] ==
"getOutputs")
716 if (ddBoard.view(ipid))
718 yInfo(
"Initializing a getOuts thread\n");
719 myDumper[i].
setDevice(&ddBoard, &ddDebug, rate, portPrefix, dataToDump[i], logToFile);
722 if (ddBoard.view(istmp))
724 yInfo(
"getOutputs::The time stamp initalization interfaces was successfull! \n");
728 yError(
"Problems getting the time stamp interfaces \n");
732 else if (dataToDump[i] ==
"getCurrents")
734 if (ddBoard.view(iamp))
736 yInfo(
"Initializing a getCurrs thread\n");
737 myDumper[i].
setDevice(&ddBoard, &ddDebug, rate, portPrefix, dataToDump[i], logToFile);
740 if (ddBoard.view(istmp))
742 yInfo(
"getCurrents::The time stamp initalization interfaces was successfull! \n");
746 yError(
"Problems getting the time stamp interfaces \n");
751 else if (dataToDump[i] ==
"getTorques")
753 if (ddBoard.view(itrq))
755 yInfo(
"Initializing a getTorques thread\n");
756 myDumper[i].
setDevice(&ddBoard, &ddDebug, rate, portPrefix, dataToDump[i], logToFile);
759 if (ddBoard.view(istmp))
761 yInfo(
"getTorques::The time stamp initalization interfaces was successfull! \n");
765 yError(
"Problems getting the time stamp interfaces \n");
770 else if (dataToDump[i] ==
"getTorqueErrors")
772 if (ddBoard.view(ipid))
774 yInfo(
"Initializing a getTorqueErrors thread\n");
775 myDumper[i].
setDevice(&ddBoard, &ddDebug, rate, portPrefix, dataToDump[i], logToFile);
778 if (ddBoard.view(istmp))
780 yInfo(
"getTorqueErrors::The time stamp initalization interfaces was successfull! \n");
784 yError(
"Problems getting the time stamp interfaces \n");
789 else if (dataToDump[i] ==
"getTemperatures")
791 if (ddBoard.view(imotenc))
793 yInfo(
"Initializing a getTemps thread\n");
794 myDumper[i].
setDevice(&ddBoard, &ddDebug, rate, portPrefix, dataToDump[i], logToFile);
797 if (ddBoard.view(istmp))
799 yInfo(
"getEncoders::The time stamp initalization interfaces was successfull! \n");
803 yError(
"Problems getting the time stamp interfaces \n");
807 else if (dataToDump[i] ==
"getMotorEncoders")
809 if (ddBoard.view(imotenc))
811 yInfo(
"Initializing a getEncs thread\n");
812 myDumper[i].
setDevice(&ddBoard, &ddDebug, rate, portPrefix, dataToDump[i], logToFile);
815 if (ddBoard.view(istmp))
817 yInfo(
"getEncoders::The time stamp initalization interfaces was successfull! \n");
821 yError(
"Problems getting the time stamp interfaces \n");
825 else if (dataToDump[i] ==
"getMotorEncoderSpeeds")
827 if (ddBoard.view(imotenc))
829 yInfo(
"Initializing a getSpeeds thread\n");
830 myDumper[i].
setDevice(&ddBoard, &ddDebug, rate, portPrefix, dataToDump[i], logToFile);
833 if (ddBoard.view(istmp))
835 yInfo(
"getEncodersSpeed::The time stamp initalization interfaces was successfull! \n");
839 yError(
"Problems getting the time stamp interfaces \n");
840 myDumper[i].
setGetter(&myGetMotorSpeeds);
843 else if (dataToDump[i] ==
"getMotorEncoderAccelerations")
845 if (ddBoard.view(imotenc))
847 yInfo(
"Initializing a getAccs thread\n");
848 myDumper[i].
setDevice(&ddBoard, &ddDebug, rate, portPrefix, dataToDump[i], logToFile);
851 if (ddBoard.view(istmp))
853 yInfo(
"getEncoderAccelerations::The time stamp initalization interfaces was successfull! \n");
857 yError(
"Problems getting the time stamp interfaces \n");
861 else if (dataToDump[i] ==
"getMotorsPwm")
863 if (ddBoard.view(iamp))
865 yInfo(
"Initializing a getMotPwm thread\n");
866 myDumper[i].
setDevice(&ddBoard, &ddDebug, rate, portPrefix, dataToDump[i], logToFile);
871 if(!ddBoard.view(ienc))
875 if (ddBoard.view(istmp))
877 yInfo(
"getMotorsPwm::The time stamp initalization interfaces was successfull! \n");
881 yError(
"Problems getting the time stamp interfaces \n");
887 for (
int i = 0; i < nData; i++)
900 yInfo(
"Stopping dumper class\n");
901 for(
int i = 0; i < nData; i++)
904 yInfo(
"Deleting dumper class\n");
908 yInfo(
"Closing the device driver\n");
909 if (ddBoard.isValid()) ddBoard.close();
910 yInfo(
"Device driver closed\n");
913 yInfo(
"Closing the debug interface\n");
914 if (ddDebug.isValid()) ddDebug.close();
915 yInfo(
"Debug interface closed\n");
929 rf.setDefaultContext(
"controlBoardDumper");
930 rf.setDefaultConfigFile(
"controlBoardDumper.ini");
932 rf.setDefault(
"part",
"head");
933 rf.setDefault(
"robot",
"icub");
934 rf.setDefault(
"rate",
"500");
935 rf.setDefault(
"joints",
"(0)");
936 rf.setDefault(
"dataToDump",
"(getEncoders getEncoderSpeeds getEncoderAccelerations getPositionErrors getOutputs getCurrents getTorques getTorqueErrors)");
937 rf.configure(
argc,argv);
939 if (rf.check(
"help"))
941 printf (
"\ncontrolBoardDumper usage:\n");
942 printf (
"1) controlBoardDumper --robot icub --part left_arm --rate 10 --joints \"(0 1 2)\" \n");
943 printf (
" All data from the controlBoarWrapper will be dumped, except for advanced debugInterface (default).\n");
944 printf (
"\n2) controlBoardDumper --robot icub --part left_arm --rate 10 --joints \"(0 1 2)\" --dataToDump \"(xxx xxx)\"\n");
945 printf (
" where xxx can be uset to select one (or more) from the following:\n");
946 printf (
" getEncoders (joint position)\n");
947 printf (
" getEncoderSpeeds (joint velocity)\n");
948 printf (
" getEncoderAccelerations (joint acceleration)\n");
949 printf (
" getPositionErrors (difference between desired and actual position)\n");
950 printf (
" getTorqueErrors (difference between desired and measured torque, if available)\n");
951 printf (
" getOutputs (Position Pid output)\n");
952 printf (
" getCurrents (current given to the motor)\n");
953 printf (
" getTorques (joint torques, if available)\n");
954 printf (
" getPosPidReferences (last position referenece)\n");
955 printf (
" getTrqPidReferences (last torque reference)\n");
956 printf (
" getMotorEncoders (motor encoder position)\n");
957 printf (
" getMotorEncoderSpeeds (motor encoder velocity)\n");
958 printf (
" getMotorEncoderAccelerations (motor encoder acceleration\n");
959 printf (
" getMotorsPwm (voltage (PWM) given to the motor)\n");
960 printf (
" getControlModes (joint control mode)\n");
961 printf (
" getInteractionModes (joint interaction mode)\n");
962 printf (
" getTemperatures (motor temperatures)\n");
963 printf (
"\n3) controlBoardDumper --robot icub --part left_arm --rate 10 --joints \"(0 1 2)\" --dataToDumpAll\n");
964 printf (
" All data from the controlBoarWrapper will be dumped, including data from the debugInterface (getRotorxxx).\n");
965 printf (
"\n --logToFile can be used to create log files storing the data\n\n");
970 if (!
yarp.checkNetwork())
972 yError()<<
"YARP server not available!";
977 return mod.runModule(rf);
virtual bool updateModule()
virtual bool configure(ResourceFinder &rf)
void setInterface(IEncoders *)
void setInterface(IControlMode *, int joints)
void setInterface(IAmplifierControl *)
void setStamp(IPreciselyTimed *)
void setInterface(IEncoders *)
void setInterface(IInteractionMode *, int joints)
void setInterface(IMotorEncoders *)
void setInterface(IMotorEncoders *)
void setInterface(IAmplifierControl *)
void setInterface(IMotorEncoders *)
void setInterface(IPidControl *)
void setInterface(IPidControl *)
void setInterface(IPidControl *)
void setInterface(IEncoders *)
void setInterface(IMotor *)
void setInterface(IPidControl *)
void setInterface(ITorqueControl *)
void setInterface(ITorqueControl *)
void setThetaMap(int *, int)
void setGetter(GetData *)
void setDevice(PolyDriver *board_d, PolyDriver *debug_d, int rate, std::string portPrefix, std::string dataToDump, bool logOnDisk)
int main(int argc, char *argv[])
int getDataToDump(ResourceFinder &rf, std::string *listOfData, int n, bool *needDebug)
int getNumberConstraints(ResourceFinder &rf, int &n)
#define NUMBER_OF_AVAILABLE_DEBUG_DATA_TO_DUMP
int getNumberDataToDump(ResourceFinder &rf, int &n)
void getRate(ResourceFinder &rf, int &r)
#define NUMBER_OF_AVAILABLE_STANDARD_DATA_TO_DUMP
int getNumberUsedJoints(ResourceFinder &rf, int &n)
int getUsedJointsMap(ResourceFinder &rf, int n, int *thetaMap)
std::string toString(const T &t)
Copyright (C) 2008 RobotCub Consortium.