11#include <yarp/os/LogStream.h>
12#include <yarp/os/Value.h>
71 static constexpr std::string_view
kClassName =
"CiA402MotionControl";
226 std::fill(this->jointTorques.
begin(), this->jointTorques.end(), 0.0);
227 std::fill(this->jointVelocities.
begin(), this->jointVelocities.end(), 0.0);
228 std::fill(this->motorCurrents.
begin(), this->motorCurrents.end(), 0.0);
229 std::fill(this->hasTorqueSP.
begin(), this->hasTorqueSP.end(),
false);
230 std::fill(this->hasCurrentSP.
begin(), this->hasCurrentSP.end(),
false);
232 std::fill(this->ppJointTargetsDeg.
begin(), this->ppJointTargetsDeg.end(), 0.0);
233 std::fill(this->ppTargetCounts.
begin(), this->ppTargetCounts.end(), 0);
234 std::fill(this->ppHasPosSP.
begin(), this->ppHasPosSP.end(),
false);
235 std::fill(this->ppIsRelative.
begin(), this->ppIsRelative.end(),
false);
237 std::fill(this->ppPulseCoolDown.
begin(), this->ppPulseCoolDown.end(),
false);
240 this->positionDirectJointTargetsDeg.end(),
243 this->positionDirectTargetCounts.end(),
250 this->jointTorques[axis] = 0.0;
251 this->jointVelocities[axis] = 0.0;
252 this->motorCurrents[axis] = 0.0;
253 this->hasTorqueSP[axis] =
false;
254 this->hasCurrentSP[axis] =
false;
255 this->ppJointTargetsDeg[axis] = 0.0;
256 this->ppTargetCounts[axis] = 0;
257 this->hasVelSP[axis] =
false;
258 this->ppHasPosSP[axis] =
false;
259 this->ppIsRelative[axis] =
false;
260 this->ppPulseHi[axis] =
false;
261 this->ppPulseCoolDown[axis] =
false;
262 this->positionDirectJointTargetsDeg[axis] = 0.0;
263 this->positionDirectTargetCounts[axis] = 0;
300 yarp::dev::InteractionModeEnum::VOCAB_IM_STIFF};
334 double shaftDeg = jointDeg;
339 const double cnt = (res ? (shaftDeg / 360.0) *
static_cast<double>(res) : 0.0);
340 long long q = llround(cnt);
345 return static_cast<int32_t
>(q);
355 const int32_t cAdj = inv ? -counts : counts;
384 const double shaftDeg = res ? (double(cAdj) / double(res)) * 360.0 : 0.0;
396 constexpr auto logPrefix =
"[setPositionCountsLimits]";
397 auto errorCode = this->ethercatManager.
writeSDO<int32_t>(this->firstSlave + axis,
404 "%s: setLimits: SDO write 0x607D:01 (min) failed for axis %d",
410 errorCode = this->ethercatManager.
writeSDO<int32_t>(this->firstSlave + axis,
417 "%s: setLimits: SDO write 0x607D:02 (max) failed for axis %d",
431 constexpr auto logPrefix =
"[readEncoderResolutions]";
438 for (
size_t j = 0; j <
numAxes; ++j)
450 for (
size_t j = 0; j <
numAxes; ++j)
457 yCInfo(CIA402,
"%s successfully read encoder resolutions from SDO", logPrefix);
458 for (
size_t j = 0; j <
numAxes; ++j)
461 "%s j=%zu enc1_resolution=%u (inv=%.9f), enc2_resolution=%u (inv=%.9f)",
477 if (v == 0x00B44700u)
478 return {6.0, 1.0 / 6.0,
"1 RPM"};
479 if (v == 0xFFB44700u)
480 return {0.6, 1.0 / 0.6,
"0.1 RPM"};
481 if (v == 0xFEB44700u)
482 return {0.06, 1.0 / 0.06,
"0.01 RPM"};
483 if (v == 0xFDB44700u)
484 return {0.006, 1.0 / 0.006,
"0.001 RPM"};
486 if (v == 0x00B40300u)
487 return {360.0, 1.0 / 360.0,
"1 RPS"};
488 if (v == 0xFFB40300u)
489 return {36.0, 1.0 / 36.0,
"0.1 RPS"};
490 if (v == 0xFEB40300u)
491 return {3.6, 1.0 / 3.6,
"0.01 RPS"};
492 if (v == 0xFDB40300u)
493 return {0.36, 1.0 / 0.36,
"0.001 RPS"};
496 return {6.0, 1.0 / 6.0,
"UNKNOWN (assume 1 RPM)"};
501 constexpr auto logPrefix =
"[readSiVelocityUnits]";
506 for (
size_t j = 0; j <
numAxes; ++j)
511 uint32_t raw = 0x00B44700u;
514 auto [toDegS, toDev, name] = this->
decode60A9(raw);
520 "%s j=%zu 0x60A9=0x%08X velocity_unit=%s (1_unit=%.6f_deg/s)",
527 yWarning(
"%s j=%zu failed to read 0x60A9, assuming 1_RPM (1_unit=6_deg/s)",
532 yCInfo(CIA402,
"%s successfully read velocity conversion units from SDO", logPrefix);
567 const double shaftDeg = (counts / double(res)) * 360.0;
571 "loopCountsToJointDeg j=%zu counts=%.3f res=%u mount=%d -> shaftDeg=%.9f",
575 static_cast<int>(mount),
585 if (j < 0 || j >=
static_cast<int>(this->numAxes))
588 "%s: setPositionWindowDeg: invalid joint index",
592 const int s = this->firstSlave + j;
598 rawWin = 0xFFFFFFFFu;
601 rawWin =
static_cast<uint32_t
>(
606 auto e1 = this->ethercatManager.
writeSDO<uint32_t>(s, 0x6067, 0x00, rawWin);
610 "%s: setPositionWindowDeg: SDO 0x6067 write failed on joint %d",
615 auto e2 = this->ethercatManager.
writeSDO<uint32_t>(s, 0x6068, 0x00, rawTime);
619 "%s: setPositionWindowDeg: SDO 0x6068 write failed on joint %d",
629 constexpr auto logPrefix =
"[getPositionControlStrategy]";
638 "%s failed to read 0x2002:00",
644 "%s read position strategy %u from first axis",
646 static_cast<unsigned>(strategyValue));
652 constexpr auto logPrefix =
"[setPositionControlStrategy]";
654 for (
size_t j = 0; j <
numAxes; ++j)
656 const int slaveIdx =
firstSlave +
static_cast<int>(j);
662 "%s j=%zu failed to set 0x2002:00 (value=%u)",
665 static_cast<unsigned>(strategyValue));
671 "%s configured %zu axes with position strategy %u",
674 static_cast<unsigned>(strategyValue));
682 constexpr auto logPrefix =
"[readSimplePidGains]";
687 for (
size_t j = 0; j <
numAxes; ++j)
689 const int slaveIdx =
firstSlave +
static_cast<int>(j);
690 float32 kpValue = 0.0f;
691 float32 kdValue = 0.0f;
700 "%s j=%zu failed to read gains (errs=%d,%d)",
703 static_cast<int>(errKp),
704 static_cast<int>(errKd));
709 const double kpMotor_mNm_per_deg =
static_cast<double>(kpValue) / degPerCount;
710 const double kdMotor_mNmS_per_deg =
static_cast<double>(kdValue) / degPerCount;
712 kpNmPerDeg[j] = (kpMotor_mNm_per_deg *
gearRatio[j]) / 1000.0;
713 kdNmSecPerDeg[j] = (kdMotor_mNmS_per_deg *
gearRatio[j]) / 1000.0;
716 "%s j=%zu read gains: kp_device=%.3f[mNm/inc], kd_device=%.3f[mNm*s/inc] "
717 "=> kp_motor=%.6f[mNm/deg], kd_motor=%.6f[mNm*s/deg] => "
718 "kp_joint=%.6f[Nm/deg], kd_joint=%.6f[Nm*s/deg]",
724 kdMotor_mNmS_per_deg,
728 yCInfo(CIA402,
"%s read simple PID gains for %zu axes", logPrefix,
numAxes);
735 constexpr auto logPrefix =
"[configureSimplePidGains]";
740 "%s mismatched gain vector sizes (kp=%zu kd=%zu expected=%zu)",
743 kdNmSecPerDeg.
size(),
748 for (
size_t j = 0; j <
numAxes; ++j)
752 yCError(CIA402,
"%s j=%zu invalid gear ratio (0)", logPrefix, j);
757 if (degPerCount == 0.0)
760 "%s j=%zu cannot derive counts/deg (loop source missing)",
765 const double kpMotor_mNm_per_deg = (kpNmPerDeg[j] /
gearRatio[j]) * 1000.0;
766 const double kdMotor_mNmS_per_deg = (kdNmSecPerDeg[j] /
gearRatio[j]) * 1000.0;
768 const double kpDevice = kpMotor_mNm_per_deg * degPerCount;
769 const double kdDevice = kdMotor_mNmS_per_deg * degPerCount;
771 const float32 kpValue =
static_cast<float32
>(kpDevice);
772 const float32 kdValue =
static_cast<float32
>(kdDevice);
773 constexpr float32 kiValue = 0.0f;
777 "%s j=%zu computing gains: kp_joint=%.6f[Nm/deg], kd_joint=%.6f[Nm*s/deg], "
778 "gearRatio=%.6f, degPerCount=%.9f => kp_motor=%.6f[mNm/deg], "
779 "kd_motor=%.6f[mNm*s/deg] => kp_device=%.3f[mNm/inc], kd_device=%.3f[mNm*s/inc]",
787 kdMotor_mNmS_per_deg,
791 const int slaveIdx =
firstSlave +
static_cast<int>(j);
801 "%s j=%zu failed to program gains (errs=%d,%d,%d). Gains "
802 "Kp=%.3f[mNm/inc]=%.3f[Nm/deg], Kd=%.3f[mNm*s/inc]=%.3f[Nm*s/deg]",
805 static_cast<int>(errKp),
806 static_cast<int>(errKi),
807 static_cast<int>(errKd),
816 "%s j=%zu Kp=%.3f[mNm/inc] Kd=%.3f[mNm*s/inc]",
823 yCInfo(CIA402,
"%s programmed simple PID gains for %zu axes", logPrefix,
numAxes);
829 constexpr auto logPrefix =
"[readMotorConstants]";
834 for (
size_t j = 0; j <
numAxes; ++j)
837 int32_t tcMicroNmA = 0;
842 yWarning(
"%s j=%zu cannot read torque constant (0x2003:02) or zero, assuming 1.0 "
855 uint32_t ratedCurrentMilliA = 0;
856 double ratedCurrentA = 0.0;
859 || ratedCurrentMilliA == 0)
861 yWarning(
"%s j=%zu cannot read motor rated current (0x6075:00) or zero, assuming "
869 ratedCurrentA = double(ratedCurrentMilliA) * 1e-3;
873 uint16_t maxPermille = 0;
877 yWarning(
"%s j=%zu cannot read max current (0x6073:00), assuming 1000 per_mille",
884 "%s j=%zu max_current=%u_permille (%.3fA), torque_constant=%.6f_Nm/A",
888 (
double(maxPermille) / 1000.0) * ratedCurrentA,
889 this->torqueConstants[j]);
891 maxCurrentsA[j] = (double(maxPermille) / 1000.0) * ratedCurrentA;
894 yCInfo(CIA402,
"%s successfully read motor constants from SDO", logPrefix);
909 constexpr auto logPrefix =
"[readGearRatios]";
914 for (
size_t j = 0; j <
numAxes; ++j)
916 const int slaveIdx =
firstSlave +
static_cast<int>(j);
925 yWarning(
"%s j=%zu gear_ratio_numerator not available (0x6091:01), assuming 1",
936 yWarning(
"%s j=%zu gear_ratio_denominator not available/zero (0x6091:02), assuming "
944 "%s j=%zu gear_ratio=%u:%u (ratio=%.6f)",
949 static_cast<double>(num) /
static_cast<double>(den));
952 gearRatio[j] =
static_cast<double>(num) /
static_cast<double>(den);
956 for (
size_t j = 0; j <
numAxes; ++j)
961 yCInfo(CIA402,
"%s successfully read gear ratios from SDO", logPrefix);
967 constexpr auto logPrefix =
"[readTorqueValues]";
972 for (
size_t j = 0; j <
numAxes; ++j)
975 uint32_t rated_mNm = 0;
979 yCError(CIA402,
"%s j=%zu cannot read rated torque (0x6076:00)", logPrefix, j);
984 for (
size_t j = 0; j <
numAxes; ++j)
987 uint16_t maxPerm = 0;
991 yCError(CIA402,
"%s j=%zu cannot read max torque (0x6072:00)", logPrefix, j);
996 "%s j=%zu motor_rated_torque=%.3fNm max_torque=%.3fNm",
1003 yCInfo(CIA402,
"%s successfully read torque values from SDO", logPrefix);
1009 constexpr auto logPrefix =
"[configureMaxTorqueFromJointNm]";
1014 "%s invalid vector size (%zu), expected %zu",
1016 maxJointTorqueNm.
size(),
1021 for (
size_t j = 0; j <
numAxes; ++j)
1023 const double jointNm = maxJointTorqueNm[j];
1027 "%s j=%zu invalid max joint torque %.6f Nm (must be > 0)",
1037 "%s j=%zu invalid gear ratio %.6f",
1047 "%s j=%zu invalid rated motor torque %.6f Nm",
1054 constexpr uint16_t maxTorqueAdmissibleValue = 32767;
1055 const double motorNm = jointNm /
gearRatio[j];
1057 const double clamped = std::clamp(perThousand, 0.0,
static_cast<double>(maxTorqueAdmissibleValue));
1058 const uint16_t maxPerm =
static_cast<uint16_t
>(
std::llround(clamped));
1059 const int s =
firstSlave +
static_cast<int>(j);
1065 "%s j=%zu failed to write 0x6072:00",
1074 "%s j=%zu configured 0x6072 to %u permille (joint=%.6f Nm, motor=%.6f Nm)",
1077 static_cast<unsigned>(maxPerm),
1088 double shaft_deg_s = spDegS;
1089 switch (this->posLoopSrc[j])
1093 shaft_deg_s = spDegS * this->gearRatio[j];
1095 shaft_deg_s = spDegS;
1099 shaft_deg_s = spDegS * this->gearRatio[j];
1101 shaft_deg_s = spDegS;
1109 shaft_deg_s = spDegS * this->gearRatio[j];
1114 const int s = this->firstSlave + j;
1115 const int32_t vel =
static_cast<int32_t
>(
std::llround(shaft_deg_s * this->degSToVel[j]));
1116 (void)this->ethercatManager.
writeSDO<int32_t>(s, 0x6081, 0x00, vel);
1129 for (
size_t j = 0; j < this->numAxes; ++j)
1132 auto rx = this->ethercatManager.
getRxPDO(s);
1133 const int opMode = this->controlModeState.
active[j];
1136 rx->TargetPosition = 0;
1137 rx->TargetTorque = 0;
1138 rx->TargetVelocity = 0;
1141 if (opMode == VOCAB_CM_TORQUE)
1143 if (!this->trqLatched[j])
1145 rx->TargetTorque = 0;
1146 this->trqLatched[j] =
true;
1155 const int16_t tq_thousand =
static_cast<int16_t
>(
std::llround(
1158 rx->TargetTorque = this->invertedMotionSenseDirection[j] ? -tq_thousand
1164 if (opMode == VOCAB_CM_VELOCITY)
1168 rx->TargetVelocity = 0;
1179 double shaft_deg_s = joint_deg_s;
1187 shaft_deg_s = joint_deg_s *
gearRatio[j];
1189 shaft_deg_s = joint_deg_s;
1195 shaft_deg_s = joint_deg_s *
gearRatio[j];
1197 shaft_deg_s = joint_deg_s;
1209 const double vel = shaft_deg_s * this->degSToVel[j];
1210 rx->TargetVelocity =
static_cast<int32_t
>(
std::llround(vel))
1211 * (this->invertedMotionSenseDirection[j] ? -1 : 1);
1216 if (opMode == VOCAB_CM_POSITION)
1220 rx->Controlword |= (1u << 8);
1222 rx->Controlword &= ~(1u << 8);
1227 rx->Controlword |= (1u << 5);
1228 rx->Controlword &= ~(1u << 4);
1232 const double currentJointDeg = this->variables.
jointPositions[j];
1233 const int32_t seedStoreCounts
1248 const int32_t driveTargetCounts = this->invertedMotionSenseDirection[j]
1251 rx->TargetPosition = driveTargetCounts;
1262 rx->Controlword |= (1u << 5);
1267 rx->Controlword &= ~(1u << 4);
1272 int32_t targetPositionCounts = 0;
1277 rx->Controlword |= (1u << 6);
1279 rx->Controlword &= ~(1u << 6);
1282 targetPositionCounts = this->invertedMotionSenseDirection[j]
1287 rx->Controlword |= (1u << 4);
1295 auto tx = this->ethercatManager.
getTxView(s);
1296 targetPositionCounts = this->invertedMotionSenseDirection[j]
1302 targetPositionCounts);
1306 ? -targetPositionCounts
1307 : targetPositionCounts;
1313 rx->TargetPosition = targetPositionCounts;
1318 if (opMode == VOCAB_CM_POSITION_DIRECT)
1322 const double currentJointDeg = this->variables.
jointPositions[j];
1329 const int32_t driveCounts = this->invertedMotionSenseDirection[j]
1332 rx->TargetPosition = driveCounts;
1335 if (opMode == VOCAB_CM_CURRENT)
1337 if (!this->currLatched[j])
1340 rx->TargetTorque = 0;
1341 this->currLatched[j] =
true;
1349 const double torqueNm = currentA * this->torqueConstants[j];
1352 const int16_t tq_thousand =
static_cast<int16_t
>(
std::llround(
1355 rx->TargetTorque = this->invertedMotionSenseDirection[j] ? -tq_thousand
1374 auto shaftFromMount_pos = [&](
double deg,
Mount m,
size_t j,
bool asMotor) ->
double {
1381 return asMotor ? deg
1394 auto shaftFromMount_vel = [&](
double degs,
Mount m,
size_t j,
bool asMotor) ->
double {
1401 return asMotor ? degs *
gearRatio[j] : degs;
1406 for (
size_t j = 0; j < this->numAxes; ++j)
1408 const int s = this->firstSlave + int(j);
1409 auto tx = this->ethercatManager.
getTxView(s);
1488 const double k = this->velToDegS[j];
1512 return {double(v606C) * k,
enc1Mount[j]};
1514 return {double(v606C) * k,
enc2Mount[j]};
1520 return {double(v606C) * k,
enc2Mount[j]};
1523 return {double(v606C) * k,
enc1Mount[j]};
1525 return {double(v606C) * k,
enc2Mount[j]};
1537 auto [degJ_src, mountJ] = posDegOnOwnShaft(
posSrcJoint[j]);
1538 auto [degM_src, mountM] = posDegOnOwnShaft(
posSrcMotor[j]);
1541 const double jointDeg = shaftFromMount_pos(degJ_src, mountJ, j,
false);
1542 const double motorDeg = shaftFromMount_pos(degM_src, mountM, j,
true);
1546 = this->invertedMotionSenseDirection[j] ? -jointDeg : jointDeg;
1548 = this->invertedMotionSenseDirection[j] ? -motorDeg : motorDeg;
1557 auto [degsJ_src, mountJ] = velDegSOnOwnShaft(
velSrcJoint[j]);
1559 auto [degsM_src, mountM] = velDegSOnOwnShaft(
velSrcMotor[j]);
1563 const double jointDegS
1564 = shaftFromMount_vel(degsJ_src, mountJ, j,
false);
1565 const double motorDegS = shaftFromMount_vel(degsM_src, mountM, j,
true);
1569 = this->invertedMotionSenseDirection[j] ? -jointDegS : jointDegS;
1571 = this->invertedMotionSenseDirection[j] ? -motorDegS : motorDegS;
1584 const double tq_per_thousand
1586 const double motorNm = tq_per_thousand * this->ratedMotorTorqueNm[j];
1588 const double signedMotorNm = this->invertedMotionSenseDirection[j] ? -motorNm : motorNm;
1589 this->variables.
jointTorques[j] = signedMotorNm * this->gearRatio[j];
1590 this->variables.
motorCurrents[j] = signedMotorNm / this->torqueConstants[j];
1611 const uint32_t back = this->tsLastRaw[j] - raw;
1614 this->tsWraps[j] += 1u;
1618 this->tsLastRaw[j] = raw;
1620 const uint64_t us_ext
1648 case VOCAB_CM_FORCE_IDLE:
1650 case VOCAB_CM_POSITION:
1652 case VOCAB_CM_VELOCITY:
1654 case VOCAB_CM_TORQUE:
1655 case VOCAB_CM_CURRENT:
1657 case VOCAB_CM_POSITION_DIRECT:
1671 return (cstFlavor == VOCAB_CM_CURRENT) ? VOCAB_CM_CURRENT : VOCAB_CM_TORQUE;
1682 return VOCAB_CM_IDLE;
1684 return VOCAB_CM_POSITION;
1686 return VOCAB_CM_VELOCITY;
1688 return VOCAB_CM_POSITION_DIRECT;
1690 return VOCAB_CM_VELOCITY;
1692 return VOCAB_CM_TORQUE;
1694 return VOCAB_CM_UNKNOWN;
1704 return "VOCAB_CM_IDLE";
1705 case VOCAB_CM_FORCE_IDLE:
1706 return "VOCAB_CM_FORCE_IDLE";
1707 case VOCAB_CM_POSITION:
1708 return "VOCAB_CM_POSITION";
1709 case VOCAB_CM_VELOCITY:
1710 return "VOCAB_CM_VELOCITY";
1711 case VOCAB_CM_TORQUE:
1712 return "VOCAB_CM_TORQUE";
1713 case VOCAB_CM_CURRENT:
1714 return "VOCAB_CM_CURRENT";
1715 case VOCAB_CM_POSITION_DIRECT:
1716 return "VOCAB_CM_POSITION_DIRECT";
1735 return "Continuous over current (device internal)";
1737 return "Short circuit (device internal)";
1739 return "Load level fault (I2t, thermal state)";
1741 return "Load level warning (I2t, thermal state)";
1743 return "Phase failure";
1745 return "Phase failure L1";
1747 return "Phase failure L2";
1749 return "Phase failure L3";
1751 return "DC link over-voltage";
1753 return "DC link under-voltage";
1755 return "Field circuit interrupted";
1757 return "Excess temperature device";
1759 return "Excess temperature drive";
1763 return "Operating unit";
1765 return "Software reset (watchdog)";
1767 return "Parameter error";
1769 return "Motor blocked";
1773 return "Resolver 1 fault";
1775 return "Resolver 2 fault";
1777 return "Communication";
1779 return "Positioning controller (reference limit)";
1781 return "Sub-synchronous run";
1785 switch (code & 0xFF00)
1788 return "Current/device-internal fault";
1790 return "Motor/output circuit fault";
1792 return "Phase/mains supply issue";
1794 return "DC link voltage issue";
1796 return "Field/armature circuit issue";
1798 return "Excess temperature (device)";
1800 return "Excess temperature (drive)";
1802 return "Control device hardware / limits";
1804 return "Operating unit / safety";
1806 return "Software reset / watchdog";
1808 return "Parameter/configuration error";
1810 return "Motor blocked / mechanical issue";
1812 return "Sensor/encoder fault";
1814 return "Communication/internal";
1816 return "Positioning controller (vendor specific)";
1818 return "Timing/performance warning";
1821 std::snprintf(buf,
sizeof(buf),
"Unknown 0x603F error: 0x%04X", code);
1833 :
yarp::os::PeriodicThread(period, useSysClock,
yarp::os::PeriodicThreadClock::Absolute)
1834 , m_impl(
std::make_unique<
Impl>())
1839 :
yarp::os::PeriodicThread(0.001 ,
1840 yarp::os::ShouldUseSystemClock::Yes,
1841 yarp::os::PeriodicThreadClock::Absolute)
1842 , m_impl(
std::make_unique<
Impl>())
1852 constexpr auto logPrefix =
"[open]";
1857 if (!cfg.check(
"ifname") || !cfg.find(
"ifname").isString())
1859 yCError(CIA402,
"%s: 'ifname' parameter is not a string",
Impl::kClassName.data());
1862 if (!cfg.check(
"num_axes") || !cfg.find(
"num_axes").isInt32())
1864 yCError(CIA402,
"%s: 'num_axes' parameter is not an integer",
Impl::kClassName.data());
1868 if (!cfg.check(
"period") || !cfg.find(
"period").isFloat64())
1870 yCError(CIA402,
"%s: 'period' parameter is not a float64",
Impl::kClassName.data());
1873 const double period = cfg.find(
"period").asFloat64();
1876 yCError(CIA402,
"%s: 'period' parameter must be positive",
Impl::kClassName.data());
1879 this->setPeriod(period);
1880 yCDebug(CIA402,
"%s: using period = %.6f s", logPrefix, period);
1882 m_impl->numAxes =
static_cast<size_t>(cfg.find(
"num_axes").asInt32());
1883 m_impl->firstSlave = cfg.check(
"first_slave", yarp::os::Value(1)).asInt32();
1884 if (cfg.check(
"expected_slave_name"))
1885 m_impl->expectedName = cfg.find(
"expected_slave_name").asString();
1922 yWarning(
"%s: invalid mount '%s' (allowed: none|motor|joint) → 'none'",
1928 auto extractListOfStringFromSearchable = [
this](
const yarp::os::Searchable& cfg,
1934 if (!cfg.check(key))
1940 const yarp::os::Value& v = cfg.find(key);
1943 yCError(CIA402,
"%s: key '%s' is not a list",
Impl::kClassName.data(), key);
1947 const yarp::os::Bottle* lst = v.asList();
1951 "%s: internal error: list for key '%s' is null",
1957 const size_t expected =
static_cast<size_t>(m_impl->numAxes);
1958 const size_t actual =
static_cast<size_t>(lst->size());
1959 if (actual != expected)
1962 "%s: list for key '%s' has incorrect size (%zu), expected (%zu)",
1970 result.reserve(expected);
1971 for (
int i = 0; i < lst->size(); ++i)
1973 const yarp::os::Value& elem = lst->get(i);
1975 if (!elem.isString())
1978 "%s: element %d in list for key '%s' is not a string",
1989 if (!acceptedKeys.empty())
1991 if (
std::find(acceptedKeys.begin(), acceptedKeys.end(), val) == acceptedKeys.end())
1994 "%s: invalid value '%s' in list for key '%s'",
2008 auto extractListOfDoubleFromSearchable = [
this](
const yarp::os::Searchable& cfg,
2013 if (!cfg.check(key))
2019 const yarp::os::Value& v = cfg.find(key);
2022 yCError(CIA402,
"%s: key '%s' is not a list",
Impl::kClassName.data(), key);
2026 const yarp::os::Bottle* lst = v.asList();
2030 "%s: internal error: list for key '%s' is null",
2036 const size_t expected =
static_cast<size_t>(m_impl->numAxes);
2037 const size_t actual =
static_cast<size_t>(lst->size());
2038 if (actual != expected)
2041 "%s: list for key '%s' has incorrect size (%zu), expected (%zu)",
2049 result.reserve(expected);
2050 for (
int i = 0; i < lst->size(); ++i)
2052 const yarp::os::Value& elem = lst->get(i);
2054 if (!elem.isFloat64() && !elem.isInt32() && !elem.isInt64() && !elem.isFloat32())
2057 "%s: element %d in list for key '%s' is not a number",
2065 result.push_back(elem.asFloat64());
2071 auto extractListOfBoolFromSearchable = [
this](
const yarp::os::Searchable& cfg,
2076 if (!cfg.check(key))
2082 const yarp::os::Value& v = cfg.find(key);
2085 yCError(CIA402,
"%s: key '%s' is not a list",
Impl::kClassName.data(), key);
2089 const yarp::os::Bottle* lst = v.asList();
2093 "%s: internal error: list for key '%s' is null",
2099 const size_t expected =
static_cast<size_t>(m_impl->numAxes);
2100 const size_t actual =
static_cast<size_t>(lst->size());
2101 if (actual != expected)
2104 "%s: list for key '%s' has incorrect size (%zu), expected (%zu)",
2112 result.reserve(expected);
2113 for (
int i = 0; i < lst->size(); ++i)
2115 const yarp::os::Value& elem = lst->get(i);
2120 "%s: element %d in list for key '%s' is not a boolean",
2128 result.push_back(elem.asBool());
2140 if (!extractListOfStringFromSearchable(cfg,
"enc1_mount", {
"motor",
"joint"}, enc1MStr))
2142 if (!extractListOfStringFromSearchable(cfg,
"enc2_mount", {
"motor",
"joint",
"none"}, enc2MStr))
2149 if (!extractListOfStringFromSearchable(cfg,
2150 "position_feedback_joint",
2151 {
"6064",
"enc1",
"enc2"},
2154 if (!extractListOfStringFromSearchable(cfg,
2155 "position_feedback_motor",
2156 {
"6064",
"enc1",
"enc2"},
2159 if (!extractListOfStringFromSearchable(cfg,
2160 "velocity_feedback_joint",
2161 {
"606C",
"enc1",
"enc2"},
2164 if (!extractListOfStringFromSearchable(cfg,
2165 "velocity_feedback_motor",
2166 {
"606C",
"enc1",
"enc2"},
2176 constexpr uint16_t kPositionStrategySimplePid = 1u;
2177 constexpr uint16_t kPositionStrategyCascadedPid = 2u;
2178 const bool useSimplePidMode
2179 = cfg.check(
"use_simple_pid_mode") ? cfg.find(
"use_simple_pid_mode").asBool() :
false;
2180 const uint16_t desiredPositionStrategy
2181 = useSimplePidMode ? kPositionStrategySimplePid : kPositionStrategyCascadedPid;
2183 if (!extractListOfDoubleFromSearchable(cfg,
"position_window_deg", positionWindowDeg))
2185 if (!extractListOfDoubleFromSearchable(cfg,
"timing_window_ms", timingWindowMs))
2188 const bool hasMaxJointTorqueCfg = cfg.check(
"max_torque_joint_nm");
2189 if (hasMaxJointTorqueCfg
2190 && !extractListOfDoubleFromSearchable(cfg,
2191 "max_torque_joint_nm",
2192 maxJointTorqueNmFromConfig))
2197 const bool hasSimplePidKpCfg = cfg.check(
"simple_pid_kp_nm_per_deg");
2198 const bool hasSimplePidKdCfg = cfg.check(
"simple_pid_kd_nm_s_per_deg");
2199 const bool programSimplePidGains = hasSimplePidKpCfg || hasSimplePidKdCfg;
2200 if (hasSimplePidKpCfg != hasSimplePidKdCfg)
2203 "%s configuration must provide both simple_pid_kp_nm_per_deg and "
2204 "simple_pid_kd_nm_s_per_deg",
2208 if (programSimplePidGains)
2210 if (!extractListOfDoubleFromSearchable(cfg,
"simple_pid_kp_nm_per_deg", simplePidKpNmPerDeg))
2212 if (!extractListOfDoubleFromSearchable(cfg,
2213 "simple_pid_kd_nm_s_per_deg",
2214 simplePidKdNmSecPerDeg))
2218 for (
size_t j = 0; j < m_impl->numAxes; ++j)
2220 m_impl->enc1Mount.push_back(parseMount(enc1MStr[j]));
2221 m_impl->enc2Mount.push_back(parseMount(enc2MStr[j]));
2222 m_impl->posSrcJoint.push_back(parsePos(posSrcJointStr[j]));
2223 m_impl->posSrcMotor.push_back(parsePos(posSrcMotorStr[j]));
2224 m_impl->velSrcJoint.push_back(parseVel(velSrcJointStr[j]));
2225 m_impl->velSrcMotor.push_back(parseVel(velSrcMotorStr[j]));
2230 const int pdoTimeoutUs = cfg.check(
"pdo_timeout_us") ? cfg.find(
"pdo_timeout_us").asInt32()
2232 const bool enableDc = cfg.check(
"enable_dc") ? cfg.find(
"enable_dc").asBool() :
true;
2233 const int dcShiftNs = cfg.check(
"dc_shift_ns") ? cfg.find(
"dc_shift_ns").asInt32() : 0;
2234 yCInfo(CIA402,
"%s opening EtherCAT manager on interface %s", logPrefix, ifname.
c_str());
2236 if (!extractListOfBoolFromSearchable(cfg,
2237 "inverted_motion_sense_direction",
2238 m_impl->invertedMotionSenseDirection))
2243 for (
size_t i = 0; i < v.size(); ++i)
2245 s += (v[i] ?
"true" :
"false");
2246 if (i + 1 < v.size())
2253 "%s: inverted_motion_sense_direction = [%s]",
2255 vecBoolToString(m_impl->invertedMotionSenseDirection).c_str());
2261 const auto ecErr = m_impl->ethercatManager.init(ifname);
2265 "%s EtherCAT initialization failed with error code %d",
2267 static_cast<int>(ecErr));
2271 if (pdoTimeoutUs > 0)
2273 m_impl->ethercatManager.setPdoTimeoutUs(pdoTimeoutUs);
2275 "%s PDO receive timeout set to %d us",
2277 m_impl->ethercatManager.getPdoTimeoutUs());
2281 "%s using default PDO receive timeout of %d us",
2283 m_impl->ethercatManager.getPdoTimeoutUs());
2287 const uint32_t cycleNs =
static_cast<uint32_t
>(
std::llround(this->getPeriod() * 1e9));
2297 const int s = m_impl->firstSlave + int(j);
2299 auto e = m_impl->ethercatManager.readSDO<uint8_t>(s, 0x2012, 0x09, src);
2303 "%s: failed to read position loop source (joint %zu)",
2313 const int s = m_impl->firstSlave + int(j);
2315 auto e = m_impl->ethercatManager.readSDO<uint8_t>(s, 0x2011, 0x05, src);
2326 auto hasEnc1Pos = [&](
size_t j) {
2327 const int s = m_impl->firstSlave + int(j);
2330 auto hasEnc1Vel = [&](
size_t j) {
2331 const int s = m_impl->firstSlave + int(j);
2334 auto hasEnc2Pos = [&](
size_t j) {
2335 const int s = m_impl->firstSlave + int(j);
2338 auto hasEnc2Vel = [&](
size_t j) {
2339 const int s = m_impl->firstSlave + int(j);
2344 "%s using %zu axes, EtherCAT slaves %d to %d",
2348 m_impl->firstSlave +
int(m_impl->numAxes) - 1);
2354 for (
size_t j = 0; j < m_impl->numAxes; ++j)
2356 m_impl->posLoopSrc[j] = readPosLoopSrc(j);
2357 m_impl->velLoopSrc[j] = readVelLoopSrc(j);
2365 for (
size_t j = 0; j < m_impl->numAxes; ++j)
2367 auto bad = [&](
const char* what) {
2368 yCError(CIA402,
"%s j=%zu invalid configuration: %s", logPrefix, j, what);
2376 if (bad(
"pos_joint=enc1 but enc1 not mounted/mapped"))
2382 if (bad(
"pos_joint=enc2 but enc2 not mounted/mapped"))
2389 if (bad(
"pos_motor=enc1 but enc1 not mounted/mapped"))
2395 if (bad(
"pos_motor=enc2 but enc2 not mounted/mapped"))
2403 if (bad(
"vel_joint=enc1 but enc1 not mounted/mapped"))
2409 if (bad(
"vel_joint=enc2 but enc2 not mounted/mapped"))
2416 if (bad(
"vel_motor=enc1 but enc1 not mounted/mapped"))
2422 if (bad(
"vel_motor=enc2 but enc2 not mounted/mapped"))
2430 if (!m_impl->readEncoderResolutions())
2432 yCError(CIA402,
"%s failed to read encoder resolutions from SDO", logPrefix);
2435 if (!m_impl->readSiVelocityUnits())
2437 yCError(CIA402,
"%s failed to read velocity conversions from SDO", logPrefix);
2440 if (!m_impl->readGearRatios())
2442 yCError(CIA402,
"%s failed to read gear ratios from SDO", logPrefix);
2445 if (!m_impl->readMotorConstants())
2447 yCError(CIA402,
"%s failed to read motor constants from SDO", logPrefix);
2450 if (!m_impl->readTorqueValues())
2452 yCError(CIA402,
"%s failed to read torque values from SDO", logPrefix);
2456 if (hasMaxJointTorqueCfg)
2458 if (!m_impl->configureMaxTorqueFromJointNm(maxJointTorqueNmFromConfig))
2461 "%s failed to configure max torque (0x6072) from max_torque_joint_nm",
2468 "%s max_torque_joint_nm not provided: using drive 0x6072 values",
2473 uint16_t currentStrategy = 0;
2474 if (!m_impl->getPositionControlStrategy(currentStrategy))
2476 yCError(CIA402,
"%s failed to get current control strategy", logPrefix);
2480 "%s current control strategy is %u",
2482 static_cast<unsigned>(currentStrategy));
2486 "%s requested position strategy %u (%s)",
2488 static_cast<unsigned>(desiredPositionStrategy),
2489 useSimplePidMode ?
"simple PID" :
"cascaded PID");
2491 if (!m_impl->setPositionControlStrategy(desiredPositionStrategy))
2493 yCError(CIA402,
"%s failed to configure position control strategy", logPrefix);
2498 if (!m_impl->getPositionControlStrategy(currentStrategy))
2500 yCError(CIA402,
"%s failed to get current control strategy", logPrefix);
2504 "%s current control strategy after configuration is %u",
2506 static_cast<unsigned>(currentStrategy));
2508 const bool enableSimplePidGainsIo = (desiredPositionStrategy == kPositionStrategySimplePid);
2509 if (!enableSimplePidGainsIo && programSimplePidGains)
2512 "%s simple PID gains provided but position strategy is not simple PID; skipping "
2513 "0x2012 gains programming",
2517 if (enableSimplePidGainsIo && programSimplePidGains)
2519 if (!m_impl->configureSimplePidGains(simplePidKpNmPerDeg, simplePidKdNmSecPerDeg))
2521 yCError(CIA402,
"%s failed to program simple PID gains", logPrefix);
2524 }
else if (enableSimplePidGainsIo)
2527 "%s skipping simple PID gains programming (config keys not provided)",
2533 bool simplePidGainsAvailable =
false;
2534 if (enableSimplePidGainsIo)
2537 if (!m_impl->readSimplePidGains(readKp, readKd))
2539 yCError(CIA402,
"%s failed to read back simple PID gains", logPrefix);
2542 simplePidGainsAvailable =
true;
2544 for (
size_t j = 0; j < m_impl->numAxes; ++j)
2547 "%s j=%zu simple PID gains: Kp=%.6f Nm/deg, Kd=%.6f Nm·s/deg",
2558 if (!extractListOfDoubleFromSearchable(cfg,
2559 "pos_limit_min_deg",
2560 m_impl->limits.minPositionLimitDeg))
2562 yCError(CIA402,
"%s failed to parse pos_limit_min_deg", logPrefix);
2565 if (!extractListOfDoubleFromSearchable(cfg,
2566 "pos_limit_max_deg",
2567 m_impl->limits.maxPositionLimitDeg))
2569 yCError(CIA402,
"%s failed to parse pos_limit_max_deg", logPrefix);
2572 if (!extractListOfBoolFromSearchable(cfg,
2573 "use_position_limits_from_config",
2574 m_impl->limits.usePositionLimitsFromConfig))
2576 yCError(CIA402,
"%s failed to parse use_position_limits_from_config", logPrefix);
2580 if (m_impl->limits.minPositionLimitDeg.size() != m_impl->numAxes
2581 || m_impl->limits.maxPositionLimitDeg.size() != m_impl->numAxes
2582 || m_impl->limits.usePositionLimitsFromConfig.size() != m_impl->numAxes)
2585 "%s position limit lists must have exactly %zu elements",
2591 for (
size_t j = 0; j < m_impl->numAxes; ++j)
2593 const bool inv = m_impl->invertedMotionSenseDirection[j];
2595 if (m_impl->limits.usePositionLimitsFromConfig[j])
2598 const int32_t lowerCounts
2599 = m_impl->jointDegToTargetCounts(j, m_impl->limits.minPositionLimitDeg[j]);
2600 const int32_t upperCounts
2601 = m_impl->jointDegToTargetCounts(j, m_impl->limits.maxPositionLimitDeg[j]);
2603 int32_t minCounts = 0;
2604 int32_t maxCounts = 0;
2607 minCounts = lowerCounts;
2608 maxCounts = upperCounts;
2612 minCounts = -upperCounts;
2613 maxCounts = -lowerCounts;
2616 if (!m_impl->setPositionCountsLimits(j, minCounts, maxCounts))
2618 yCError(CIA402,
"%s j=%zu failed to set position limits", logPrefix, j);
2624 const int s = m_impl->firstSlave +
static_cast<int>(j);
2625 int32_t minCounts = 0;
2626 int32_t maxCounts = 0;
2627 auto e1 = m_impl->ethercatManager.readSDO<int32_t>(s, 0x607D, 0x01, minCounts);
2628 auto e2 = m_impl->ethercatManager.readSDO<int32_t>(s, 0x607D, 0x02, maxCounts);
2632 yCError(CIA402,
"%s j=%zu failed to read position limits from SDO", logPrefix, j);
2637 double minDeg = 0.0;
2638 double maxDeg = 0.0;
2641 minDeg = m_impl->targetCountsToJointDeg(j, minCounts);
2642 maxDeg = m_impl->targetCountsToJointDeg(j, maxCounts);
2646 minDeg = m_impl->targetCountsToJointDeg(j, maxCounts);
2647 maxDeg = m_impl->targetCountsToJointDeg(j, minCounts);
2650 m_impl->limits.minPositionLimitDeg[j] = minDeg;
2651 m_impl->limits.maxPositionLimitDeg[j] = maxDeg;
2658 for (
size_t j = 0; j < m_impl->numAxes; ++j)
2660 const int slave = m_impl->firstSlave +
static_cast<int>(j);
2661 auto* rx = m_impl->ethercatManager.getRxPDO(slave);
2664 yCError(CIA402,
"%s invalid slave index %d for axis %zu", logPrefix, slave, j);
2667 rx->Controlword = 0x0000;
2674 yCError(CIA402,
"%s initial EtherCAT send/receive after SDO reading failed", logPrefix);
2681 for (
int j = 0; j < m_impl->numAxes; ++j)
2683 if (!m_impl->setPositionWindowDeg(j, positionWindowDeg[j], timingWindowMs[j]))
2685 yCError(CIA402,
"%s j=%d failed to set position window", logPrefix, j);
2694 m_impl->variables.resizeContainers(m_impl->numAxes);
2695 m_impl->setPoints.
resize(m_impl->numAxes);
2696 m_impl->setPoints.reset();
2697 m_impl->controlModeState.resize(m_impl->numAxes);
2698 m_impl->sm.resize(m_impl->numAxes);
2699 m_impl->velLatched.assign(m_impl->numAxes,
false);
2700 m_impl->trqLatched.assign(m_impl->numAxes,
false);
2701 m_impl->currLatched.assign(m_impl->numAxes,
false);
2702 m_impl->posLatched.assign(m_impl->numAxes,
false);
2703 m_impl->torqueSeedNm.assign(m_impl->numAxes, 0.0);
2704 m_impl->tsLastRaw.assign(m_impl->numAxes, 0u);
2705 m_impl->tsWraps.assign(m_impl->numAxes, 0u);
2706 m_impl->ppState.ppRefSpeedDegS.assign(m_impl->numAxes, 0.0);
2707 m_impl->ppState.ppRefAccelerationDegSS.assign(m_impl->numAxes, 0.0);
2708 m_impl->ppState.ppHaltRequested.assign(m_impl->numAxes,
false);
2710 for (
size_t j = 0; j < m_impl->numAxes; ++j)
2712 m_impl->sm[j] = std::make_unique<CiA402::StateMachine>();
2713 m_impl->sm[j]->reset();
2717 if (!extractListOfStringFromSearchable(cfg,
"axes_names", {}, m_impl->variables.jointNames))
2720 constexpr double initialPositionVelocityDegs = 10;
2721 for (
size_t j = 0; j < m_impl->numAxes; ++j)
2726 m_impl->ppState.ppRefSpeedDegS[j] = initialPositionVelocityDegs;
2728 m_impl->setSDORefSpeed(j, initialPositionVelocityDegs);
2731 yCInfo(CIA402,
"%s opened %zu axes, initialization complete", logPrefix, m_impl->numAxes);
2737 const auto opErr = m_impl->ethercatManager.goOperational();
2740 yCError(CIA402,
"%s failed to enter OPERATIONAL state", logPrefix);
2747 = m_impl->ethercatManager.enableDCSync0(cycleNs, dcShiftNs);
2750 yCError(CIA402,
"%s failed to enable DC SYNC0", logPrefix);
2755 yWarning(
"%s DC synchronization disabled by configuration", logPrefix);
2766 yCError(CIA402,
"%s initial send/receive in OPERATIONAL failed", logPrefix);
2770 (void)m_impl->readFeedback();
2772 bool outOfLimits =
false;
2773 for (
size_t j = 0; j < m_impl->numAxes; ++j)
2775 const double posDeg = m_impl->variables.jointPositions[j];
2776 const double minDeg = m_impl->limits.minPositionLimitDeg[j];
2777 const double maxDeg = m_impl->limits.maxPositionLimitDeg[j];
2779 const bool belowMin = (posDeg < minDeg);
2780 const bool aboveMax = (posDeg > maxDeg);
2782 if (belowMin || aboveMax)
2784 const char* axisLabel =
nullptr;
2785 if (j < m_impl->variables.jointNames.size()
2786 && !m_impl->variables.jointNames[j].empty())
2788 axisLabel = m_impl->variables.jointNames[j].c_str();
2792 "%s joint %zu%s%s%s out of limits: pos=%.6f deg, min=%.6f, max=%.6f. "
2793 "Move the joint within limits before starting.",
2796 axisLabel ?
" (" :
"",
2797 axisLabel ? axisLabel :
"",
2798 axisLabel ?
")" :
"",
2809 for (
size_t j = 0; j < m_impl->numAxes; ++j)
2811 const int slave = m_impl->firstSlave +
static_cast<int>(j);
2812 auto* rx = m_impl->ethercatManager.getRxPDO(slave);
2815 rx->Controlword = 0x0000;
2820 (void)m_impl->ethercatManager.sendReceive();
2830 yCError(CIA402,
"%s failed to start device thread", logPrefix);
2835 "%s device thread started (position strategy=%u: %s)",
2837 static_cast<unsigned>(desiredPositionStrategy),
2838 useSimplePidMode ?
"simple PID" :
"cascaded PID");
2840 if (simplePidGainsAvailable)
2842 yCInfo(CIA402,
"%s simple PID gains:", logPrefix);
2843 for (
size_t j = 0; j < m_impl->numAxes; ++j)
2845 const char* axisLabel =
nullptr;
2846 if (j < m_impl->variables.jointNames.size() && !m_impl->variables.jointNames[j].empty())
2848 axisLabel = m_impl->variables.jointNames[j].c_str();
2851 const char*
open = axisLabel ?
" (" :
"";
2852 const char* label = axisLabel ? axisLabel :
"";
2853 const char*
close = axisLabel ?
")" :
"";
2856 "%s j=%zu%s%s%s Kp=%.6f Nm/deg, Kd=%.6f Nm\xC2\xB7s/deg",
2891 constexpr auto logPrefix =
"[run]";
2903 for (
size_t j = 0; j < m_impl->numAxes; ++j)
2905 const int slaveIdx = m_impl->firstSlave +
static_cast<int>(j);
2907 auto tx = m_impl->ethercatManager.getTxView(slaveIdx);
2909 const int tgt = m_impl->controlModeState.target[j];
2912 if (m_impl->controlModeState.active[j] == VOCAB_CM_HW_FAULT
2913 && tgt == VOCAB_CM_FORCE_IDLE)
2915 const auto cmd = m_impl->sm[j]->faultReset();
2919 m_impl->setPoints.reset((
int)j);
2920 m_impl->velLatched[j] = m_impl->trqLatched[j] = m_impl->currLatched[j] =
false;
2940 if (cmd.writeOpMode)
2950 m_impl->setSetPoints();
2958 "%s sendReceive() failed, expected_wkc=%d got_wkc=%d",
2960 m_impl->ethercatManager.getExpectedWorkingCounter(),
2961 m_impl->ethercatManager.getWorkingCounter());
2962 m_impl->ethercatManager.dumpDiagnostics();
2968 m_impl->readFeedback();
2976 for (
size_t j = 0; j < m_impl->numAxes; ++j)
2978 const int slaveIdx = m_impl->firstSlave +
static_cast<int>(j);
2979 auto tx = m_impl->ethercatManager.getTxView(slaveIdx);
2980 bool flavourChanged =
false;
2993 int newActive = VOCAB_CM_IDLE;
2996 newActive = VOCAB_CM_HW_FAULT;
2997 }
else if (!hwInhibit && enabled)
2999 const int activeOp = m_impl->sm[j]->getActiveOpMode();
3005 int flavor = m_impl->controlModeState.cstFlavor[j];
3007 if (flavor != VOCAB_CM_CURRENT && flavor != VOCAB_CM_TORQUE)
3009 flavor = VOCAB_CM_TORQUE;
3015 = (flavor != m_impl->controlModeState.prevCstFlavor[j])
3016 || (m_impl->controlModeState.prevCstFlavor[j] == VOCAB_CM_UNKNOWN);
3025 if (newActive == VOCAB_CM_IDLE || newActive == VOCAB_CM_HW_FAULT
3026 || newActive == VOCAB_CM_FORCE_IDLE)
3028 m_impl->setPoints.reset(j);
3029 m_impl->velLatched[j] = m_impl->trqLatched[j] = m_impl->posLatched[j]
3030 = m_impl->currLatched[j] =
false;
3033 m_impl->controlModeState.target[j] = VOCAB_CM_IDLE;
3038 if (m_impl->controlModeState.active[j] != newActive || flavourChanged)
3041 m_impl->velLatched[j] = m_impl->trqLatched[j] = m_impl->posLatched[j]
3042 = m_impl->currLatched[j] =
false;
3043 m_impl->setPoints.reset(j);
3046 m_impl->controlModeState.active[j] = newActive;
3047 m_impl->controlModeState.prevCstFlavor[j] = m_impl->controlModeState.cstFlavor[j];
3052 constexpr double printingIntervalSec = 30.0;
3056 m_impl->runTimeAccumSec += dtSec;
3057 m_impl->runTimeSamples += 1;
3058 const auto windowSec
3061 if (windowSec >= printingIntervalSec)
3064 = (m_impl->runTimeSamples > 0)
3065 ? (m_impl->runTimeAccumSec /
static_cast<double>(m_impl->runTimeSamples)) * 1000.0
3067 yCInfoThrottle(CIA402,
3068 printingIntervalSec,
3069 "%s %.1fs window: avg run() time = %.3f ms (frequency=%.1f Hz) over %zu "
3070 "cycles (window=%.1fs) - Expected period=%.3f ms (%.1f Hz)",
3072 printingIntervalSec,
3074 (m_impl->runTimeSamples > 0) ? (1000.0 / avgMs) : 0.0,
3075 m_impl->runTimeSamples,
3077 this->getPeriod() * 1000.0,
3078 1.0 / this->getPeriod());
3079 m_impl->runTimeAccumSec = 0.0;
3080 m_impl->runTimeSamples = 0;
3081 m_impl->avgWindowStart = tEnd;
3096 *num =
static_cast<int>(m_impl->numAxes);
3102 yCError(CIA402,
"%s: resetMotorEncoder() not implemented",
Impl::kClassName.data());
3108 yCError(CIA402,
"%s: resetMotorEncoders() not implemented",
Impl::kClassName.data());
3115 "%s: setMotorEncoderCountsPerRevolution() not implemented",
3122 yCError(CIA402,
"%s: setMotorEncoder() not implemented",
Impl::kClassName.data());
3128 yCError(CIA402,
"%s: setMotorEncoders() not implemented",
Impl::kClassName.data());
3139 if (m >=
static_cast<int>(m_impl->numAxes))
3150 *cpr =
static_cast<double>(m_impl->enc1Res[m]);
3152 *cpr =
static_cast<double>(m_impl->enc2Res[m]);
3166 if (m >=
static_cast<int>(m_impl->numAxes))
3173 *v = m_impl->variables.motorEncoders[m];
3180 if (encs ==
nullptr)
3187 std::memcpy(encs, m_impl->variables.motorEncoders.data(), m_impl->numAxes *
sizeof(
double));
3195 if (encs ==
nullptr || time ==
nullptr)
3202 std::memcpy(encs, m_impl->variables.motorEncoders.data(), m_impl->numAxes *
sizeof(
double));
3203 std::memcpy(time, m_impl->variables.feedbackTime.data(), m_impl->numAxes *
sizeof(
double));
3210 if (encs ==
nullptr || time ==
nullptr)
3215 if (m >=
static_cast<int>(m_impl->numAxes))
3222 *encs = m_impl->variables.motorEncoders[m];
3223 *time = m_impl->variables.feedbackTime[m];
3235 if (m >=
static_cast<int>(m_impl->numAxes))
3242 *sp = m_impl->variables.motorVelocities[m];
3249 if (spds ==
nullptr)
3257 m_impl->variables.motorVelocities.data(),
3258 m_impl->numAxes *
sizeof(
double));
3270 if (m >=
static_cast<int>(m_impl->numAxes))
3277 *acc = m_impl->variables.motorAccelerations[m];
3284 if (accs ==
nullptr)
3292 m_impl->variables.motorAccelerations.data(),
3293 m_impl->numAxes *
sizeof(
double));
3303 if (encs ==
nullptr || time ==
nullptr)
3311 m_impl->variables.jointPositions.data(),
3312 m_impl->numAxes *
sizeof(
double));
3313 std::memcpy(time, m_impl->variables.feedbackTime.data(), m_impl->numAxes *
sizeof(
double));
3320 if (encs ==
nullptr || time ==
nullptr)
3325 if (j >=
static_cast<int>(m_impl->numAxes))
3332 *encs = m_impl->variables.jointPositions[j];
3333 *time = m_impl->variables.feedbackTime[j];
3345 *ax =
static_cast<int>(m_impl->numAxes);
3351 yCError(CIA402,
"%s: resetEncoder() not implemented",
Impl::kClassName.data());
3357 yCError(CIA402,
"%s: resetEncoders() not implemented",
Impl::kClassName.data());
3363 yCError(CIA402,
"%s: setEncoder() not implemented",
Impl::kClassName.data());
3369 yCError(CIA402,
"%s: setEncoders() not implemented",
Impl::kClassName.data());
3380 if (j >=
static_cast<int>(m_impl->numAxes))
3387 *v = m_impl->variables.jointPositions[j];
3394 if (encs ==
nullptr)
3402 m_impl->variables.jointPositions.data(),
3403 m_impl->numAxes *
sizeof(
double));
3415 if (j >=
static_cast<int>(m_impl->numAxes))
3422 *sp = m_impl->variables.jointVelocities[j];
3429 if (spds ==
nullptr)
3437 m_impl->variables.jointVelocities.data(),
3438 m_impl->numAxes *
sizeof(
double));
3445 if (spds ==
nullptr)
3450 if (j >=
static_cast<int>(m_impl->numAxes))
3457 *spds = m_impl->variables.jointAccelerations[j];
3464 if (accs ==
nullptr)
3472 m_impl->variables.jointAccelerations.data(),
3473 m_impl->numAxes *
sizeof(
double));
3484 if (j >=
static_cast<int>(m_impl->numAxes))
3493 name = m_impl->variables.jointNames[j];
3499 if (axis >=
static_cast<int>(m_impl->numAxes))
3501 yCError(CIA402,
"%s: joint %d out of range",
Impl::kClassName.data(), axis);
3504 type = yarp::dev::JointTypeEnum::VOCAB_JOINTTYPE_REVOLUTE;
3512 if (mode ==
nullptr)
3517 if (j >=
static_cast<int>(m_impl->numAxes))
3525 *mode = m_impl->controlModeState.active[j];
3532 if (modes ==
nullptr)
3540 std::memcpy(modes, m_impl->controlModeState.active.data(), m_impl->numAxes *
sizeof(
int));
3547 if (modes ==
nullptr || joints ==
nullptr)
3554 yCError(CIA402,
"%s: invalid number of joints %d",
Impl::kClassName.data(), n);
3560 for (
int k = 0; k < n; ++k)
3562 if (joints[k] >=
static_cast<int>(m_impl->numAxes))
3564 yCError(CIA402,
"%s: joint %d out of range",
Impl::kClassName.data(), joints[k]);
3567 modes[k] = m_impl->controlModeState.active[joints[k]];
3575 if (j >=
static_cast<int>(m_impl->numAxes))
3582 yCError(CIA402,
"%s: control mode %d not supported",
Impl::kClassName.data(), mode);
3587 m_impl->controlModeState.target[j] = mode;
3588 if (mode == VOCAB_CM_CURRENT || mode == VOCAB_CM_TORQUE)
3590 m_impl->controlModeState.cstFlavor[j] = mode;
3598 if (modes ==
nullptr || joints ==
nullptr)
3605 yCError(CIA402,
"%s: invalid number of joints %d",
Impl::kClassName.data(), n);
3609 for (
int k = 0; k < n; ++k)
3611 if (joints[k] >=
static_cast<int>(m_impl->numAxes))
3613 yCError(CIA402,
"%s: joint %d out of range",
Impl::kClassName.data(), joints[k]);
3616 m_impl->controlModeState.target[joints[k]] = modes[k];
3618 if (modes[k] == VOCAB_CM_CURRENT || modes[k] == VOCAB_CM_TORQUE)
3620 m_impl->controlModeState.cstFlavor[joints[k]] = modes[k];
3628 if (modes ==
nullptr)
3634 std::memcpy(m_impl->controlModeState.target.data(), modes, m_impl->numAxes *
sizeof(
int));
3636 for (
size_t j = 0; j < m_impl->numAxes; ++j)
3638 if (m_impl->controlModeState.target[j] == VOCAB_CM_CURRENT
3639 || m_impl->controlModeState.target[j] == VOCAB_CM_TORQUE)
3641 m_impl->controlModeState.cstFlavor[j] = m_impl->controlModeState.target[j];
3656 if (j >=
static_cast<int>(m_impl->numAxes))
3663 *t = m_impl->variables.jointTorques[j];
3678 std::memcpy(t, m_impl->variables.jointTorques.data(), m_impl->numAxes *
sizeof(
double));
3690 if (j >=
static_cast<int>(m_impl->numAxes))
3697 *t = m_impl->setPoints.jointTorques[j];
3711 std::memcpy(t, m_impl->setPoints.jointTorques.data(), m_impl->numAxes *
sizeof(
double));
3718 if (j >=
static_cast<int>(m_impl->numAxes))
3727 if (m_impl->controlModeState.active[j] != VOCAB_CM_TORQUE)
3730 "%s: setRefTorque rejected: TORQUE mode is not active for the joint %d",
3738 m_impl->setPoints.jointTorques[j] = t;
3739 m_impl->setPoints.hasTorqueSP[j] =
true;
3753 for (
size_t j = 0; j < m_impl->numAxes; ++j)
3755 if (m_impl->controlModeState.active[j] != VOCAB_CM_TORQUE)
3758 "%s: setRefTorques rejected: TORQUE mode is not active for the joint "
3768 std::memcpy(m_impl->setPoints.jointTorques.data(), t, m_impl->numAxes *
sizeof(
double));
3769 std::fill(m_impl->setPoints.hasTorqueSP.begin(), m_impl->setPoints.hasTorqueSP.end(),
true);
3775 if (t ==
nullptr || joints ==
nullptr)
3782 yCError(CIA402,
"%s: invalid number of joints %d",
Impl::kClassName.data(), n_joint);
3789 for (
int k = 0; k < n_joint; ++k)
3791 if (joints[k] >=
static_cast<int>(m_impl->numAxes))
3793 yCError(CIA402,
"%s: joint %d out of range",
Impl::kClassName.data(), joints[k]);
3796 if (m_impl->controlModeState.active[joints[k]] != VOCAB_CM_TORQUE)
3799 "%s: setRefTorques rejected: TORQUE mode is not active for the joint %d",
3808 for (
int k = 0; k < n_joint; ++k)
3810 m_impl->setPoints.jointTorques[joints[k]] = t[k];
3811 m_impl->setPoints.hasTorqueSP[joints[k]] =
true;
3818 if (min ==
nullptr || max ==
nullptr)
3823 if (j >=
static_cast<int>(m_impl->numAxes))
3830 *min = -m_impl->maxMotorTorqueNm[j] * m_impl->gearRatio[j];
3831 *max = m_impl->maxMotorTorqueNm[j] * m_impl->gearRatio[j];
3838 if (min ==
nullptr || max ==
nullptr)
3844 for (
size_t j = 0; j < m_impl->numAxes; ++j)
3846 min[j] = -m_impl->maxMotorTorqueNm[j] * m_impl->gearRatio[j];
3847 max[j] = m_impl->maxMotorTorqueNm[j] * m_impl->gearRatio[j];
3854 if (j >=
static_cast<int>(m_impl->numAxes))
3863 if (m_impl->controlModeState.active[j] != VOCAB_CM_VELOCITY)
3866 "%s: velocityMove rejected: VELOCITY mode is not active for the joint %d",
3876 m_impl->setPoints.jointVelocities[j] = spd;
3877 m_impl->setPoints.hasVelSP[j] =
true;
3883 if (spds ==
nullptr)
3892 for (
size_t j = 0; j < m_impl->numAxes; ++j)
3894 if (m_impl->controlModeState.active[j] != VOCAB_CM_VELOCITY)
3897 "%s: velocityMove rejected: VELOCITY mode is not active for the joint "
3907 std::memcpy(m_impl->setPoints.jointVelocities.data(), spds, m_impl->numAxes *
sizeof(
double));
3908 std::fill(m_impl->setPoints.hasVelSP.begin(), m_impl->setPoints.hasVelSP.end(),
true);
3919 if (joint >=
static_cast<int>(m_impl->numAxes))
3921 yCError(CIA402,
"%s: joint %d out of range",
Impl::kClassName.data(), joint);
3926 *vel = m_impl->setPoints.jointVelocities[joint];
3933 if (spds ==
nullptr)
3941 m_impl->setPoints.jointVelocities.data(),
3942 m_impl->numAxes *
sizeof(
double));
3949 if (vels ==
nullptr || joints ==
nullptr)
3956 yCError(CIA402,
"%s: invalid number of joints %d",
Impl::kClassName.data(), n_joint);
3962 for (
int k = 0; k < n_joint; ++k)
3964 if (joints[k] >=
static_cast<int>(m_impl->numAxes))
3966 yCError(CIA402,
"%s: joint %d out of range",
Impl::kClassName.data(), joints[k]);
3969 vels[k] = m_impl->setPoints.jointVelocities[joints[k]];
3981 if (j < 0 || j >=
static_cast<int>(m_impl->numAxes))
3983 yCError(CIA402,
"%s: setRefAcceleration: joint %d out of range",
Impl::kClassName.data(), j);
3990 accDegS2 = -accDegS2;
3994 constexpr double maxAcc = 10.0;
3995 if (accDegS2 > maxAcc)
3998 "%s: setRefAcceleration: joint %d: acceleration %.2f deg/s^2 too high, "
3999 "saturating to %.2f deg/s^2",
4008 int controlMode = -1;
4011 controlMode = m_impl->controlModeState.active[j];
4014 if (controlMode != VOCAB_CM_POSITION)
4020 const int s = m_impl->firstSlave + j;
4021 const int32_t acc =
static_cast<int32_t
>(
std::llround(accDegS2 * m_impl->degSToVel[j]));
4024 m_impl->ppState.ppRefAccelerationDegSS[j] = accDegS2;
4028 (void)m_impl->ethercatManager.writeSDO<int32_t>(s, 0x6083, 0x00, acc);
4029 (void)m_impl->ethercatManager.writeSDO<int32_t>(s, 0x6084, 0x00, acc);
4030 (void)m_impl->ethercatManager.writeSDO<int32_t>(s, 0x6085, 0x00, acc);
4039 yCError(CIA402,
"%s: setRefAccelerations: null pointer",
Impl::kClassName.data());
4043 for (
size_t j = 0; j < m_impl->numAxes; ++j)
4057 if (j >=
static_cast<int>(m_impl->numAxes))
4063 int controlMode = -1;
4066 controlMode = m_impl->controlModeState.active[j];
4069 if (controlMode == VOCAB_CM_POSITION)
4073 *acc = m_impl->ppState.ppRefAccelerationDegSS[j];
4083 if (accs ==
nullptr)
4089 for (
size_t j = 0; j < m_impl->numAxes; ++j)
4091 int controlMode = -1;
4094 controlMode = m_impl->controlModeState.active[j];
4097 if (controlMode == VOCAB_CM_POSITION)
4101 accs[j] = m_impl->ppState.ppRefAccelerationDegSS[j];
4116 if (j < 0 || j >=
static_cast<int>(m_impl->numAxes))
4118 yCError(CIA402,
"%s: stop: joint %d out of range",
Impl::kClassName.data(), j);
4122 int controlMode = -1;
4125 controlMode = m_impl->controlModeState.active[j];
4128 if (controlMode == VOCAB_CM_POSITION)
4131 m_impl->ppState.ppHaltRequested[j] =
true;
4138 m_impl->setPoints.jointVelocities[j] = 0.0;
4139 m_impl->setPoints.hasVelSP[j] =
true;
4149 for (
size_t j = 0; j < m_impl->numAxes; ++j)
4151 if (m_impl->controlModeState.active[j] == VOCAB_CM_POSITION)
4154 m_impl->ppState.ppHaltRequested[j] =
true;
4160 std::fill(m_impl->setPoints.jointVelocities.begin(),
4161 m_impl->setPoints.jointVelocities.end(),
4163 std::fill(m_impl->setPoints.hasVelSP.begin(), m_impl->setPoints.hasVelSP.end(),
true);
4170 if (spds ==
nullptr || joints ==
nullptr)
4177 yCError(CIA402,
"%s: invalid number of joints %d",
Impl::kClassName.data(), n_joint);
4184 for (
int k = 0; k < n_joint; ++k)
4186 if (joints[k] >=
static_cast<int>(m_impl->numAxes))
4188 yCError(CIA402,
"%s: joint %d out of range",
Impl::kClassName.data(), joints[k]);
4191 if (m_impl->controlModeState.active[joints[k]] != VOCAB_CM_VELOCITY)
4194 "%s: velocityMove rejected: VELOCITY mode is not active for the joint "
4204 for (
int k = 0; k < n_joint; ++k)
4206 m_impl->setPoints.jointVelocities[joints[k]] = spds[k];
4207 m_impl->setPoints.hasVelSP[joints[k]] =
true;
4217 if (accs ==
nullptr || joints ==
nullptr)
4224 yCError(CIA402,
"%s: invalid number of joints %d",
Impl::kClassName.data(), n_joint);
4234 if (accs ==
nullptr || joints ==
nullptr)
4246 if (joints ==
nullptr)
4253 yCError(CIA402,
"%s: invalid number of joints %d",
Impl::kClassName.data(), n_joint);
4259 for (
int k = 0; k < n_joint; ++k)
4261 if (joints[k] >=
static_cast<int>(m_impl->numAxes))
4263 yCError(CIA402,
"%s: joint %d out of range",
Impl::kClassName.data(), joints[k]);
4266 m_impl->setPoints.jointVelocities[joints[k]] = 0.0;
4267 m_impl->setPoints.hasVelSP[joints[k]] =
true;
4275 if (j < 0 || j >=
static_cast<int>(m_impl->numAxes))
4277 yCError(CIA402,
"%s: getLastJointFault: joint %d out of range",
Impl::kClassName.data(), j);
4281 const int slave = m_impl->firstSlave + j;
4285 auto err = m_impl->ethercatManager.readSDO<uint16_t>(slave, 0x603F, 0x00, code);
4289 "%s: getLastJointFault: SDO read 0x603F:00 failed (joint %d)",
4295 fault =
static_cast<int>(code);
4296 message = m_impl->describe603F(code);
4300 char report[8] = {0};
4301 auto err2 = m_impl->ethercatManager.readSDO(slave, 0x203F, 0x01, report);
4306 while (len <
sizeof(report) && report[len] !=
'\0')
4312 bool printable =
true;
4315 const unsigned char c =
static_cast<unsigned char>(report[i]);
4316 if (c < 0x20 || c > 0x7E)
4325 message +=
" — report: ";
4326 message.
append(report, len);
4329 char hex[3 * 8 + 1] = {0};
4331 for (
std::size_t i = 0; i < len && pos <= static_cast<int>(
sizeof(hex)) - 3; ++i)
4335 static_cast<unsigned char>(report[i]),
4336 (i + 1 < len) ?
" " :
"");
4337 message +=
" — report: [";
4348 if (j < 0 || j >=
static_cast<int>(m_impl->numAxes))
4350 yCError(CIA402,
"%s: positionMove: joint %d out of range",
Impl::kClassName.data(), j);
4354 int controlMode = -1;
4357 controlMode = m_impl->controlModeState.active[j];
4360 if (controlMode != VOCAB_CM_POSITION)
4363 "%s: positionMove rejected: POSITION mode not active for joint %d",
4370 m_impl->setPoints.ppJointTargetsDeg[j] = refDeg;
4371 m_impl->setPoints.ppTargetCounts[j] = m_impl->jointDegToTargetCounts(
size_t(j), refDeg);
4372 m_impl->setPoints.ppIsRelative[j] =
false;
4373 m_impl->setPoints.ppHasPosSP[j] =
true;
4374 m_impl->setPoints.ppPulseHi[j] =
true;
4389 for (
size_t j = 0; j < m_impl->numAxes; ++j)
4390 if (m_impl->controlModeState.active[j] != VOCAB_CM_POSITION)
4393 "%s: positionMove rejected: POSITION mode not active on joint %zu",
4401 for (
size_t j = 0; j < m_impl->numAxes; ++j)
4403 m_impl->setPoints.ppJointTargetsDeg[j] = refsDeg[j];
4404 m_impl->setPoints.ppTargetCounts[j] = m_impl->jointDegToTargetCounts(j, refsDeg[j]);
4405 m_impl->setPoints.ppIsRelative[j] =
false;
4406 m_impl->setPoints.ppHasPosSP[j] =
true;
4407 m_impl->setPoints.ppPulseHi[j] =
true;
4414 if (!joints || !refsDeg || n <= 0)
4421 for (
int k = 0; k < n; ++k)
4423 if (joints[k] < 0 || joints[k] >=
static_cast<int>(m_impl->numAxes))
4425 if (m_impl->controlModeState.active[joints[k]] != VOCAB_CM_POSITION)
4428 "%s: positionMove rejected: POSITION mode not active on joint %d",
4436 for (
int k = 0; k < n; ++k)
4438 const int j = joints[k];
4439 m_impl->setPoints.ppJointTargetsDeg[j] = refsDeg[k];
4440 m_impl->setPoints.ppTargetCounts[j] = m_impl->jointDegToTargetCounts(
size_t(j), refsDeg[k]);
4441 m_impl->setPoints.ppIsRelative[j] =
false;
4442 m_impl->setPoints.ppHasPosSP[j] =
true;
4443 m_impl->setPoints.ppPulseHi[j] =
true;
4450 if (j < 0 || j >=
static_cast<int>(m_impl->numAxes))
4454 if (m_impl->controlModeState.active[j] != VOCAB_CM_POSITION)
4457 "%s: relativeMove rejected: POSITION mode not active for joint %d",
4464 m_impl->setPoints.ppJointTargetsDeg[j] += deltaDeg;
4465 m_impl->setPoints.ppTargetCounts[j] = m_impl->jointDegToTargetCounts(
size_t(j), deltaDeg);
4466 m_impl->setPoints.ppIsRelative[j] =
true;
4467 m_impl->setPoints.ppHasPosSP[j] =
true;
4468 m_impl->setPoints.ppPulseHi[j] =
true;
4478 for (
size_t j = 0; j < m_impl->numAxes; ++j)
4479 if (m_impl->controlModeState.active[j] != VOCAB_CM_POSITION)
4483 for (
size_t j = 0; j < m_impl->numAxes; ++j)
4485 m_impl->setPoints.ppJointTargetsDeg[j] += deltasDeg[j];
4486 m_impl->setPoints.ppTargetCounts[j] = m_impl->jointDegToTargetCounts(j, deltasDeg[j]);
4487 m_impl->setPoints.ppIsRelative[j] =
true;
4488 m_impl->setPoints.ppHasPosSP[j] =
true;
4489 m_impl->setPoints.ppPulseHi[j] =
true;
4496 if (!joints || !deltasDeg || n <= 0)
4500 for (
int k = 0; k < n; ++k)
4501 if (m_impl->controlModeState.active[joints[k]] != VOCAB_CM_POSITION)
4505 for (
int k = 0; k < n; ++k)
4507 const int j = joints[k];
4508 m_impl->setPoints.ppJointTargetsDeg[j] += deltasDeg[k];
4509 m_impl->setPoints.ppTargetCounts[j]
4510 = m_impl->jointDegToTargetCounts(
size_t(j), deltasDeg[k]);
4511 m_impl->setPoints.ppIsRelative[j] =
true;
4512 m_impl->setPoints.ppHasPosSP[j] =
true;
4513 m_impl->setPoints.ppPulseHi[j] =
true;
4520 if (flag ==
nullptr)
4522 yCError(CIA402,
"%s: checkMotionDone: null pointer",
Impl::kClassName.data());
4526 if (j < 0 || j >=
static_cast<int>(m_impl->numAxes))
4528 yCError(CIA402,
"%s: checkMotionDone: joint %d out of range",
Impl::kClassName.data(), j);
4533 *flag = m_impl->variables.targetReached[j];
4539 if (flag ==
nullptr)
4541 yCError(CIA402,
"%s: checkMotionDone: null pointer",
Impl::kClassName.data());
4546 for (
size_t j = 0; j < m_impl->numAxes; ++j)
4548 flag[j] = m_impl->variables.targetReached[j];
4556 if (!joints || !flag || n <= 0)
4559 for (
int k = 0; k < n; ++k)
4571 if (j < 0 || j >=
static_cast<int>(m_impl->numAxes))
4573 yCError(CIA402,
"%s: setRefSpeed: joint %d out of range",
Impl::kClassName.data(), j);
4581 cm = m_impl->controlModeState.active[j];
4583 if (cm != VOCAB_CM_POSITION)
4586 "%s: setRefSpeed: POSITION mode not active for joint %d, not writing SDO",
4595 m_impl->ppState.ppRefSpeedDegS[j] = spDegS;
4598 m_impl->setSDORefSpeed(j, spDegS);
4605 if (spDegS ==
nullptr)
4607 yCError(CIA402,
"%s: setRefSpeeds: null pointer",
Impl::kClassName.data());
4610 for (
size_t j = 0; j < m_impl->numAxes; ++j)
4612 this->
setRefSpeed(
static_cast<int>(j), spDegS[j]);
4619 if (!joints || !spDegS || n <= 0)
4621 yCError(CIA402,
"%s: setRefSpeeds: invalid args",
Impl::kClassName.data());
4625 for (
int k = 0; k < n; ++k)
4634 if (!ref || j < 0 || j >=
static_cast<int>(m_impl->numAxes))
4641 *ref = m_impl->ppState.ppRefSpeedDegS[j];
4648 yCError(CIA402,
"%s: getRefSpeeds: null pointer",
Impl::kClassName.data());
4652 std::memcpy(spds, m_impl->ppState.ppRefSpeedDegS.data(), m_impl->numAxes *
sizeof(
double));
4658 if (!joints || !spds || n <= 0)
4660 yCError(CIA402,
"%s: getRefSpeeds: invalid args",
Impl::kClassName.data());
4664 for (
int k = 0; k < n; ++k)
4666 spds[k] = m_impl->ppState.ppRefSpeedDegS[joints[k]];
4673 if (!ref || j < 0 || j >=
static_cast<int>(m_impl->numAxes))
4675 yCError(CIA402,
"%s: getTargetPosition: invalid args",
Impl::kClassName.data());
4680 *ref = m_impl->setPoints.ppJointTargetsDeg[j];
4686 if (refs ==
nullptr)
4688 yCError(CIA402,
"%s: getTargetPositions: null pointer",
Impl::kClassName.data());
4693 std::memcpy(refs, m_impl->setPoints.ppJointTargetsDeg.data(), m_impl->numAxes *
sizeof(
double));
4699 if (!joints || !refs || n <= 0)
4701 yCError(CIA402,
"%s: getTargetPositions: invalid args",
Impl::kClassName.data());
4705 for (
int k = 0; k < n; ++k)
4707 refs[k] = m_impl->setPoints.ppJointTargetsDeg[joints[k]];
4716 if (j < 0 || j >=
static_cast<int>(m_impl->numAxes))
4718 yCError(CIA402,
"%s: setPosition: joint %d out of range",
Impl::kClassName.data(), j);
4724 if (m_impl->controlModeState.active[j] != VOCAB_CM_POSITION_DIRECT)
4727 "%s: setPosition rejected: POSITION_DIRECT mode is not active for joint %d",
4735 m_impl->setPoints.positionDirectJointTargetsDeg[j] = refDeg;
4736 m_impl->setPoints.positionDirectTargetCounts[j]
4737 = m_impl->jointDegToTargetCounts(
static_cast<size_t>(j), refDeg);
4743 if (refs ==
nullptr)
4745 yCError(CIA402,
"%s: setPositions: null pointer",
Impl::kClassName.data());
4751 for (
size_t j = 0; j < m_impl->numAxes; ++j)
4753 if (m_impl->controlModeState.active[j] != VOCAB_CM_POSITION_DIRECT)
4756 "%s: setPositions rejected: POSITION_DIRECT mode is not active for joint "
4766 for (
size_t j = 0; j < m_impl->numAxes; ++j)
4768 m_impl->setPoints.positionDirectJointTargetsDeg[j] = refs[j];
4769 m_impl->setPoints.positionDirectTargetCounts[j]
4770 = m_impl->jointDegToTargetCounts(j, refs[j]);
4777 if (!joints || !refs)
4779 yCError(CIA402,
"%s: setPositions: null pointer",
Impl::kClassName.data());
4785 "%s: setPositions: invalid number of joints %d",
4793 for (
int k = 0; k < n_joint; ++k)
4795 if (joints[k] < 0 || joints[k] >=
static_cast<int>(m_impl->numAxes))
4798 "%s: setPositions: joint %d out of range",
4803 if (m_impl->controlModeState.active[joints[k]] != VOCAB_CM_POSITION_DIRECT)
4806 "%s: setPositions rejected: POSITION_DIRECT mode is not active for joint "
4816 for (
int k = 0; k < n_joint; ++k)
4818 const int j = joints[k];
4819 m_impl->setPoints.positionDirectJointTargetsDeg[j] = refs[k];
4820 m_impl->setPoints.positionDirectTargetCounts[j]
4821 = m_impl->jointDegToTargetCounts(
static_cast<size_t>(j), refs[k]);
4830 yCError(CIA402,
"%s: getRefPosition: null pointer",
Impl::kClassName.data());
4833 if (joint < 0 || joint >=
static_cast<int>(m_impl->numAxes))
4835 yCError(CIA402,
"%s: getRefPosition: joint %d out of range",
Impl::kClassName.data(), joint);
4840 *ref = m_impl->setPoints.positionDirectJointTargetsDeg[joint];
4848 yCError(CIA402,
"%s: getRefPositions: null pointer",
Impl::kClassName.data());
4854 m_impl->setPoints.positionDirectJointTargetsDeg.data(),
4855 m_impl->numAxes *
sizeof(
double));
4861 if (!joints || !refs)
4863 yCError(CIA402,
"%s: getRefPositions: null pointer",
Impl::kClassName.data());
4869 "%s: getRefPositions: invalid number of joints %d",
4876 for (
int k = 0; k < n_joint; ++k)
4878 if (joints[k] < 0 || joints[k] >=
static_cast<int>(m_impl->numAxes))
4881 "%s: getRefPositions: joint %d out of range",
4886 refs[k] = m_impl->setPoints.positionDirectJointTargetsDeg[joints[k]];
4895 yCError(CIA402,
"%s: getNumberOfMotors: null pointer",
Impl::kClassName.data());
4898 *num = m_impl->numAxes;
4909 if (m < 0 || m >=
static_cast<int>(m_impl->numAxes))
4915 *val = m_impl->variables.driveTemperatures[m];
4921 if (vals ==
nullptr)
4927 std::memcpy(vals, m_impl->variables.driveTemperatures.data(), m_impl->numAxes *
sizeof(
double));
4935 "%s: The getTemperatureLimit function is not implemented",
4944 "%s: The setTemperatureLimit function is not implemented",
4956 if (m < 0 || m >=
static_cast<int>(m_impl->numAxes))
4961 *val = m_impl->gearRatio[m];
4968 yCError(CIA402,
"%s: The setGearboxRatio function is not implemented",
Impl::kClassName.data());
4974 if (curr ==
nullptr)
4979 if (m < 0 || m >=
static_cast<int>(m_impl->numAxes))
4981 yCError(CIA402,
"%s: getCurrent: motor %d out of range",
Impl::kClassName.data(), m);
4985 *curr = m_impl->variables.motorCurrents[m];
4991 if (currs ==
nullptr)
4997 std::memcpy(currs, m_impl->variables.motorCurrents.data(), m_impl->numAxes *
sizeof(
double));
5003 if (min ==
nullptr || max ==
nullptr)
5005 yCError(CIA402,
"%s: getCurrentRange: null pointer",
Impl::kClassName.data());
5008 if (m < 0 || m >=
static_cast<int>(m_impl->numAxes))
5010 yCError(CIA402,
"%s: getCurrentRange: motor %d out of range",
Impl::kClassName.data(), m);
5014 *min = -m_impl->maxCurrentsA[m];
5015 *max = m_impl->maxCurrentsA[m];
5021 if (min ==
nullptr || max ==
nullptr)
5023 yCError(CIA402,
"%s: getCurrentRanges: null pointer",
Impl::kClassName.data());
5027 for (
size_t m = 0; m < m_impl->numAxes; ++m)
5029 min[m] = -m_impl->maxCurrentsA[m];
5030 max[m] = m_impl->maxCurrentsA[m];
5037 if (currs ==
nullptr)
5039 yCError(CIA402,
"%s: setRefCurrents: null pointer",
Impl::kClassName.data());
5046 for (
size_t j = 0; j < m_impl->numAxes; ++j)
5048 if (m_impl->controlModeState.active[j] != VOCAB_CM_CURRENT)
5051 "%s: setRefCurrents rejected: CURRENT mode is not active for the joint "
5061 std::memcpy(m_impl->setPoints.motorCurrents.data(), currs, m_impl->numAxes *
sizeof(
double));
5062 std::fill(m_impl->setPoints.hasCurrentSP.begin(), m_impl->setPoints.hasCurrentSP.end(),
true);
5068 if (m < 0 || m >=
static_cast<int>(m_impl->numAxes))
5070 yCError(CIA402,
"%s: setRefCurrent: motor %d out of range",
Impl::kClassName.data(), m);
5077 if (m_impl->controlModeState.active[m] != VOCAB_CM_CURRENT)
5080 "%s: setRefCurrent rejected: CURRENT mode is not active for the joint %d",
5088 m_impl->setPoints.motorCurrents[m] = curr;
5089 m_impl->setPoints.hasCurrentSP[m] =
true;
5096 if (currs ==
nullptr || motors ==
nullptr)
5098 yCError(CIA402,
"%s: setRefCurrents: null pointer",
Impl::kClassName.data());
5104 "%s: setRefCurrents: invalid number of motors %d",
5109 for (
int k = 0; k < n_motor; ++k)
5111 if (motors[k] < 0 || motors[k] >=
static_cast<int>(m_impl->numAxes))
5114 "%s: setRefCurrents: motor %d out of range",
5124 for (
int k = 0; k < n_motor; ++k)
5126 if (m_impl->controlModeState.active[motors[k]] != VOCAB_CM_CURRENT)
5129 "%s: setRefCurrents rejected: CURRENT mode is not active for the joint %d",
5138 for (
int k = 0; k < n_motor; ++k)
5140 m_impl->setPoints.motorCurrents[motors[k]] = currs[k];
5141 m_impl->setPoints.hasCurrentSP[motors[k]] =
true;
5148 if (currs ==
nullptr)
5150 yCError(CIA402,
"%s: getRefCurrents: null pointer",
Impl::kClassName.data());
5155 std::memcpy(currs, m_impl->setPoints.motorCurrents.data(), m_impl->numAxes *
sizeof(
double));
5161 if (curr ==
nullptr)
5163 yCError(CIA402,
"%s: getRefCurrent: null pointer",
Impl::kClassName.data());
5166 if (m < 0 || m >=
static_cast<int>(m_impl->numAxes))
5168 yCError(CIA402,
"%s: getRefCurrent: motor %d out of range",
Impl::kClassName.data(), m);
5173 *curr = m_impl->setPoints.motorCurrents[m];
5179 if (axis < 0 || axis >=
static_cast<int>(m_impl->numAxes))
5181 yCError(CIA402,
"%s: setLimits: axis %d out of range",
Impl::kClassName.data(), axis);
5187 if (!(min < 0.0 || max < 0.0) && (min >= max))
5190 "%s: setLimits: invalid limits [min=%g, max=%g]",
5199 m_impl->limits.maxPositionLimitDeg[axis] = max;
5200 m_impl->limits.minPositionLimitDeg[axis] = min;
5205 const bool inv = m_impl->invertedMotionSenseDirection[axis];
5206 const bool lowerLimitDisabled = (min < 0.0);
5207 const bool upperLimitDisabled = (max < 0.0);
5209 const auto lowerLimitCounts
5210 = lowerLimitDisabled ? 0 : m_impl->jointDegToTargetCounts(
size_t(axis), min);
5211 const auto upperLimitCounts
5212 = upperLimitDisabled ? 0 : m_impl->jointDegToTargetCounts(
size_t(axis), max);
5214 int32_t minCounts = 0;
5215 int32_t maxCounts = 0;
5228 return m_impl->setPositionCountsLimits(axis, minCounts, maxCounts);
5233 if (min ==
nullptr || max ==
nullptr)
5238 if (axis < 0 || axis >=
static_cast<int>(m_impl->numAxes))
5240 yCError(CIA402,
"%s: getLimits: axis %d out of range",
Impl::kClassName.data(), axis);
5245 *min = m_impl->limits.minPositionLimitDeg[axis];
5246 *max = m_impl->limits.maxPositionLimitDeg[axis];
5253 constexpr auto logPrefix =
"[setVelLimits] ";
5254 yCError(CIA402,
"%s: The setVelLimits function is not implemented", logPrefix);
5261 constexpr auto logPrefix =
"[getVelLimits] ";
5262 yCError(CIA402,
"%s: The getVelLimits function is not implemented", logPrefix);
5274 *mode = m_impl->dummyInteractionMode;
5280 yarp::dev::InteractionModeEnum* modes)
5282 if (!joints || !modes || n_joints <= 0)
5288 for (
int k = 0; k < n_joints; ++k)
5290 if (joints[k] < 0 || joints[k] >=
static_cast<int>(m_impl->numAxes))
5292 yCError(CIA402,
"%s: joint %d out of range",
Impl::kClassName.data(), joints[k]);
5295 modes[k] = m_impl->dummyInteractionMode;
5302 if (modes ==
nullptr)
5308 for (
size_t j = 0; j < m_impl->numAxes; ++j)
5310 modes[j] = m_impl->dummyInteractionMode;
5317 if (axis < 0 || axis >=
static_cast<int>(m_impl->numAxes))
5319 yCError(CIA402,
"%s: joint %d out of range",
Impl::kClassName.data(), axis);
5325 "%s: The setInteractionMode function is not implemented",
5332 yarp::dev::InteractionModeEnum* modes)
5334 if (!joints || !modes || n_joints <= 0)
5340 for (
int k = 0; k < n_joints; ++k)
5342 if (joints[k] < 0 || joints[k] >=
static_cast<int>(m_impl->numAxes))
5344 yCError(CIA402,
"%s: joint %d out of range",
Impl::kClassName.data(), joints[k]);
5351 "%s: The setInteractionModes function is not implemented",
5358 if (modes ==
nullptr)
5365 "%s: The setInteractionModes function is not implemented",
Minimal EtherCAT master built on SOEM for CiA-402 devices.
TxView getTxView(int slaveIndex) const noexcept
Obtain a typed, bounds-checked view over the TxPDO (slave→master).
const RxPDO * getRxPDO(int slaveIndex) const noexcept
Access the RxPDO (master→slave) buffer for a given slave.
Error readSDO(int slaveIndex, uint16_t idx, uint8_t subIdx, T &out) noexcept
Read an SDO value from a slave (blocking call).
@ NoError
Operation completed successfully.
Error writeSDO(int slaveIndex, uint16_t idx, uint8_t subIdx, const T &value) noexcept
Write an SDO value to a slave (blocking call).
static bool isOperationEnabled(uint16_t sw)
static bool isFault(uint16_t sw)
static bool isFaultReactionActive(uint16_t sw)
T get(TxField f, T fallback={}) const
Read a field from the TxPDO image with a typed accessor.
bool setGearboxRatio(int m, const double val) override
Sets the gearbox ratio of a specific motor.
bool setRefAcceleration(int j, double acc) override
(Unused in CSV mode) Sets the reference acceleration for a specific joint.
bool getTargetPosition(int j, double *ref) override
Gets the target position for a specific joint.
bool getCurrentRange(int m, double *min, double *max) override
Gets the allowable current range for a specific motor.
bool resetMotorEncoders() override
Resets all motor encoders to zero.
bool setRefCurrent(int m, double curr) override
Sets the reference current for a specific motor.
bool setEncoder(int j, double val) override
Sets the value of a specific encoder.
bool getVelLimits(int axis, double *min, double *max) override
Gets the velocity limits for a specific axis.
void run() override
Runs the periodic thread.
bool setMotorEncoder(int m, const double val) override
Sets the value of a specific motor encoder.
bool getRefVelocity(const int joint, double *vel) override
Gets the reference velocity for a specific joint.
bool setMotorEncoders(const double *vals) override
Sets the values of all motor encoders.
bool getNumberOfMotors(int *num) override
Gets the number of motors controlled by the device.
bool getEncoderAcceleration(int j, double *spds) override
Gets the acceleration of a specific encoder.
bool getEncoderSpeed(int j, double *sp) override
Gets the speed of a specific encoder.
bool getEncoders(double *encs) override
Gets the values of all encoders.
bool getEncoderSpeeds(double *spds) override
Gets the speeds of all encoders.
bool setVelLimits(int axis, double min, double max) override
Sets the velocity limits for a specific axis.
bool positionMove(int j, double ref) override
Commands an absolute position move for a specific joint using Profile Position Mode (PP).
bool getMotorEncoder(int m, double *v) override
Gets the value of a specific motor encoder.
bool getEncoderTimed(int j, double *encs, double *time) override
Gets the value and timestamp of a specific encoder.
bool getAxisName(int axis, std::string &name) override
Gets the name of a specific axis.
bool setPosition(int j, double ref) override
Streams a single joint reference in Cyclic Synchronous Position mode.
bool relativeMove(int j, double delta) override
Commands a relative position move for a specific joint.
bool getLastJointFault(int j, int &fault, std::string &message) override
Gets the last joint fault for a specific joint.
bool getJointType(int axis, yarp::dev::JointTypeEnum &type) override
Gets the type of a specific axis.
bool getRefPosition(const int joint, double *ref) override
Returns the most recent position-direct command for a joint.
bool getMotorEncoderCountsPerRevolution(int m, double *cpr) override
Gets the counts per revolution for a specific motor encoder.
~CiA402MotionControl() override
Destructor.
bool resetEncoders() override
Resets all encoders to zero.
bool getTargetPositions(double *refs) override
Gets the target positions for all joints.
bool setRefCurrents(const double *currs) override
Sets the reference currents for all motors.
bool getTorques(double *t) override
Gets the measured torques for all joints.
bool getRefCurrent(int m, double *curr) override
Gets the last commanded reference current for a specific motor.
bool getRefCurrents(double *currs) override
Gets the last commanded reference currents for all motors.
bool stop() override
Stops motion for all joints.
bool setRefTorques(const double *t) override
Sets the reference torques for all joints.
bool getControlMode(int j, int *mode) override
Gets the control mode of a specific joint.
bool getEncoderAccelerations(double *accs) override
Gets the accelerations of all encoders.
bool getRefSpeed(int j, double *ref) override
Gets the current reference speed (profile velocity) for a specific joint.
bool setLimits(int axis, double min, double max) override
Sets the position limits for a specific axis.
bool setInteractionModes(int n_joints, int *joints, yarp::dev::InteractionModeEnum *modes) override
Sets the interaction modes of a subset of joints.
bool setTemperatureLimit(int m, const double temp) override
Sets the temperature limit of a specific motor.
bool getTorque(int j, double *t) override
Gets the measured torque for a specific joint.
bool getRefPositions(double *refs) override
Returns the position-direct references for all joints.
bool getLimits(int axis, double *min, double *max) override
Gets the position limits for a specific axis.
bool velocityMove(int j, double sp) override
Commands a velocity move for a specific joint.
bool setMotorEncoderCountsPerRevolution(int m, const double cpr) override
Sets the counts per revolution for a specific motor encoder.
bool getRefVelocities(double *vels) override
Gets the reference velocities for all joints.
bool getEncodersTimed(double *encs, double *time) override
Gets the values and timestamps of all encoders.
bool getTorqueRanges(double *min, double *max) override
Gets the torque ranges for all joints.
bool getControlModes(int *modes) override
Gets the control modes of all joints.
bool resetEncoder(int j) override
Resets the specified encoder to zero.
bool setControlModes(const int n, const int *joints, int *modes) override
Sets the control modes of a subset of joints.
bool getMotorEncoderSpeed(int m, double *sp) override
Gets the speed of a specific motor encoder.
bool getMotorEncoders(double *encs) override
Gets the values of all motor encoders.
bool setPositions(const int n_joint, const int *joints, const double *refs) override
Streams references for a subset of joints.
bool setRefSpeed(int j, double sp) override
Sets the reference speed (profile velocity) for a specific joint.
bool getMotorEncoderAcceleration(int m, double *acc) override
Gets the acceleration of a specific motor encoder.
bool getEncoder(int j, double *v) override
Gets the value of a specific encoder.
bool getMotorEncoderTimed(int m, double *encs, double *time) override
Gets the value and timestamp of a specific motor encoder.
bool getCurrentRanges(double *min, double *max) override
Gets the allowable current ranges for all motors.
bool setControlMode(const int j, const int mode) override
Sets the control mode of a specific joint.
bool getTemperatureLimit(int m, double *temp) override
Gets the temperature limit of a specific motor.
bool getInteractionMode(int axis, yarp::dev::InteractionModeEnum *mode) override
Gets the interaction mode of a specific axis.
bool getRefAcceleration(int j, double *acc) override
(Unused in CSV mode) Gets the reference acceleration for a specific joint.
bool getCurrents(double *currs) override
Gets the measured currents of all motors.
bool checkMotionDone(int j, bool *flag) override
Checks if a specific joint has completed its motion.
CiA402MotionControl()
Default constructor.
bool stop(int j) override
Stops motion for a specific joint.
bool getGearboxRatio(int m, double *val) override
Gets the gearbox ratio of a specific motor.
bool open(yarp::os::Searchable &config) override
Opens the device driver.
bool getTemperature(int m, double *val) override
Gets the temperature of a specific motor.
bool setRefSpeeds(const double *spds) override
Sets the reference speeds (profile velocities) for all joints.
bool getInteractionModes(int n_joints, int *joints, yarp::dev::InteractionModeEnum *modes) override
Gets the interaction modes of a subset of joints.
bool setRefAccelerations(const double *accs) override
(Unused in CSV mode) Sets the reference accelerations for all joints.
bool getMotorEncodersTimed(double *encs, double *time) override
Gets the values and timestamps of all motor encoders.
bool getMotorEncoderAccelerations(double *accs) override
Gets the accelerations of all motor encoders.
bool getRefTorque(int j, double *t) override
Gets the reference torque for a specific joint.
bool setEncoders(const double *vals) override
Sets the values of all encoders.
bool close() override
Closes the device driver.
bool getNumberOfMotorEncoders(int *num) override
Gets the number of motor encoders.
bool getCurrent(int m, double *curr) override
Gets the measured current of a specific motor.
bool getAxes(int *ax) override
Gets the number of axes (encoders).
bool setRefTorque(int j, double t) override
Sets the reference torque for a specific joint.
bool getTemperatures(double *vals) override
Gets the temperatures of all motors.
bool getMotorEncoderSpeeds(double *spds) override
Gets the speeds of all motor encoders.
bool resetMotorEncoder(int m) override
Resets the specified motor encoder to zero.
bool getRefTorques(double *t) override
Gets the reference torques for all joints.
bool setInteractionMode(int axis, yarp::dev::InteractionModeEnum mode) override
Sets the interaction mode of a specific axis.
bool getTorqueRange(int j, double *min, double *max) override
Gets the torque range for a specific joint.
bool getRefAccelerations(double *accs) override
(Unused in CSV mode) Gets the reference accelerations for all joints.
bool getRefSpeeds(double *spds) override
Gets the current reference speeds (profile velocities) for all joints.
T duration_cast(T... args)
@ Velocity606C
0x606C: Velocity actual value
@ Enc2Pos2113_02
0x2113:02 Vendor enc2 position
@ SBC_6621_02
0x6621:02 Safe Brake Control status (exposed via PDO)
@ Enc2Vel2113_03
0x2113:03 Vendor enc2 velocity
@ OpModeDisplay
0x6061: Modes of operation display
@ Timestamp20F0
0x20F0: Timestamp (if supported)
@ Statusword
0x6041: Statusword
@ TemperatureDrive
0x2031:01 Temperature (if supported)
@ Position6064
0x6064: Position actual value
@ Torque6077
0x6077: Torque actual value
@ Enc1Pos2111_02
0x2111:02 Vendor enc1 position
@ Enc1Vel2111_03
0x2111:03 Vendor enc1 velocity
@ STO_6621_01
0x6621:01 Safe Torque Off status (exposed via PDO)
Process Data Object written from master to slave (RxPDO).
int8_t OpMode
0x6060: Modes of operation
uint16_t Controlword
0x6040: Controlword
std::vector< int > prevCstFlavor
std::vector< int > active
std::vector< int > cstFlavor
void resize(std::size_t n)
std::vector< int > target
std::vector< double > minPositionLimitDeg
std::vector< double > maxPositionLimitDeg
std::vector< bool > usePositionLimitsFromConfig
std::vector< double > ppRefSpeedDegS
std::vector< double > ppRefAccelerationDegSS
std::vector< bool > ppHaltRequested
std::vector< bool > ppPulseHi
void resize(std::size_t n)
std::vector< bool > hasCurrentSP
std::vector< double > positionDirectJointTargetsDeg
std::vector< double > jointVelocities
std::vector< bool > ppHasPosSP
std::vector< double > ppJointTargetsDeg
std::vector< bool > hasTorqueSP
std::vector< bool > ppIsRelative
std::vector< bool > hasVelSP
std::vector< bool > ppPulseCoolDown
std::vector< int32_t > ppTargetCounts
std::vector< double > motorCurrents
std::vector< double > jointTorques
std::vector< int32_t > positionDirectTargetCounts
std::vector< uint8_t > STO
std::vector< double > driveTemperatures
std::vector< double > jointAccelerations
std::vector< double > feedbackTime
std::vector< std::string > jointNames
std::vector< double > motorCurrents
std::vector< double > jointTorques
std::vector< double > jointPositions
std::vector< bool > targetReached
std::vector< double > motorVelocities
std::vector< uint8_t > SBC
std::vector< double > jointVelocities
std::vector< double > motorEncoders
void resizeContainers(std::size_t numAxes)
std::vector< double > motorAccelerations
static constexpr std::string_view kClassName
std::vector< double > maxCurrentsA
bool setPositionControlStrategy(uint16_t strategyValue)
static int ciaOpToYarp(int op)
std::vector< double > velToDegS
ControlModeState controlModeState
std::vector< double > ratedMotorTorqueNm
std::vector< double > gearRatio
std::vector< Mount > enc2Mount
static std::string_view yarpToString(int op)
std::vector< VelSrc > velSrcMotor
std::vector< PosSrc > posSrcMotor
std::vector< bool > trqLatched
yarp::dev::InteractionModeEnum dummyInteractionMode
std::vector< double > gearRatioInv
bool setPositionWindowDeg(int j, double winDeg, double winTime_ms)
std::vector< VelSrc > velSrcJoint
std::mutex CiA402MotionControlMutex
std::size_t runTimeSamples
std::vector< bool > posLatched
static constexpr uint64_t TIMESTAMP_WRAP_PERIOD_US
std::vector< double > torqueSeedNm
static std::tuple< double, double, const char * > decode60A9(uint32_t v)
std::string describe603F(uint16_t code)
VariablesReadFromMotors variables
bool readSiVelocityUnits()
std::vector< bool > currLatched
static constexpr uint32_t TIMESTAMP_WRAP_HALF_RANGE
int32_t jointDegToTargetCounts(size_t j, double jointDeg) const
std::vector< uint32_t > tsLastRaw
std::vector< double > torqueConstants
std::chrono::steady_clock::time_point avgWindowStart
std::vector< Mount > enc1Mount
double loopCountsToJointDeg(std::size_t j, double counts) const
PositionProfileState ppState
std::vector< double > maxMotorTorqueNm
std::vector< double > enc2ResInv
std::vector< std::unique_ptr< CiA402::StateMachine > > sm
std::vector< uint32_t > enc2Res
std::vector< uint32_t > enc1Res
bool readMotorConstants()
std::vector< uint64_t > tsWraps
std::vector< double > degSToVel
void setSDORefSpeed(int j, double spDegS)
static int yarpToCiaOp(int cm)
std::vector< double > enc1ResInv
std::vector< int > lastActiveMode
bool readSimplePidGains(std::vector< double > &kpNmPerDeg, std::vector< double > &kdNmSecPerDeg)
struct yarp::dev::CiA402MotionControl::Impl::Limits limits
std::vector< SensorSrc > posLoopSrc
bool readEncoderResolutions()
std::vector< SensorSrc > velLoopSrc
std::vector< PosSrc > posSrcJoint
bool configureSimplePidGains(const std::vector< double > &kpNmPerDeg, const std::vector< double > &kdNmSecPerDeg)
bool configureMaxTorqueFromJointNm(const std::vector< double > &maxJointTorqueNm)
::CiA402::EthercatManager ethercatManager
bool setPositionCountsLimits(int axis, int32_t minCounts, int32_t maxCounts)
static constexpr double MICROSECONDS_TO_SECONDS
bool getPositionControlStrategy(uint16_t &strategyValue)
int ciaOpToYarpWithFlavor(int op, int cstFlavor)
std::vector< bool > invertedMotionSenseDirection
double targetCountsToJointDeg(size_t j, int32_t counts) const
std::vector< bool > velLatched