Skip to content

Commit a0ab64d

Browse files
[Transmissions] Add absolute_position and torque interfaces (#2310)
1 parent 2c691e0 commit a0ab64d

4 files changed

Lines changed: 247 additions & 22 deletions

File tree

transmission_interface/include/transmission_interface/differential_transmission.hpp

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ namespace transmission_interface
108108
*
109109
* \ingroup transmission_types
110110
*/
111+
112+
constexpr auto HW_IF_ABSOLUTE_POSITION = "absolute_position";
113+
111114
class DifferentialTransmission : public Transmission
112115
{
113116
public:
@@ -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

173180
inline 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

308353
inline 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

352409
std::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

transmission_interface/include/transmission_interface/simple_transmission.hpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ namespace transmission_interface
8080
*
8181
* \ingroup transmission_types
8282
*/
83+
84+
constexpr auto HW_IF_ABSOLUTE_POSITION = "absolute_position";
85+
8386
class SimpleTransmission : public Transmission
8487
{
8588
public:
@@ -131,10 +134,14 @@ class SimpleTransmission : public Transmission
131134
JointHandle joint_position_ = {"", "", nullptr};
132135
JointHandle joint_velocity_ = {"", "", nullptr};
133136
JointHandle joint_effort_ = {"", "", nullptr};
137+
JointHandle joint_torque_ = {"", "", nullptr};
138+
JointHandle joint_absolute_position_ = {"", "", nullptr};
134139

135140
ActuatorHandle actuator_position_ = {"", "", nullptr};
136141
ActuatorHandle actuator_velocity_ = {"", "", nullptr};
137142
ActuatorHandle actuator_effort_ = {"", "", nullptr};
143+
ActuatorHandle actuator_torque_ = {"", "", nullptr};
144+
ActuatorHandle actuator_absolute_position_ = {"", "", nullptr};
138145
};
139146

140147
inline SimpleTransmission::SimpleTransmission(
@@ -198,17 +205,25 @@ inline void SimpleTransmission::configure(
198205
joint_position_ = get_by_interface(joint_handles, hardware_interface::HW_IF_POSITION);
199206
joint_velocity_ = get_by_interface(joint_handles, hardware_interface::HW_IF_VELOCITY);
200207
joint_effort_ = get_by_interface(joint_handles, hardware_interface::HW_IF_EFFORT);
208+
joint_torque_ = get_by_interface(joint_handles, hardware_interface::HW_IF_TORQUE);
209+
joint_absolute_position_ = get_by_interface(joint_handles, HW_IF_ABSOLUTE_POSITION);
201210

202-
if (!joint_position_ && !joint_velocity_ && !joint_effort_)
211+
if (
212+
!joint_position_ && !joint_velocity_ && !joint_effort_ && !joint_torque_ &&
213+
!joint_absolute_position_)
203214
{
204215
throw Exception("None of the provided joint handles are valid or from the required interfaces");
205216
}
206217

207218
actuator_position_ = get_by_interface(actuator_handles, hardware_interface::HW_IF_POSITION);
208219
actuator_velocity_ = get_by_interface(actuator_handles, hardware_interface::HW_IF_VELOCITY);
209220
actuator_effort_ = get_by_interface(actuator_handles, hardware_interface::HW_IF_EFFORT);
221+
actuator_torque_ = get_by_interface(actuator_handles, hardware_interface::HW_IF_TORQUE);
222+
actuator_absolute_position_ = get_by_interface(actuator_handles, HW_IF_ABSOLUTE_POSITION);
210223

211-
if (!actuator_position_ && !actuator_velocity_ && !actuator_effort_)
224+
if (
225+
!actuator_position_ && !actuator_velocity_ && !actuator_effort_ && !actuator_torque_ &&
226+
!actuator_absolute_position_)
212227
{
213228
throw Exception("None of the provided joint handles are valid or from the required interfaces");
214229
}
@@ -230,6 +245,17 @@ inline void SimpleTransmission::actuator_to_joint()
230245
{
231246
joint_position_.set_value(actuator_position_.get_value() / reduction_ + jnt_offset_);
232247
}
248+
249+
if (joint_torque_ && actuator_torque_)
250+
{
251+
joint_torque_.set_value(actuator_torque_.get_value() * reduction_);
252+
}
253+
254+
if (joint_absolute_position_ && actuator_absolute_position_)
255+
{
256+
joint_absolute_position_.set_value(
257+
actuator_absolute_position_.get_value() / reduction_ + jnt_offset_);
258+
}
233259
}
234260

235261
inline void SimpleTransmission::joint_to_actuator()
@@ -248,6 +274,11 @@ inline void SimpleTransmission::joint_to_actuator()
248274
{
249275
actuator_position_.set_value((joint_position_.get_value() - jnt_offset_) * reduction_);
250276
}
277+
278+
if (joint_torque_ && actuator_torque_)
279+
{
280+
actuator_torque_.set_value(joint_torque_.get_value() / reduction_);
281+
}
251282
}
252283

253284
} // namespace transmission_interface

0 commit comments

Comments
 (0)