10#include <yarp/os/Time.h>
11#include <yarp/dev/PolyDriver.h>
16#include <yarp/os/LogStream.h>
18using namespace yarp::os;
30static bool extractGroup(Bottle &input, Bottle &
out,
const std::string &key1,
const std::string &txt,
int size)
33 Bottle &tmp=input.findGroup(key1.c_str(), txt.c_str());
36 yError () << key1.c_str() <<
" not found\n";
42 yError () << key1.c_str() <<
" incorrect number of entries in board.";
55 original_max_pwm(NULL),
56 limited_max_pwm(NULL),
67 skipCalibration(false),
70 totJointsToCalibrate(0)
84 p.fromString(config.toString());
86 if (
p.check(
"GENERAL") ==
false)
88 yError() <<
"Parametric calibrator: missing [GENERAL] section";
92 if (
p.findGroup(
"GENERAL").check(
"deviceName"))
94 deviceName =
p.findGroup(
"GENERAL").find(
"deviceName").asString();
98 yError() <<
"Parametric calibrator: missing deviceName parameter";
103 if (config.findGroup(
"GENERAL").find(
"verbose").asInt32())
105 str = config.toString().c_str();
106 yTrace() << deviceName.c_str() << str;
110 Value val_clearHwFault = config.findGroup(
"GENERAL").find(
"clearHwFaultBeforeCalibration");
111 if (val_clearHwFault.isNull())
113 clearHwFault =
false;
117 if (!val_clearHwFault.isBool())
119 yError() << deviceName.c_str() <<
": clearHwFaultBeforeCalibration bool param is different from accepted values (true / false). Assuming false";
120 clearHwFault =
false;
124 clearHwFault = val_clearHwFault.asBool();
126 yInfo() << deviceName.c_str() <<
": clearHwFaultBeforeCalibration option enabled\n";
131 skipCalibration = config.findGroup(
"GENERAL").find(
"skipCalibration").asBool();
132 skipCalibration = !!skipCalibration;
135 yWarning() << deviceName <<
": skipping calibration!! This option was set in general.xml file.";
136 yWarning() << deviceName <<
": BE CAREFUL USING THE ROBOT IN THIS CONFIGURATION! See 'skipCalibration' param in config file";
140 if (
p.findGroup(
"GENERAL").check(
"joints"))
142 nj =
p.findGroup(
"GENERAL").find(
"joints").asInt32();
144 else if (
p.findGroup(
"GENERAL").check(
"Joints"))
147 nj =
p.findGroup(
"GENERAL").find(
"Joints").asInt32();
151 yError() << deviceName.c_str() <<
": missing joints parameter";
155 type =
new unsigned char[nj];
156 param1 =
new double[nj];
157 param2 =
new double[nj];
158 param3 =
new double[nj];
159 maxPWM =
new int[nj];
161 zeroPos =
new double[nj];
162 zeroVel =
new double[nj];
163 currPos =
new double[nj];
164 currVel =
new double[nj];
165 homePos =
new double[nj];
166 homeVel =
new double[nj];
167 zeroPosThreshold =
new double[nj];
171 Bottle& xtmp =
p.findGroup(
"CALIBRATION").findGroup(
"calibration1");
172 if (xtmp.size() - 1 != nj) { yError() << deviceName <<
": invalid number of Calibration1 params " << xtmp.size() <<
" " << nj;
return false; }
173 for (i = 1; i < xtmp.size(); i++) param1[i - 1] = xtmp.get(i).asFloat64();
175 xtmp =
p.findGroup(
"CALIBRATION").findGroup(
"calibration2");
176 if (xtmp.size() - 1 != nj) { yError() << deviceName <<
": invalid number of Calibration2 params";
return false; }
177 for (i = 1; i < xtmp.size(); i++) param2[i - 1] = xtmp.get(i).asFloat64();
179 xtmp =
p.findGroup(
"CALIBRATION").findGroup(
"calibration3");
180 if (xtmp.size() - 1 != nj) { yError() << deviceName <<
": invalid number of Calibration3 params";
return false; }
181 for (i = 1; i < xtmp.size(); i++) param3[i - 1] = xtmp.get(i).asFloat64();
183 xtmp =
p.findGroup(
"CALIBRATION").findGroup(
"calibrationType");
184 if (xtmp.size() - 1 != nj) { yError() << deviceName <<
": invalid number of Calibration3 params";
return false; }
185 for (i = 1; i < xtmp.size(); i++) type[i - 1] = (
unsigned char)xtmp.get(i).asFloat64();
187 xtmp =
p.findGroup(
"CALIBRATION").findGroup(
"startupPosition");
188 if (xtmp.size() - 1 != nj) { yError() << deviceName <<
": invalid number of startupPosition params";
return false; }
189 for (i = 1; i < xtmp.size(); i++) zeroPos[i - 1] = xtmp.get(i).asFloat64();
191 xtmp =
p.findGroup(
"CALIBRATION").findGroup(
"startupVelocity");
192 if (xtmp.size() - 1 != nj) { yError() << deviceName <<
": invalid number of startupVelocity params";
return false; }
193 for (i = 1; i < xtmp.size(); i++) zeroVel[i - 1] = xtmp.get(i).asFloat64();
195 xtmp =
p.findGroup(
"HOME").findGroup(
"positionHome");
196 if (xtmp.size() - 1 != nj) { yError() << deviceName <<
": invalid number of PositionHome params";
return false; }
197 for (i = 1; i < xtmp.size(); i++) homePos[i - 1] = xtmp.get(i).asFloat64();
199 xtmp =
p.findGroup(
"HOME").findGroup(
"velocityHome");
200 if (xtmp.size() - 1 != nj) { yError() << deviceName <<
": invalid number of VelocityHome params";
return false; }
201 for (i = 1; i < xtmp.size(); i++) homeVel[i - 1] = xtmp.get(i).asFloat64();
203 xtmp =
p.findGroup(
"CALIBRATION").findGroup(
"startupMaxPwm");
204 if (xtmp.size() - 1 != nj) { yError() << deviceName <<
": invalid number of startupMaxPwm params";
return false; }
205 for (i = 1; i < xtmp.size(); i++) maxPWM[i - 1] = xtmp.get(i).asInt32();
207 xtmp =
p.findGroup(
"CALIBRATION").findGroup(
"startupPosThreshold");
208 if (xtmp.size()-1!=nj) {yError() << deviceName <<
": invalid number of startupPosThreshold params";
return false;}
209 for (i = 1; i < xtmp.size(); i++) zeroPosThreshold[i-1] = xtmp.get(i).asFloat64();
211 calibJointsString =
p.findGroup(
"CALIB_ORDER");
212 int calib_order_size = calibJointsString.size();
213 if (calib_order_size <= 1) {yError() << deviceName <<
": invalid number CALIB_ORDER params";
return false;}
217 for(
int i=1; i<calibJointsString.size(); i++)
221 set= calibJointsString.get(i).asList();
223 for(
int j=0; j<set->size(); j++)
225 tmp.push_back(set->get(j).asInt32() );
227 joints.push_back(tmp);
239 if (param1 != NULL) {
243 if (param2 != NULL) {
247 if (param3 != NULL) {
252 if (maxPWM != NULL) {
256 if (original_max_pwm != NULL) {
257 delete[] original_max_pwm;
258 original_max_pwm = NULL;
260 if (limited_max_pwm != NULL) {
261 delete[] limited_max_pwm;
262 limited_max_pwm = NULL;
265 if (currPos != NULL) {
269 if (currVel != NULL) {
274 if (zeroPos != NULL) {
278 if (zeroVel != NULL) {
283 if (homePos != NULL) {
287 if (homeVel != NULL) {
297 yInfo() << deviceName <<
": starting calibration";
304 yError() << deviceName <<
": invalid device driver";
305 return ReturnValue::return_code::return_value_error_generic;
308 yarp::dev::PolyDriver *
p =
dynamic_cast<yarp::dev::PolyDriver *
>(device);
316 p->view(iControlMode);
325 yWarning() << deviceName <<
": using parametricCalibrator on an old iCubInterface system. Upgrade to robotInterface is recommended.";
326 device->view(iCalibrate);
327 device->view(iEncoders);
328 device->view(iPosition);
330 device->view(iControlMode);
334 if (!(iCalibrate && iEncoders && iPosition && iPids && iControlMode)) {
335 yError() << deviceName <<
": interface not found" << iCalibrate << iPosition << iPids << iControlMode;
336 return ReturnValue::return_code::return_value_error_generic;
339 return calibrate() ? ReturnValue_ok : ReturnValue::return_code::return_value_error_generic;
344 int setOfJoint_idx = 0;
345 totJointsToCalibrate = 0;
348 if (dev2calibrate==0)
350 yError() << deviceName <<
": not able to find a valid device to calibrate";
354 if ( !iEncoders->getAxes(n_joints))
356 yError() << deviceName <<
": error getting number of axes" ;
360 std::list<int> currentSetList;
361 std::list<std::list<int> >::iterator Bit=joints.begin();
362 std::list<std::list<int> >::iterator Bend=joints.end();
367 currentSetList.clear();
368 currentSetList = (*Bit);
369 std::list<int>::iterator lit = currentSetList.begin();
370 std::list<int>::iterator lend = currentSetList.end();
371 totJointsToCalibrate += currentSetList.size();
375 calibJoints.push_back(*lit);
382 for (
int i=0; i<totJointsToCalibrate; i++)
387 yDebug() << deviceName <<
": Joints calibration order:" << calibJointsString.toString();
389 if (totJointsToCalibrate > n_joints)
391 yError() << deviceName <<
": too much axis to calibrate for this part..." << totJointsToCalibrate <<
" bigger than "<< n_joints;
395 if (totJointsToCalibrate < n_joints)
397 yWarning() << deviceName <<
" is calibrating only a subset of the robot part. Calibrating " << totJointsToCalibrate <<
" over a total of " << n_joints;
400 original_max_pwm =
new double[n_joints];
401 limited_max_pwm =
new double[n_joints];
404 yWarning() << deviceName <<
": skipCalibration flag is on! Setting safe pid but skipping calibration.";
407 std::list<int>::iterator lit;
408 while( (Bit != Bend) && (!abortCalib) )
411 currentSetList.clear();
412 currentSetList = (*Bit);
415 for(lit = currentSetList.begin(); lit != currentSetList.end() && !abortCalib; lit++)
417 yWarning() << deviceName <<
"lit is " << *lit;
418 if ( ((*lit) <0) || ((*lit) >= n_joints) )
420 yError() << deviceName <<
": asked to calibrate joint" << (*lit) <<
", which is negative OR bigger than the number of axes for this part ("<< n_joints <<
")";
425 if(!iAmp->getPWMLimit((*lit), &original_max_pwm[(*lit)]) )
427 yError() << deviceName <<
": getPWMLimit joint " << (*lit) <<
"failed... aborting calibration";
432 limited_max_pwm[(*lit)] = original_max_pwm[(*lit)];
434 if (maxPWM[(*lit)]==0)
436 yDebug() << deviceName <<
": skipping maxPwm=0 of joint " << (*lit);
437 iAmp->setPWMLimit((*lit), original_max_pwm[(*lit)]);
441 if (maxPWM[(*lit)]<limited_max_pwm[(*lit)])
443 limited_max_pwm[(*lit)] = maxPWM[(*lit)];
444 iAmp->setPWMLimit((*lit), limited_max_pwm[(*lit)]);
448 yDebug() << deviceName <<
": joint " << (*lit) <<
" has max_output already limited to a safe value: " << limited_max_pwm[(*lit)];
463 for(lit = currentSetList.begin(); lit != currentSetList.end() && !abortCalib; lit++)
469 yDebug() <<
"In calibration " << deviceName <<
": enabling joint " << *lit <<
" to test hardware limit";
470 iControlMode->setControlMode((*lit), yarp::dev::SelectableControlModeEnum::VOCAB_CM_POSITION);
482 for(lit = currentSetList.begin(); lit != currentSetList.end() && !abortCalib; lit++)
486 calibrateJoint((*lit));
491 for(lit = currentSetList.begin(); lit != currentSetList.end(); lit++)
493 iEncoders->getEncoder((*lit), &currPos[(*lit)]);
494 yDebug() << deviceName <<
": set" << setOfJoint_idx <<
"j" << (*lit) <<
": Calibrating... enc values AFTER calib: " << currPos[(*lit)];
504 if(checkCalibrateJointEnded((*Bit)) )
506 yDebug() << deviceName <<
": set" << setOfJoint_idx <<
": Calibration ended, going to zero!\n";
510 yError() << deviceName <<
": set" << setOfJoint_idx <<
": Calibration went wrong! Disabling axes and keeping safe pid limit\n";
512 for(lit = currentSetList.begin(); lit != currentSetList.end() && !abortCalib; lit++)
514 iControlMode->setControlMode((*lit),yarp::dev::SelectableControlModeEnum::VOCAB_CM_IDLE);
521 for(lit = currentSetList.begin(); lit != currentSetList.end() && !abortCalib; lit++)
529 iControlMode->setControlMode((*lit), yarp::dev::SelectableControlModeEnum::VOCAB_CM_POSITION);
541 for(lit = currentSetList.begin(); lit != currentSetList.end() && !abortCalib; lit++)
555 bool goneToZero =
true;
556 for(lit = currentSetList.begin(); lit != currentSetList.end() && !abortCalib; lit++)
558 goneToZero &= checkGoneToZeroThreshold(*lit);
569 yDebug() << deviceName <<
": set" << setOfJoint_idx <<
": Reached zero position!\n";
570 for(lit = currentSetList.begin(); lit != currentSetList.end() && !abortCalib; lit++)
572 iAmp->setPWMLimit((*lit),original_max_pwm[(*lit)]);
577 yError() << deviceName <<
": set" << setOfJoint_idx <<
": some axis got timeout while reaching zero position... disabling this set of axes\n";
578 for(lit = currentSetList.begin(); lit != currentSetList.end() && !abortCalib; lit++)
580 iControlMode->setControlMode((*lit),yarp::dev::SelectableControlModeEnum::VOCAB_CM_IDLE);
590 yError() << deviceName <<
": calibration has been aborted!I'm going to disable all joints..." ;
591 for(lit = currentSetList.begin(); lit != currentSetList.end() && !abortCalib; lit++)
593 iControlMode->setControlMode(*lit, yarp::dev::SelectableControlModeEnum::VOCAB_CM_IDLE);
597 std::lock_guard<std::mutex> lck(calibMutex);
602bool parametricCalibrator::calibrateJoint(
int j)
604 if(std::find(calibJoints.begin(), calibJoints.end(), j) == calibJoints.end())
606 yError(
"%s cannot perform 'calibration' operation because joint number %d is out of range [%s].", deviceName.c_str(), j, calibJointsString.toString().c_str());
609 yInfo() << deviceName <<
": Calling calibrateJoint on joint "<< j <<
" with params: " << type[j] << param1[j] << param2[j] << param3[j];
610 return iCalibrate->calibrateAxisWithParams(j, type[j], param1[j], param2[j], param3[j]);
613bool parametricCalibrator::checkCalibrateJointEnded(std::list<int> set)
616 bool calibration_ok =
false;
618 std::list<int>::iterator lit;
619 std::list<int>::iterator lend;
624 calibration_ok =
true;
631 yWarning() << deviceName <<
": calibration aborted\n";
636 if( !(calibration_ok &= iCalibrate->calibrationDone((*lit))) )
645 yError() << deviceName <<
":Timeout while calibrating " << (*lit) <<
"\n";
647 yDebug() << deviceName <<
": calib joint ended";
649 return calibration_ok;
652bool parametricCalibrator::checkHwFault(
int j)
654 if(std::find(calibJoints.begin(), calibJoints.end(), j) == calibJoints.end())
656 yError(
"%s cannot perform 'check hw fault' operation because joint number %d is out of range [%s].", deviceName.c_str(), j, calibJointsString.toString().c_str());
660 yarp::dev::ControlModeEnum mode{};
661 iControlMode->getControlMode(j, mode);
662 if (mode == yarp::dev::ControlModeEnum::VOCAB_CM_HW_FAULT)
666 iControlMode->setControlMode(j,yarp::dev::SelectableControlModeEnum::VOCAB_CM_FORCE_IDLE);
667 yWarning() << deviceName <<
": detected an hardware fault on joint " << j <<
". An attempt will be made to clear it.";
669 iControlMode->getControlMode(j, mode);
670 if (mode == yarp::dev::ControlModeEnum::VOCAB_CM_HW_FAULT)
672 yError() << deviceName <<
": unable to clear the hardware fault detected on joint " << j <<
" before starting the calibration procedure!";
675 else if (mode == yarp::dev::ControlModeEnum::VOCAB_CM_IDLE)
677 yWarning() << deviceName <<
": hardware fault on joint " << j <<
" successfully cleared.";
682 yError() << deviceName <<
": an unknown error occured while trying the hardware fault on joint " << j ;
688 yError() << deviceName <<
": detected an hardware fault on joint " << j <<
" before starting the calibration procedure!";
695bool parametricCalibrator::goToZero(
int j)
697 if(std::find(calibJoints.begin(), calibJoints.end(), j) == calibJoints.end())
699 yError(
"%s cannot perform 'go to zero' operation because joint number %d is out of range [%s]!!", deviceName.c_str(), j, calibJointsString.toString().c_str());
704 if (abortCalib)
return true;
705 yDebug() << deviceName <<
": Sending positionMove to joint" << j <<
" (desired pos: " << zeroPos[j] <<
"desired speed: " << zeroVel[j] <<
" )";
706 ret = iPosition->setTrajSpeed(j, zeroVel[j]);
707 ret &= iPosition->positionMove(j, zeroPos[j]);
711bool parametricCalibrator::checkGoneToZeroThreshold(
int j)
713 if(std::find(calibJoints.begin(), calibJoints.end(), j) == calibJoints.end())
715 yError(
"%s cannot perform 'check gone to zero' operation because joint number %d is out of range [%s].", deviceName.c_str(), j, calibJointsString.toString().c_str());
719 if (skipCalibration)
return false;
722 bool finished =
false;
727 yarp::dev::ControlModeEnum mode{};
730 double start_time = yarp::os::Time::now();
731 while ( (!finished) && (!abortCalib))
733 iEncoders->getEncoder(j, &angj);
734 iPosition->checkMotionDone(j,
done);
735 iControlMode->getControlMode(j, mode);
736 iPids->getPidOutput(PidControlTypeEnum::VOCAB_PIDTYPE_POSITION, j, &output);
738 delta = fabs(angj-zeroPos[j]);
739 yDebug(
"%s: checkGoneToZeroThreshold: joint: %d curr: %.3f des: %.3f -> delta: %.3f threshold: %.3f output: %.3f mode: %s" ,deviceName.c_str(),j,angj, zeroPos[j],delta, zeroPosThreshold[j], output, yarp::os::Vocab32::decode(
static_cast<int>(mode)).c_str());
741 if (delta < zeroPosThreshold[j] &&
done)
743 yDebug(
"%s: checkGoneToZeroThreshold: joint: %d completed with delta: %.3f over: %.3f" ,deviceName.c_str(),j,delta, zeroPosThreshold[j]);
749 yError() << deviceName <<
": checkGoneToZeroThreshold: joint " << j <<
" Timeout while going to zero!";
752 if (mode == yarp::dev::ControlModeEnum::VOCAB_CM_IDLE)
754 yError() << deviceName <<
": checkGoneToZeroThreshold: joint " << j <<
" is idle, skipping!";
757 if (mode == yarp::dev::ControlModeEnum::VOCAB_CM_HW_FAULT)
759 yError() << deviceName <<
": checkGoneToZeroThreshold: hardware fault on joint " << j <<
", skipping!";
764 yWarning() << deviceName <<
": checkGoneToZeroThreshold: joint " << j <<
" Aborting wait while going to zero!\n";
781 yWarning() << deviceName <<
": Calling park without calibration... skipping";
783 return ReturnValue_ok;
789 yWarning() << deviceName <<
": skipCalibration flag is on!! Faking park!!";
790 return ReturnValue_ok;
792 std::vector<yarp::dev::ControlModeEnum> currentControlModes(n_joints, yarp::dev::ControlModeEnum::VOCAB_CM_UNKNOWN);
793 bool* cannotPark =
new bool [n_joints];
794 bool res = iControlMode->getControlModes(currentControlModes);
797 yError() << deviceName <<
": error getting control mode during parking";
800 std::list<int>::iterator lit;
801 for(lit = calibJoints.begin(); lit != calibJoints.end() && !abortCalib; lit++)
803 switch(currentControlModes[(*lit)])
805 case yarp::dev::ControlModeEnum::VOCAB_CM_IDLE:
807 yError() << deviceName <<
": joint " << (*lit) <<
" is idle, skipping park";
808 cannotPark[(*lit)] =
true;
812 case yarp::dev::ControlModeEnum::VOCAB_CM_HW_FAULT:
814 yError() << deviceName <<
": joint " << (*lit) <<
" has an hardware fault, skipping park";
815 cannotPark[(*lit)] =
true;
819 case yarp::dev::ControlModeEnum::VOCAB_CM_NOT_CONFIGURED:
821 yError() << deviceName <<
": joint " << (*lit) <<
" is not configured, skipping park";
822 cannotPark[(*lit)] =
true;
826 case yarp::dev::ControlModeEnum::VOCAB_CM_UNKNOWN:
828 yError() << deviceName <<
": joint " << (*lit) <<
" is in unknown state, skipping park";
829 cannotPark[(*lit)] =
true;
834 iControlMode->setControlMode((*lit), yarp::dev::SelectableControlModeEnum::VOCAB_CM_POSITION);
835 cannotPark[(*lit)] =
false;
840 iPosition->setTrajSpeeds(homeVel);
841 iPosition->positionMove(homePos);
847 for(lit = calibJoints.begin(); lit != calibJoints.end() && !abortCalib; lit++)
849 if (cannotPark[(*lit)] ==
false)
851 yDebug() << deviceName.c_str() <<
": Moving to park position, joint:" << (*lit);
853 iPosition->checkMotionDone((*lit),
done);
858 iPosition->checkMotionDone((*lit),
done);
862 yError() << deviceName <<
": joint " << (*lit) <<
" not in position after a timeout of" <<
PARK_TIMEOUT <<
" seconds";
868 yDebug() << deviceName.c_str() <<
": Park " << (abortParking ?
"aborted" :
"completed");
869 for(lit = calibJoints.begin(); lit != calibJoints.end() && !abortCalib; lit++)
872 switch(currentControlModes[(*lit)])
874 case yarp::dev::ControlModeEnum::VOCAB_CM_IDLE:
875 case yarp::dev::ControlModeEnum::VOCAB_CM_HW_FAULT:
876 case yarp::dev::ControlModeEnum::VOCAB_CM_NOT_CONFIGURED:
877 case yarp::dev::ControlModeEnum::VOCAB_CM_UNKNOWN:
882 iControlMode->setControlMode((*lit), yarp::dev::SelectableControlModeEnum::VOCAB_CM_IDLE);
886 return ReturnValue_ok;
891 yDebug() << deviceName.c_str() <<
": Quitting calibrate\n";
893 return ReturnValue_ok;
898 yDebug() << deviceName.c_str() <<
": Quitting parking\n";
900 return ReturnValue_ok;
910 if(std::find(calibJoints.begin(), calibJoints.end(), j) == calibJoints.end())
912 yError(
"%s cannot perform 'calibrate' operation because joint number %d is out of range [%s].", deviceName.c_str(), j, calibJointsString.toString().c_str());
913 return ReturnValue::return_code::return_value_error_generic;
915 return calibrateJoint(j) ? ReturnValue_ok : ReturnValue::return_code::return_value_error_generic;
921 return calibrate() ? ReturnValue_ok : ReturnValue::return_code::return_value_error_generic;
926 if(std::find(calibJoints.begin(), calibJoints.end(), j) == calibJoints.end())
928 yError(
"%s cannot perform 'homing' operation because joint number %d is out of range [%s].", deviceName.c_str(), j, calibJointsString.toString().c_str());
929 return ReturnValue::return_code::return_value_error_generic;
931 return goToZero(j) ? ReturnValue_ok : ReturnValue::return_code::return_value_error_generic;
938 std::list<int>::iterator lit;
939 for(lit = calibJoints.begin(); lit != calibJoints.end() && !abortCalib; lit++)
943 return ret ? ReturnValue_ok : ReturnValue::return_code::return_value_error_generic;
948 if(std::find(calibJoints.begin(), calibJoints.end(), j) == calibJoints.end())
950 yError(
"%s cannot perform 'park' operation because joint number %d is out of range [%s].", deviceName.c_str(), j, calibJointsString.toString().c_str());
951 return ReturnValue::return_code::return_value_error_generic;
960 yWarning() << deviceName <<
": Calling park without calibration... skipping";
962 return ReturnValue_ok;
968 yWarning() << deviceName <<
": skipCalibration flag is on!! Faking park!!";
969 return ReturnValue_ok;
972 yarp::dev::ControlModeEnum currentControlMode{};
974 bool res = iControlMode->getControlMode(j, currentControlMode);
977 yError() << deviceName <<
": error getting control mode during parking";
980 if(currentControlMode != yarp::dev::ControlModeEnum::VOCAB_CM_IDLE &&
981 currentControlMode != yarp::dev::ControlModeEnum::VOCAB_CM_HW_FAULT)
983 iControlMode->setControlMode(j, yarp::dev::SelectableControlModeEnum::VOCAB_CM_POSITION);
986 else if (currentControlMode == yarp::dev::ControlModeEnum::VOCAB_CM_IDLE)
988 yError() << deviceName <<
": joint " << j <<
" is idle, skipping park";
991 else if (currentControlMode == yarp::dev::ControlModeEnum::VOCAB_CM_HW_FAULT)
993 yError() << deviceName <<
": joint " << j <<
" has an hardware fault, skipping park";
997 iPosition->setTrajSpeed(j, homeVel[j]);
998 iPosition->positionMove(j, homePos[j]);
1004 if (cannotPark ==
false)
1006 yDebug() << deviceName.c_str() <<
": Moving to park position, joint:" << j;
1008 iPosition->checkMotionDone(j,
done);
1013 iPosition->checkMotionDone(j,
done);
1017 yError() << deviceName <<
": joint " << j <<
" not in position after a timeout of" <<
PARK_TIMEOUT <<
" seconds";
1022 yDebug() << deviceName.c_str() <<
": Park " << (abortParking ?
"aborted" :
"completed");
1023 iControlMode->setControlMode(j,yarp::dev::SelectableControlModeEnum::VOCAB_CM_IDLE);
1024 return ReturnValue_ok;
1032 yError() <<
"Device is not calibrated therefore cannot be parked";
1033 return ReturnValue::return_code::return_value_error_generic;
1036 return park(dev2calibrate) ? ReturnValue_ok : ReturnValue::return_code::return_value_error_generic;
virtual ReturnValue parkSingleJoint(int j, bool _wait=true) override
parametricCalibrator()
Default constructor.
virtual ReturnValue parkWholePart() override
virtual ReturnValue homingSingleJoint(int j) override
virtual ReturnValue quitPark() override
virtual bool close() override
Close the device driver.
virtual ReturnValue calibrateWholePart() override
~parametricCalibrator()
Destructor.
virtual ReturnValue calibrateSingleJoint(int j) override
virtual ReturnValue park(DeviceDriver *dd, bool wait=true) override
virtual ReturnValue quitCalibrate() override
virtual yarp::dev::IRemoteCalibrator * getCalibratorDevice()
virtual ReturnValue homingWholePart() override
ReturnValue calibrate(DeviceDriver *dd) override
Calibrate method.
virtual bool open(yarp::os::Searchable &config) override
Open the device driver.
const double GO_TO_ZERO_TIMEOUT
const int CALIBRATE_JOINT_TIMEOUT
static bool extractGroup(Bottle &input, Bottle &out, const std::string &key1, const std::string &txt, int size)
const double POSITION_THRESHOLD