Skip to content

Commit 10c86da

Browse files
Add torque and absolute position to simple transmission
1 parent 52b0d2e commit 10c86da

2 files changed

Lines changed: 76 additions & 14 deletions

File tree

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

transmission_interface/test/simple_transmission_test.cpp

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020

2121
using hardware_interface::HW_IF_EFFORT;
2222
using hardware_interface::HW_IF_POSITION;
23+
using hardware_interface::HW_IF_TORQUE;
2324
using hardware_interface::HW_IF_VELOCITY;
2425
using transmission_interface::ActuatorHandle;
2526
using transmission_interface::Exception;
27+
using transmission_interface::HW_IF_ABSOLUTE_POSITION;
2628
using transmission_interface::JointHandle;
2729
using transmission_interface::SimpleTransmission;
2830

@@ -118,18 +120,15 @@ class BlackBoxTest : public TransmissionSetup, public ::testing::TestWithParam<S
118120
void testIdentityMap(
119121
SimpleTransmission & trans, const std::string & interface_name, const double ref_val)
120122
{
121-
// Effort interface
122-
{
123-
auto actuator_handle = ActuatorHandle("act1", interface_name, &a_val);
124-
auto joint_handle = JointHandle("joint1", interface_name, &j_val);
125-
trans.configure({joint_handle}, {actuator_handle});
126-
127-
a_val = ref_val;
128-
129-
trans.actuator_to_joint();
130-
trans.joint_to_actuator();
131-
EXPECT_THAT(ref_val, DoubleNear(a_val, EPS));
132-
}
123+
auto actuator_handle = ActuatorHandle("act1", interface_name, &a_val);
124+
auto joint_handle = JointHandle("joint1", interface_name, &j_val);
125+
trans.configure({joint_handle}, {actuator_handle});
126+
127+
a_val = ref_val;
128+
129+
trans.actuator_to_joint();
130+
trans.joint_to_actuator();
131+
EXPECT_THAT(ref_val, DoubleNear(a_val, EPS));
133132
}
134133
};
135134

@@ -158,6 +157,18 @@ TEST_P(BlackBoxTest, IdentityMap)
158157
testIdentityMap(trans, HW_IF_EFFORT, 0.0);
159158
reset_values();
160159
testIdentityMap(trans, HW_IF_EFFORT, -1.0);
160+
161+
testIdentityMap(trans, HW_IF_TORQUE, 1.0);
162+
reset_values();
163+
testIdentityMap(trans, HW_IF_TORQUE, 0.0);
164+
reset_values();
165+
testIdentityMap(trans, HW_IF_TORQUE, -1.0);
166+
167+
testIdentityMap(trans, HW_IF_ABSOLUTE_POSITION, 1.0);
168+
reset_values();
169+
testIdentityMap(trans, HW_IF_ABSOLUTE_POSITION, 0.0);
170+
reset_values();
171+
testIdentityMap(trans, HW_IF_ABSOLUTE_POSITION, -1.0);
161172
}
162173

163174
INSTANTIATE_TEST_SUITE_P(
@@ -211,6 +222,26 @@ TEST_F(WhiteBoxTest, MoveJoint)
211222
EXPECT_THAT(1.1, DoubleNear(j_val, EPS));
212223
}
213224

225+
// Torque interface
226+
{
227+
auto actuator_handle = ActuatorHandle("act1", HW_IF_TORQUE, &a_val);
228+
auto joint_handle = JointHandle("joint1", HW_IF_TORQUE, &j_val);
229+
trans.configure({joint_handle}, {actuator_handle});
230+
231+
trans.actuator_to_joint();
232+
EXPECT_THAT(10.0, DoubleNear(j_val, EPS));
233+
}
234+
235+
// Absolute position interface
236+
{
237+
auto actuator_handle = ActuatorHandle("act1", HW_IF_ABSOLUTE_POSITION, &a_val);
238+
auto joint_handle = JointHandle("joint1", HW_IF_ABSOLUTE_POSITION, &j_val);
239+
trans.configure({joint_handle}, {actuator_handle});
240+
241+
trans.actuator_to_joint();
242+
EXPECT_THAT(1.1, DoubleNear(j_val, EPS));
243+
}
244+
214245
// Mismatched interface is ignored
215246
{
216247
double unique_value = 13.37;

0 commit comments

Comments
 (0)