Skip to content

Commit d8dcfd8

Browse files
urfeexmergify[bot]
authored andcommitted
Fix passthrough controller to not read non-existing state_interfaces (#1314)
* passthrough_trajectory: Add a test with a full quintic trajectory * Check for state interfaces being present before attempting to read from it (cherry picked from commit 65679b2) # Conflicts: # ur_controllers/src/passthrough_trajectory_controller.cpp
1 parent 204e215 commit d8dcfd8

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

ur_controllers/src/passthrough_trajectory_controller.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,17 +579,35 @@ bool PassthroughTrajectoryController::check_goal_tolerance()
579579
return false;
580580
}
581581

582+
<<<<<<< HEAD
582583
if (!active_joint_traj_.points.back().velocities.empty()) {
583584
const double joint_vel = joint_velocity_state_interface_[i].get().get_value();
585+
=======
586+
if (!active_joint_traj_.points.back().velocities.empty() && !joint_velocity_state_interface_.empty()) {
587+
const auto joint_vel = joint_velocity_state_interface_[i].get().get_optional();
588+
if (!joint_vel.has_value()) {
589+
return false;
590+
}
591+
>>>>>>> 65679b2 (Fix passthrough controller to not read non-existing state_interfaces (#1314))
584592
const auto& expected_vel = active_joint_traj_.points.back().velocities[joint_mapping->at(joint_name)];
585593
if (std::abs(joint_vel - expected_vel) > joint_tol.velocity) {
586594
return false;
587595
}
588596
}
597+
<<<<<<< HEAD
589598
if (!active_joint_traj_.points.back().accelerations.empty()) {
590599
const double joint_vel = joint_acceleration_state_interface_[i].get().get_value();
591600
const auto& expected_vel = active_joint_traj_.points.back().accelerations[joint_mapping->at(joint_name)];
592601
if (std::abs(joint_vel - expected_vel) > joint_tol.acceleration) {
602+
=======
603+
if (!active_joint_traj_.points.back().accelerations.empty() && !joint_acceleration_state_interface_.empty()) {
604+
const auto joint_acc = joint_acceleration_state_interface_[i].get().get_optional();
605+
if (!joint_acc.has_value()) {
606+
return false;
607+
}
608+
const auto& expected_acc = active_joint_traj_.points.back().accelerations[joint_mapping->at(joint_name)];
609+
if (std::abs(joint_acc.value() - expected_acc) > joint_tol.acceleration) {
610+
>>>>>>> 65679b2 (Fix passthrough controller to not read non-existing state_interfaces (#1314))
593611
return false;
594612
}
595613
}

ur_robot_driver/test/robot_driver.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def test_passthrough_trajectory(self, tf_prefix):
360360
)
361361
waypts = [
362362
[-1.58, -1.692, -1.4311, -0.0174, 1.5882, 0.0349],
363-
[-3, -1.692, -1.4311, -0.0174, 1.5882, 0.0349],
363+
[-2.5, -1.692, -1.4311, -0.0174, 1.5882, 0.0349],
364364
[-1.58, -1.692, -1.4311, -0.0174, 1.5882, 0.0349],
365365
]
366366
time_vec = [
@@ -392,7 +392,42 @@ def test_passthrough_trajectory(self, tf_prefix):
392392
goal_handle, TIMEOUT_EXECUTE_TRAJECTORY
393393
)
394394
self.assertEqual(result.error_code, FollowJointTrajectory.Result.SUCCESSFUL)
395+
396+
# Full quintic trajectory
397+
test_trajectory = zip(time_vec, waypts)
398+
trajectory = JointTrajectory(
399+
points=[
400+
JointTrajectoryPoint(
401+
positions=pos,
402+
time_from_start=times,
403+
velocities=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
404+
accelerations=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
405+
)
406+
for (times, pos) in test_trajectory
407+
],
408+
joint_names=[tf_prefix + ROBOT_JOINTS[i] for i in range(len(ROBOT_JOINTS))],
409+
)
410+
goal_handle = self._passthrough_forward_joint_trajectory.send_goal(
411+
trajectory=trajectory,
412+
goal_time_tolerance=goal_time_tolerance,
413+
goal_tolerance=goal_tolerance,
414+
)
415+
self.assertTrue(goal_handle.accepted)
416+
if goal_handle.accepted:
417+
result = self._passthrough_forward_joint_trajectory.get_result(
418+
goal_handle, TIMEOUT_EXECUTE_TRAJECTORY
419+
)
420+
self.assertEqual(result.error_code, FollowJointTrajectory.Result.SUCCESSFUL)
421+
395422
# Test impossible goal tolerance, should fail.
423+
test_trajectory = zip(time_vec, waypts)
424+
trajectory = JointTrajectory(
425+
points=[
426+
JointTrajectoryPoint(positions=pos, time_from_start=times)
427+
for (times, pos) in test_trajectory
428+
],
429+
joint_names=[tf_prefix + ROBOT_JOINTS[i] for i in range(len(ROBOT_JOINTS))],
430+
)
396431
goal_tolerance = [
397432
JointTolerance(position=0.000000001, name=tf_prefix + ROBOT_JOINTS[i])
398433
for i in range(len(ROBOT_JOINTS))

0 commit comments

Comments
 (0)