Skip to content

Commit 23337e5

Browse files
Improving differential_transmission configure checks (#2812)
1 parent fc77935 commit 23337e5

File tree

2 files changed

+69
-6
lines changed

2 files changed

+69
-6
lines changed

transmission_interface/include/transmission_interface/differential_transmission.hpp

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,42 +344,74 @@ void DifferentialTransmission::configure(
344344
get_handles_info()));
345345
}
346346

347-
if (joint_position_.size() != actuator_position_.size())
347+
if (
348+
!joint_position_.empty() && !actuator_position_.empty() &&
349+
joint_position_.size() != actuator_position_.size())
348350
{
349351
throw Exception(
350352
fmt::format(
351353
FMT_COMPILE("Pair-wise mismatch on position interfaces. \n{}"), get_handles_info()));
352354
}
353-
if (joint_velocity_.size() != actuator_velocity_.size())
355+
if (
356+
!joint_velocity_.empty() && !actuator_velocity_.empty() &&
357+
joint_velocity_.size() != actuator_velocity_.size())
354358
{
355359
throw Exception(
356360
fmt::format(
357361
FMT_COMPILE("Pair-wise mismatch on velocity interfaces. \n{}"), get_handles_info()));
358362
}
359-
if (joint_effort_.size() != actuator_effort_.size())
363+
if (
364+
!joint_effort_.empty() && !actuator_effort_.empty() &&
365+
joint_effort_.size() != actuator_effort_.size())
360366
{
361367
throw Exception(
362368
fmt::format(
363369
FMT_COMPILE("Pair-wise mismatch on effort interfaces. \n{}"), get_handles_info()));
364370
}
365-
if (joint_torque_.size() != actuator_torque_.size())
371+
if (
372+
!joint_torque_.empty() && !actuator_torque_.empty() &&
373+
joint_torque_.size() != actuator_torque_.size())
366374
{
367375
throw Exception(
368376
fmt::format(
369377
FMT_COMPILE("Pair-wise mismatch on torque interfaces. \n{}"), get_handles_info()));
370378
}
371-
if (joint_force_.size() != actuator_force_.size())
379+
if (
380+
!joint_force_.empty() && !actuator_force_.empty() &&
381+
joint_force_.size() != actuator_force_.size())
372382
{
373383
throw Exception(
374384
fmt::format(FMT_COMPILE("Pair-wise mismatch on force interfaces. \n{}"), get_handles_info()));
375385
}
376-
if (joint_absolute_position_.size() != actuator_absolute_position_.size())
386+
if (
387+
!joint_absolute_position_.empty() && !actuator_absolute_position_.empty() &&
388+
joint_absolute_position_.size() != actuator_absolute_position_.size())
377389
{
378390
throw Exception(
379391
fmt::format(
380392
FMT_COMPILE("Pair-wise mismatch on absolute position interfaces. \n{}"),
381393
get_handles_info()));
382394
}
395+
396+
// Check at least one pair-wise interface is available
397+
if (!((!joint_position_.empty() && !actuator_position_.empty() &&
398+
joint_position_.size() == actuator_position_.size()) ||
399+
(!joint_velocity_.empty() && !actuator_velocity_.empty() &&
400+
joint_velocity_.size() == actuator_velocity_.size()) ||
401+
(!joint_effort_.empty() && !actuator_effort_.empty() &&
402+
joint_effort_.size() == actuator_effort_.size()) ||
403+
(!joint_torque_.empty() && !actuator_torque_.empty() &&
404+
joint_torque_.size() == actuator_torque_.size()) ||
405+
(!joint_force_.empty() && !actuator_force_.empty() &&
406+
joint_force_.size() == actuator_force_.size()) ||
407+
(!joint_absolute_position_.empty() && !actuator_absolute_position_.empty() &&
408+
joint_absolute_position_.size() == actuator_absolute_position_.size())))
409+
{
410+
throw Exception(
411+
fmt::format(
412+
FMT_COMPILE("No pair-wise interface available between joints and actuators. \n{}"),
413+
get_handles_info()));
414+
}
383415
}
384416

385417
inline void DifferentialTransmission::actuator_to_joint()

transmission_interface/test/differential_transmission_test.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,37 @@ TEST(ConfigureTest, FailsWithBadHandles)
133133
testConfigureWithBadHandles(HW_IF_ABSOLUTE_POSITION);
134134
}
135135

136+
TEST(ConfigureTest, SuccessWithOneGoodHandle)
137+
{
138+
DifferentialTransmission trans({1.0, 1.0}, {1.0, 1.0});
139+
double dummy;
140+
141+
auto a1_p_handle = ActuatorHandle("act1", HW_IF_POSITION, &dummy);
142+
auto a2_p_handle = ActuatorHandle("act2", HW_IF_POSITION, &dummy);
143+
auto a1_f_handle = ActuatorHandle("act1", HW_IF_FORCE, &dummy);
144+
auto a2_f_handle = ActuatorHandle("act2", HW_IF_FORCE, &dummy);
145+
auto j1_p_handle = JointHandle("joint1", HW_IF_POSITION, &dummy);
146+
auto j2_p_handle = JointHandle("joint2", HW_IF_POSITION, &dummy);
147+
148+
// No exception should be thrown even though there is no force interface in the joints
149+
ASSERT_NO_THROW(trans.configure(
150+
{j1_p_handle, j2_p_handle}, {a1_p_handle, a2_p_handle, a1_f_handle, a2_f_handle}));
151+
}
152+
153+
TEST(ConfigureTest, FailWhenGoodHandles)
154+
{
155+
DifferentialTransmission trans({1.0, 1.0}, {1.0, 1.0});
156+
double dummy;
157+
158+
auto a1_f_handle = ActuatorHandle("act1", HW_IF_FORCE, &dummy);
159+
auto a2_f_handle = ActuatorHandle("act2", HW_IF_FORCE, &dummy);
160+
auto j1_p_handle = JointHandle("joint1", HW_IF_POSITION, &dummy);
161+
auto j2_p_handle = JointHandle("joint2", HW_IF_POSITION, &dummy);
162+
163+
// No pair-wise interfaces available
164+
EXPECT_THROW(trans.configure({j1_p_handle, j2_p_handle}, {a1_f_handle, a2_f_handle}), Exception);
165+
}
166+
136167
class TransmissionSetup : public ::testing::Test
137168
{
138169
protected:

0 commit comments

Comments
 (0)