@@ -187,6 +187,8 @@ struct YarpSensorBridge::Impl
187
187
*/
188
188
bool streamJointAccelerations{true }; /* *< flag to enable reading joint accelerations from
189
189
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 */
190
192
191
193
using SubConfigLoader = bool (YarpSensorBridge::Impl::*)(
192
194
std::weak_ptr<const BipedalLocomotion::ParametersHandler::IParametersHandler>,
@@ -1167,14 +1169,29 @@ struct YarpSensorBridge::Impl
1167
1169
1168
1170
// get the names of all the joints available in the attached remote control board remapper
1169
1171
std::vector<std::string> controlBoardJoints;
1172
+ std::vector<JointType> controlBoardJointTypes;
1170
1173
int controlBoardDOFs;
1171
1174
controlBoardRemapperInterfaces.encoders ->getAxes (&controlBoardDOFs);
1172
1175
1173
1176
std::string joint;
1177
+ yarp::dev::JointTypeEnum jType;
1174
1178
for (int DOF = 0 ; DOF < controlBoardDOFs; DOF++)
1175
1179
{
1176
1180
controlBoardRemapperInterfaces.axis ->getAxisName (DOF, joint);
1181
+ controlBoardRemapperInterfaces.axis ->getJointType (DOF, jType);
1177
1182
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);
1178
1195
}
1179
1196
1180
1197
// 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
1186
1203
metaData.bridgeOptions .nrJoints = metaData.sensorsList .jointsList .size ();
1187
1204
}
1188
1205
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
+
1189
1217
// reset the control board buffers
1190
1218
this ->resetControlBoardBuffers ();
1191
1219
@@ -1595,21 +1623,69 @@ struct YarpSensorBridge::Impl
1595
1623
}
1596
1624
}
1597
1625
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 ;
1603
1629
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
+ };
1607
1641
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 )
1609
1657
{
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
+ }
1613
1689
}
1614
1690
} else
1615
1691
{
0 commit comments