Skip to content

Commit edc35b3

Browse files
committed
[effort_controllers] JointGroupPositionController: Check output of angles::shortest_angular_distance_with_large_limits
The current implementation does not check the output of angles::shortest_angular_distance_with_large_limits which indicates if the returned distance is an unspecified (and potentially wrong) case. This commit checks the return statement and adds a detailed warning. Secondly, the implementation in angles::shortest_angular_distance_with_large_limits is only valid if the `from` argument is within the range given by the upper and lower joint limit. As thus, the current_position is now enforced/clamped to the joint limits.
1 parent 745f2ab commit edc35b3

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

effort_controllers/src/joint_group_position_controller.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,26 @@ namespace effort_controllers
150150
// Compute position error
151151
if (joint_urdfs_[i]->type == urdf::Joint::REVOLUTE)
152152
{
153-
angles::shortest_angular_distance_with_large_limits(
153+
// angles::shortest_angular_distance_with_large_limits assumes implicitly (and only works correctly) if
154+
// current_position (`from`) is within the valid range. As thus, we need to enforce the joint limits
155+
// prior to passing it as an argument to angles::shortest_angular_distance_with_large_limits:
156+
enforceJointLimits(current_position, i);
157+
158+
bool is_valid = angles::shortest_angular_distance_with_large_limits(
154159
current_position,
155160
command_position,
156161
joint_urdfs_[i]->limits->lower,
157162
joint_urdfs_[i]->limits->upper,
158163
error);
164+
165+
// Warn if angles::shortest_angular_distance_with_large_limits indicates that it could not correctly
166+
// determine the error. This could potentially lead to unsafe behaviour.
167+
// Note, an epsilon margin to reduce the enforced joint limits by a small epsilon could resolve a
168+
// number of floating point issues in angles::shortest_angular_distance_with_large_limits.
169+
if (!is_valid)
170+
{
171+
ROS_WARN_STREAM("Error in angles::shortest_angular_distance_with_large_limits for joint #" << i << ", q_current=" << current_position << ", q_command=" << command_position << ", q_lb=" << joint_urdfs_[i]->limits->lower << ", q_ub=" << joint_urdfs_[i]->limits->upper << ", error=" << error << " - NOT SAFE!");
172+
}
159173
}
160174
else if (joint_urdfs_[i]->type == urdf::Joint::CONTINUOUS)
161175
{

0 commit comments

Comments
 (0)