2222
2323using hardware_interface::HW_IF_EFFORT ;
2424using hardware_interface::HW_IF_POSITION ;
25+ using hardware_interface::HW_IF_TORQUE ;
2526using hardware_interface::HW_IF_VELOCITY ;
2627using testing::DoubleNear;
2728using transmission_interface::ActuatorHandle;
2829using transmission_interface::DifferentialTransmission;
2930using transmission_interface::Exception;
31+ using transmission_interface::HW_IF_ABSOLUTE_POSITION ;
3032using transmission_interface::JointHandle;
3133// Floating-point value comparison threshold
3234const double EPS = 1e-5 ;
@@ -125,6 +127,8 @@ TEST(ConfigureTest, FailsWithBadHandles)
125127 testConfigureWithBadHandles (HW_IF_POSITION );
126128 testConfigureWithBadHandles (HW_IF_VELOCITY );
127129 testConfigureWithBadHandles (HW_IF_EFFORT );
130+ testConfigureWithBadHandles (HW_IF_TORQUE );
131+ testConfigureWithBadHandles (HW_IF_ABSOLUTE_POSITION );
128132}
129133
130134class TransmissionSetup : public ::testing::Test
@@ -220,6 +224,7 @@ TEST_F(BlackBoxTest, IdentityMap)
220224 testIdentityMap (transmission, input_value, HW_IF_POSITION );
221225 testIdentityMap (transmission, input_value, HW_IF_VELOCITY );
222226 testIdentityMap (transmission, input_value, HW_IF_EFFORT );
227+ testIdentityMap (transmission, input_value, HW_IF_TORQUE );
223228 }
224229 }
225230}
@@ -236,7 +241,7 @@ TEST_F(WhiteBoxTest, DontMoveJoints)
236241
237242 DifferentialTransmission trans (actuator_reduction, joint_reduction, joint_offset);
238243
239- // Actuator input (used for effort, velocity and position)
244+ // Actuator input (used for effort, velocity, position, torque and absolute position)
240245 *a_vec[0 ] = 0.0 ;
241246 *a_vec[1 ] = 0.0 ;
242247
@@ -275,6 +280,30 @@ TEST_F(WhiteBoxTest, DontMoveJoints)
275280 EXPECT_THAT (joint_offset[0 ], DoubleNear (j_val[0 ], EPS ));
276281 EXPECT_THAT (joint_offset[1 ], DoubleNear (j_val[1 ], EPS ));
277282 }
283+
284+ // Torque interface
285+ {
286+ auto a1_handle = ActuatorHandle (" act1" , HW_IF_TORQUE , a_vec[0 ]);
287+ auto a2_handle = ActuatorHandle (" act2" , HW_IF_TORQUE , a_vec[1 ]);
288+ auto joint1_handle = JointHandle (" joint1" , HW_IF_TORQUE , j_vec[0 ]);
289+ auto joint2_handle = JointHandle (" joint2" , HW_IF_TORQUE , j_vec[1 ]);
290+ trans.configure ({joint1_handle, joint2_handle}, {a1_handle, a2_handle});
291+ trans.actuator_to_joint ();
292+ EXPECT_THAT (0.0 , DoubleNear (j_val[0 ], EPS ));
293+ EXPECT_THAT (0.0 , DoubleNear (j_val[1 ], EPS ));
294+ }
295+
296+ // Absolute position interface
297+ {
298+ auto a1_handle = ActuatorHandle (" act1" , HW_IF_ABSOLUTE_POSITION , a_vec[0 ]);
299+ auto a2_handle = ActuatorHandle (" act2" , HW_IF_ABSOLUTE_POSITION , a_vec[1 ]);
300+ auto joint1_handle = JointHandle (" joint1" , HW_IF_ABSOLUTE_POSITION , j_vec[0 ]);
301+ auto joint2_handle = JointHandle (" joint2" , HW_IF_ABSOLUTE_POSITION , j_vec[1 ]);
302+ trans.configure ({joint1_handle, joint2_handle}, {a1_handle, a2_handle});
303+ trans.actuator_to_joint ();
304+ EXPECT_THAT (joint_offset[0 ], DoubleNear (j_val[0 ], EPS ));
305+ EXPECT_THAT (joint_offset[1 ], DoubleNear (j_val[1 ], EPS ));
306+ }
278307}
279308
280309TEST_F (WhiteBoxTest, MoveFirstJointOnly)
@@ -284,7 +313,7 @@ TEST_F(WhiteBoxTest, MoveFirstJointOnly)
284313
285314 DifferentialTransmission trans (actuator_reduction, joint_reduction);
286315
287- // Actuator input (used for effort, velocity and position)
316+ // Actuator input (used for effort, velocity, position, torque and absolute position)
288317 *a_vec[0 ] = 10.0 ;
289318 *a_vec[1 ] = 10.0 ;
290319
@@ -323,6 +352,30 @@ TEST_F(WhiteBoxTest, MoveFirstJointOnly)
323352 EXPECT_THAT (0.5 , DoubleNear (j_val[0 ], EPS ));
324353 EXPECT_THAT (0.0 , DoubleNear (j_val[1 ], EPS ));
325354 }
355+
356+ // Torque interface
357+ {
358+ auto a1_handle = ActuatorHandle (" act1" , HW_IF_TORQUE , a_vec[0 ]);
359+ auto a2_handle = ActuatorHandle (" act2" , HW_IF_TORQUE , a_vec[1 ]);
360+ auto joint1_handle = JointHandle (" joint1" , HW_IF_TORQUE , j_vec[0 ]);
361+ auto joint2_handle = JointHandle (" joint2" , HW_IF_TORQUE , j_vec[1 ]);
362+ trans.configure ({joint1_handle, joint2_handle}, {a1_handle, a2_handle});
363+ trans.actuator_to_joint ();
364+ EXPECT_THAT (400.0 , DoubleNear (j_val[0 ], EPS ));
365+ EXPECT_THAT (0.0 , DoubleNear (j_val[1 ], EPS ));
366+ }
367+
368+ // Absolute position interface
369+ {
370+ auto a1_handle = ActuatorHandle (" act1" , HW_IF_ABSOLUTE_POSITION , a_vec[0 ]);
371+ auto a2_handle = ActuatorHandle (" act2" , HW_IF_ABSOLUTE_POSITION , a_vec[1 ]);
372+ auto joint1_handle = JointHandle (" joint1" , HW_IF_ABSOLUTE_POSITION , j_vec[0 ]);
373+ auto joint2_handle = JointHandle (" joint2" , HW_IF_ABSOLUTE_POSITION , j_vec[1 ]);
374+ trans.configure ({joint1_handle, joint2_handle}, {a1_handle, a2_handle});
375+ trans.actuator_to_joint ();
376+ EXPECT_THAT (0.5 , DoubleNear (j_val[0 ], EPS ));
377+ EXPECT_THAT (0.0 , DoubleNear (j_val[1 ], EPS ));
378+ }
326379}
327380
328381TEST_F (WhiteBoxTest, MoveSecondJointOnly)
@@ -332,7 +385,7 @@ TEST_F(WhiteBoxTest, MoveSecondJointOnly)
332385
333386 DifferentialTransmission trans (actuator_reduction, joint_reduction);
334387
335- // Actuator input (used for effort, velocity and position)
388+ // Actuator input (used for effort, velocity, position, torque and absolute position)
336389 *a_vec[0 ] = 10.0 ;
337390 *a_vec[1 ] = -10.0 ;
338391
@@ -371,6 +424,30 @@ TEST_F(WhiteBoxTest, MoveSecondJointOnly)
371424 EXPECT_THAT (0.0 , DoubleNear (j_val[0 ], EPS ));
372425 EXPECT_THAT (0.5 , DoubleNear (j_val[1 ], EPS ));
373426 }
427+
428+ // Torque interface
429+ {
430+ auto a1_handle = ActuatorHandle (" act1" , HW_IF_TORQUE , a_vec[0 ]);
431+ auto a2_handle = ActuatorHandle (" act2" , HW_IF_TORQUE , a_vec[1 ]);
432+ auto joint1_handle = JointHandle (" joint1" , HW_IF_TORQUE , j_vec[0 ]);
433+ auto joint2_handle = JointHandle (" joint2" , HW_IF_TORQUE , j_vec[1 ]);
434+ trans.configure ({joint1_handle, joint2_handle}, {a1_handle, a2_handle});
435+ trans.actuator_to_joint ();
436+ EXPECT_THAT (0.0 , DoubleNear (j_val[0 ], EPS ));
437+ EXPECT_THAT (400.0 , DoubleNear (j_val[1 ], EPS ));
438+ }
439+
440+ // Absolute position interface
441+ {
442+ auto a1_handle = ActuatorHandle (" act1" , HW_IF_ABSOLUTE_POSITION , a_vec[0 ]);
443+ auto a2_handle = ActuatorHandle (" act2" , HW_IF_ABSOLUTE_POSITION , a_vec[1 ]);
444+ auto joint1_handle = JointHandle (" joint1" , HW_IF_ABSOLUTE_POSITION , j_vec[0 ]);
445+ auto joint2_handle = JointHandle (" joint2" , HW_IF_ABSOLUTE_POSITION , j_vec[1 ]);
446+ trans.configure ({joint1_handle, joint2_handle}, {a1_handle, a2_handle});
447+ trans.actuator_to_joint ();
448+ EXPECT_THAT (0.0 , DoubleNear (j_val[0 ], EPS ));
449+ EXPECT_THAT (0.5 , DoubleNear (j_val[1 ], EPS ));
450+ }
374451}
375452
376453TEST_F (WhiteBoxTest, MoveBothJoints)
@@ -424,4 +501,28 @@ TEST_F(WhiteBoxTest, MoveBothJoints)
424501 EXPECT_THAT (-2.01250 , DoubleNear (j_val[0 ], EPS ));
425502 EXPECT_THAT (4.06875 , DoubleNear (j_val[1 ], EPS ));
426503 }
504+
505+ // Torque interface
506+ {
507+ auto a1_handle = ActuatorHandle (" act1" , HW_IF_TORQUE , a_vec[0 ]);
508+ auto a2_handle = ActuatorHandle (" act2" , HW_IF_TORQUE , a_vec[1 ]);
509+ auto joint1_handle = JointHandle (" joint1" , HW_IF_TORQUE , j_vec[0 ]);
510+ auto joint2_handle = JointHandle (" joint2" , HW_IF_TORQUE , j_vec[1 ]);
511+ trans.configure ({joint1_handle, joint2_handle}, {a1_handle, a2_handle});
512+ trans.actuator_to_joint ();
513+ EXPECT_THAT (140.0 , DoubleNear (j_val[0 ], EPS ));
514+ EXPECT_THAT (520.0 , DoubleNear (j_val[1 ], EPS ));
515+ }
516+
517+ // Absolute position interface
518+ {
519+ auto a1_handle = ActuatorHandle (" act1" , HW_IF_ABSOLUTE_POSITION , a_vec[0 ]);
520+ auto a2_handle = ActuatorHandle (" act2" , HW_IF_ABSOLUTE_POSITION , a_vec[1 ]);
521+ auto joint1_handle = JointHandle (" joint1" , HW_IF_ABSOLUTE_POSITION , j_vec[0 ]);
522+ auto joint2_handle = JointHandle (" joint2" , HW_IF_ABSOLUTE_POSITION , j_vec[1 ]);
523+ trans.configure ({joint1_handle, joint2_handle}, {a1_handle, a2_handle});
524+ trans.actuator_to_joint ();
525+ EXPECT_THAT (-2.01250 , DoubleNear (j_val[0 ], EPS ));
526+ EXPECT_THAT (4.06875 , DoubleNear (j_val[1 ], EPS ));
527+ }
427528}
0 commit comments