@@ -108,6 +108,9 @@ namespace transmission_interface
108108 *
109109 * \ingroup transmission_types
110110 */
111+
112+ constexpr auto HW_IF_ABSOLUTE_POSITION = " absolute_position" ;
113+
111114class DifferentialTransmission : public Transmission
112115{
113116public:
@@ -164,10 +167,14 @@ class DifferentialTransmission : public Transmission
164167 std::vector<JointHandle> joint_position_;
165168 std::vector<JointHandle> joint_velocity_;
166169 std::vector<JointHandle> joint_effort_;
170+ std::vector<JointHandle> joint_torque_;
171+ std::vector<JointHandle> joint_absolute_position_;
167172
168173 std::vector<ActuatorHandle> actuator_position_;
169174 std::vector<ActuatorHandle> actuator_velocity_;
170175 std::vector<ActuatorHandle> actuator_effort_;
176+ std::vector<ActuatorHandle> actuator_torque_;
177+ std::vector<ActuatorHandle> actuator_absolute_position_;
171178};
172179
173180inline DifferentialTransmission::DifferentialTransmission (
@@ -228,8 +235,13 @@ void DifferentialTransmission::configure(
228235 joint_velocity_ =
229236 get_ordered_handles (joint_handles, joint_names, hardware_interface::HW_IF_VELOCITY );
230237 joint_effort_ = get_ordered_handles (joint_handles, joint_names, hardware_interface::HW_IF_EFFORT );
238+ joint_torque_ = get_ordered_handles (joint_handles, joint_names, hardware_interface::HW_IF_TORQUE );
239+ joint_absolute_position_ =
240+ get_ordered_handles (joint_handles, joint_names, HW_IF_ABSOLUTE_POSITION );
231241
232- if (joint_position_.size () != 2 && joint_velocity_.size () != 2 && joint_effort_.size () != 2 )
242+ if (
243+ joint_position_.size () != 2 && joint_velocity_.size () != 2 && joint_effort_.size () != 2 &&
244+ joint_torque_.size () != 2 && joint_absolute_position_.size () != 2 )
233245 {
234246 throw Exception (" Not enough valid or required joint handles were presented." );
235247 }
@@ -240,10 +252,15 @@ void DifferentialTransmission::configure(
240252 get_ordered_handles (actuator_handles, actuator_names, hardware_interface::HW_IF_VELOCITY );
241253 actuator_effort_ =
242254 get_ordered_handles (actuator_handles, actuator_names, hardware_interface::HW_IF_EFFORT );
255+ actuator_torque_ =
256+ get_ordered_handles (actuator_handles, actuator_names, hardware_interface::HW_IF_TORQUE );
257+ actuator_absolute_position_ =
258+ get_ordered_handles (actuator_handles, actuator_names, HW_IF_ABSOLUTE_POSITION );
243259
244260 if (
245261 actuator_position_.size () != 2 && actuator_velocity_.size () != 2 &&
246- actuator_effort_.size () != 2 )
262+ actuator_effort_.size () != 2 && actuator_torque_.size () != 2 &&
263+ actuator_absolute_position_.size () != 2 )
247264 {
248265 throw Exception (
249266 fmt::format (
@@ -254,7 +271,9 @@ void DifferentialTransmission::configure(
254271 if (
255272 joint_position_.size () != actuator_position_.size () &&
256273 joint_velocity_.size () != actuator_velocity_.size () &&
257- joint_effort_.size () != actuator_effort_.size ())
274+ joint_effort_.size () != actuator_effort_.size () &&
275+ joint_torque_.size () != actuator_torque_.size () &&
276+ joint_absolute_position_.size () != actuator_absolute_position_.size ())
258277 {
259278 throw Exception (
260279 fmt::format (FMT_COMPILE (" Pair-wise mismatch on interfaces. \n {}" ), get_handles_info ()));
@@ -303,6 +322,32 @@ inline void DifferentialTransmission::actuator_to_joint()
303322 joint_eff[1 ].set_value (
304323 jr[1 ] * (act_eff[0 ].get_value () * ar[0 ] - act_eff[1 ].get_value () * ar[1 ]));
305324 }
325+
326+ auto & act_tor = actuator_torque_;
327+ auto & joint_tor = joint_torque_;
328+ if (act_tor.size () == num_actuators () && joint_tor.size () == num_joints ())
329+ {
330+ assert (act_tor[0 ] && act_tor[1 ] && joint_tor[0 ] && joint_tor[1 ]);
331+
332+ joint_tor[0 ].set_value (
333+ jr[0 ] * (act_tor[0 ].get_value () * ar[0 ] + act_tor[1 ].get_value () * ar[1 ]));
334+ joint_tor[1 ].set_value (
335+ jr[1 ] * (act_tor[0 ].get_value () * ar[0 ] - act_tor[1 ].get_value () * ar[1 ]));
336+ }
337+
338+ auto & act_abs_pos = actuator_absolute_position_;
339+ auto & joint_abs_pos = joint_absolute_position_;
340+ if (act_abs_pos.size () == num_actuators () && joint_abs_pos.size () == num_joints ())
341+ {
342+ assert (act_abs_pos[0 ] && act_abs_pos[1 ] && joint_abs_pos[0 ] && joint_abs_pos[1 ]);
343+
344+ joint_abs_pos[0 ].set_value (
345+ (act_abs_pos[0 ].get_value () / ar[0 ] + act_abs_pos[1 ].get_value () / ar[1 ]) / (2.0 * jr[0 ]) +
346+ joint_offset_[0 ]);
347+ joint_abs_pos[1 ].set_value (
348+ (act_abs_pos[0 ].get_value () / ar[0 ] - act_abs_pos[1 ].get_value () / ar[1 ]) / (2.0 * jr[1 ]) +
349+ joint_offset_[1 ]);
350+ }
306351}
307352
308353inline void DifferentialTransmission::joint_to_actuator ()
@@ -347,6 +392,18 @@ inline void DifferentialTransmission::joint_to_actuator()
347392 act_eff[1 ].set_value (
348393 (joint_eff[0 ].get_value () / jr[0 ] - joint_eff[1 ].get_value () / jr[1 ]) / (2.0 * ar[1 ]));
349394 }
395+
396+ auto & act_tor = actuator_torque_;
397+ auto & joint_tor = joint_torque_;
398+ if (act_tor.size () == num_actuators () && joint_tor.size () == num_joints ())
399+ {
400+ assert (act_tor[0 ] && act_tor[1 ] && joint_tor[0 ] && joint_tor[1 ]);
401+
402+ act_tor[0 ].set_value (
403+ (joint_tor[0 ].get_value () / jr[0 ] + joint_tor[1 ].get_value () / jr[1 ]) / (2.0 * ar[0 ]));
404+ act_tor[1 ].set_value (
405+ (joint_tor[0 ].get_value () / jr[0 ] - joint_tor[1 ].get_value () / jr[1 ]) / (2.0 * ar[1 ]));
406+ }
350407}
351408
352409std::string DifferentialTransmission::get_handles_info () const
@@ -356,10 +413,15 @@ std::string DifferentialTransmission::get_handles_info() const
356413 " Got the following handles:\n "
357414 " Joint position: {}, Actuator position: {}\n "
358415 " Joint velocity: {}, Actuator velocity: {}\n "
359- " Joint effort: {}, Actuator effort: {}" ),
416+ " Joint effort: {}, Actuator effort: {}\n "
417+ " Joint torque: {}, Actuator torque: {}\n "
418+ " Joint absolute position: {}, Actuator absolute position: {}" ),
360419 to_string (get_names (joint_position_)), to_string (get_names (actuator_position_)),
361420 to_string (get_names (joint_velocity_)), to_string (get_names (actuator_velocity_)),
362- to_string (get_names (joint_effort_)), to_string (get_names (actuator_effort_)));
421+ to_string (get_names (joint_effort_)), to_string (get_names (actuator_effort_)),
422+ to_string (get_names (joint_torque_)), to_string (get_names (actuator_torque_)),
423+ to_string (get_names (joint_absolute_position_)),
424+ to_string (get_names (actuator_absolute_position_)));
363425}
364426
365427} // namespace transmission_interface
0 commit comments