Function angles::shortest_angular_distance_with_large_limits

Function Documentation

static inline bool angles::shortest_angular_distance_with_large_limits(double from, double to, double left_limit, double right_limit, double &shortest_angle)

Returns the delta from from_angle to to_angle, making sure it does not violate limits specified by left_limit and right_limit. This function is similar to shortest_angular_distance_with_limits(), with the main difference that it accepts limits outside the [-M_PI, M_PI] range. Even if this is quite uncommon, one could indeed consider revolute joints with large rotation limits, e.g., in the range [-2*M_PI, 2*M_PI].

\function

In this case, a strict requirement is to have left_limit smaller than right_limit. Note also that from must lie inside the valid range, while to does not need to. In fact, this function will evaluate the shortest (valid) angle shortest_angle so that from+shortest_angle equals to up to an integer multiple of 2*M_PI. As an example, a call to shortest_angular_distance_with_large_limits(0, 10.5*M_PI, -2*M_PI, 2*M_PI, shortest_angle) will return true, with shortest_angle=0.5*M_PI. This is because from and from+shortest_angle are both inside the limits, and fmod(to+shortest_angle, 2*M_PI) equals fmod(to, 2*M_PI). On the other hand, shortest_angular_distance_with_large_limits(10.5*M_PI, 0, -2*M_PI, 2*M_PI, shortest_angle) will return false, since from is not in the valid range. Finally, note that the call shortest_angular_distance_with_large_limits(0, 10.5*M_PI, -2*M_PI, 0.1*M_PI, shortest_angle) will also return true. However, shortest_angle in this case will be -1.5*M_PI.

Parameters:
  • from – - “from” angle.

  • to – - “to” angle.

  • left_limit – - left limit of valid interval, must be smaller than right_limit.

  • right_limit – - right limit of valid interval, must be greater than left_limit.

  • shortest_angle – - result of the shortest angle calculation.

Returns:

true if left_limit < right_limit and if “from” and “from+shortest_angle” positions are within the valid interval, false otherwise.