Skip to content

Commit 5867ad4

Browse files
Add joint type handling to YarpSensorBridge in case of prismatic and revolute joints (#949)
1 parent d6e289c commit 5867ad4

File tree

3 files changed

+99
-12
lines changed

3 files changed

+99
-12
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ All notable changes to this project are documented in this file.
1111
- Enable Programmatic Creation of `VariableRegularizationTask` (https://github.com/ami-iit/bipedal-locomotion-framework/pull/934)
1212
- Check if the setpoint has been set at least once in TSID and IK (https://github.com/ami-iit/bipedal-locomotion-framework/pull/939)
1313
- Add motor temperature sensor support to `SensorBridge`, `YarpSensorBridge` and `YarpRobotLoggerDevice` (https://github.com/ami-iit/bipedal-locomotion-framework/pull/946)
14+
- Add the support to the joint type (revolute/prismatic) in `SensorBridge` (https://github.com/ami-iit/bipedal-locomotion-framework/pull/949)
1415

1516
### Changed
1617
- Some improvements on the YarpRobotLoggerDevice (https://github.com/ami-iit/bipedal-locomotion-framework/pull/910)

src/RobotInterface/YarpImplementation/include/BipedalLocomotion/RobotInterface/YarpSensorBridgeImpl.h

+88-12
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ struct YarpSensorBridge::Impl
187187
*/
188188
bool streamJointAccelerations{true}; /**< flag to enable reading joint accelerations from
189189
encoders */
190+
bool allJointsAreRevolutes{false}; /**< flag to indicate if all the joints are revolute */
191+
bool allJointsArePrismatics{false}; /**< flag to indicate if all the joints are prismatic */
190192

191193
using SubConfigLoader = bool (YarpSensorBridge::Impl::*)(
192194
std::weak_ptr<const BipedalLocomotion::ParametersHandler::IParametersHandler>,
@@ -1167,14 +1169,29 @@ struct YarpSensorBridge::Impl
11671169

11681170
// get the names of all the joints available in the attached remote control board remapper
11691171
std::vector<std::string> controlBoardJoints;
1172+
std::vector<JointType> controlBoardJointTypes;
11701173
int controlBoardDOFs;
11711174
controlBoardRemapperInterfaces.encoders->getAxes(&controlBoardDOFs);
11721175

11731176
std::string joint;
1177+
yarp::dev::JointTypeEnum jType;
11741178
for (int DOF = 0; DOF < controlBoardDOFs; DOF++)
11751179
{
11761180
controlBoardRemapperInterfaces.axis->getAxisName(DOF, joint);
1181+
controlBoardRemapperInterfaces.axis->getJointType(DOF, jType);
11771182
controlBoardJoints.push_back(joint);
1183+
if (jType != yarp::dev::VOCAB_JOINTTYPE_REVOLUTE
1184+
&& jType != yarp::dev::VOCAB_JOINTTYPE_PRISMATIC)
1185+
{
1186+
log()->error("{} Joint type not supported. Only revolute and prismatic joints are "
1187+
"supported.",
1188+
logPrefix);
1189+
return false;
1190+
}
1191+
1192+
controlBoardJointTypes.push_back(yarp::dev::VOCAB_JOINTTYPE_REVOLUTE == jType
1193+
? JointType::REVOLUTE
1194+
: JointType::PRISMATIC);
11781195
}
11791196

11801197
// if the joint list is empty means that the user did not pass a "joints_list" while the
@@ -1186,6 +1203,17 @@ struct YarpSensorBridge::Impl
11861203
metaData.bridgeOptions.nrJoints = metaData.sensorsList.jointsList.size();
11871204
}
11881205

1206+
metaData.sensorsList.jointsTypeList = controlBoardJointTypes;
1207+
1208+
this->allJointsArePrismatics
1209+
= std::all_of(metaData.sensorsList.jointsTypeList.begin(),
1210+
metaData.sensorsList.jointsTypeList.end(), //
1211+
[](const auto& jointType) { return jointType == JointType::PRISMATIC; });
1212+
this->allJointsAreRevolutes
1213+
= std::all_of(metaData.sensorsList.jointsTypeList.begin(),
1214+
metaData.sensorsList.jointsTypeList.end(), //
1215+
[](const auto& jointType) { return jointType == JointType::REVOLUTE; });
1216+
11891217
// reset the control board buffers
11901218
this->resetControlBoardBuffers();
11911219

@@ -1595,21 +1623,69 @@ struct YarpSensorBridge::Impl
15951623
}
15961624
}
15971625

1598-
// convert from degrees to radians - YARP convention is to store joint positions in
1599-
// degrees
1600-
controlBoardRemapperMeasures.jointPositions.noalias()
1601-
= controlBoardRemapperMeasures.remappedJointPermutationMatrix
1602-
* controlBoardRemapperMeasures.jointPositionsUnordered * M_PI / 180;
1626+
// Create aliases for clarity
1627+
auto& measures = controlBoardRemapperMeasures;
1628+
const auto& perm = measures.remappedJointPermutationMatrix;
16031629

1604-
controlBoardRemapperMeasures.jointVelocities.noalias()
1605-
= controlBoardRemapperMeasures.remappedJointPermutationMatrix
1606-
* controlBoardRemapperMeasures.jointVelocitiesUnordered * M_PI / 180;
1630+
// Helper lambda for uniform remapping and scaling.
1631+
auto remapAndScale = [&](auto& target,
1632+
const auto& source,
1633+
std::optional<double> scale = std::nullopt) {
1634+
if (!scale.has_value())
1635+
{
1636+
target.noalias() = perm * source;
1637+
return;
1638+
}
1639+
target.noalias() = perm * source * scale.value();
1640+
};
16071641

1608-
if (streamJointAccelerations)
1642+
// Helper lambda for mixed joints: remap then convert each revolute joint.
1643+
auto remapAndConvertMixed = [&](auto& target, const auto& source) {
1644+
target.noalias() = perm * source;
1645+
for (int i = 0; i < target.size(); ++i)
1646+
{
1647+
// Convert only revolute joints from degrees to radians.
1648+
if (metaData.sensorsList.jointsTypeList[i] == JointType::REVOLUTE)
1649+
{
1650+
target(i) = deg2rad(target(i));
1651+
}
1652+
}
1653+
};
1654+
1655+
// Process joint measures based on joint type configuration.
1656+
if (this->allJointsAreRevolutes)
16091657
{
1610-
controlBoardRemapperMeasures.jointAccelerations.noalias()
1611-
= controlBoardRemapperMeasures.remappedJointPermutationMatrix
1612-
* controlBoardRemapperMeasures.jointAccelerationsUnordered * M_PI / 180;
1658+
remapAndScale(measures.jointPositions,
1659+
measures.jointPositionsUnordered,
1660+
M_PI / 180.0);
1661+
remapAndScale(measures.jointVelocities,
1662+
measures.jointVelocitiesUnordered,
1663+
M_PI / 180.0);
1664+
if (streamJointAccelerations)
1665+
{
1666+
remapAndScale(measures.jointAccelerations,
1667+
measures.jointAccelerationsUnordered,
1668+
M_PI / 180.0);
1669+
}
1670+
} else if (this->allJointsArePrismatics)
1671+
{
1672+
remapAndScale(measures.jointPositions, measures.jointPositionsUnordered);
1673+
remapAndScale(measures.jointVelocities, measures.jointVelocitiesUnordered);
1674+
if (streamJointAccelerations)
1675+
{
1676+
remapAndScale(measures.jointAccelerations,
1677+
measures.jointAccelerationsUnordered);
1678+
}
1679+
} else // Mixed joints: some revolute and some prismatic.
1680+
{
1681+
remapAndConvertMixed(measures.jointPositions, measures.jointPositionsUnordered);
1682+
remapAndConvertMixed(measures.jointVelocities,
1683+
measures.jointVelocitiesUnordered);
1684+
if (streamJointAccelerations)
1685+
{
1686+
remapAndConvertMixed(measures.jointAccelerations,
1687+
measures.jointAccelerationsUnordered);
1688+
}
16131689
}
16141690
} else
16151691
{

src/RobotInterface/include/BipedalLocomotion/RobotInterface/ISensorBridge.h

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ namespace BipedalLocomotion
2424
namespace RobotInterface
2525
{
2626

27+
/**
28+
* Enum class specifying the type of joint
29+
*/
30+
enum class JointType
31+
{
32+
REVOLUTE, /**< Revolute joint */
33+
PRISMATIC /**< Prismatic joint */
34+
};
35+
2736
/**
2837
* Sensor bridge options
2938
*/
@@ -59,6 +68,7 @@ struct SensorBridgeOptions
5968
struct SensorLists
6069
{
6170
std::vector<std::string> jointsList; /**< list of joints attached to the bridge */
71+
std::vector<JointType> jointsTypeList; /**< list of joint types */
6272
std::vector<std::string> IMUsList; /**< list of IMUs attached to the bridge */
6373
std::vector<std::string> linearAccelerometersList; /**< list of linear accelerometers attached
6474
to the bridge */

0 commit comments

Comments
 (0)