ros2_controllers icon indicating copy to clipboard operation
ros2_controllers copied to clipboard

bug(tricycle_controller): strict inequality for M_PI_2 boundary causes speed scale to drop to ~0 instead of 0.01 limit

Open joseph-ros2-dev opened this issue 6 months ago • 5 comments

Describe the bug In TricycleController::update(), there is an attenuation mechanism that scales down the wheel speed (Ws_write) based on the steering angle error (alpha_delta) between the target wheel angle (alpha_write) and the current reading (alpha_read).

However, there is an edge case at the boundary of M_PI_2 (90 degrees) where a strict inequality check (alpha_delta > M_PI_2) prevents the controller from applying the intended 1% speed limit (0.01). Instead, it falls through to the else branch and calculates cos(alpha_delta) where alpha_delta is exactly M_PI_2. Due to floating-point precision, cos(M_PI_2) yields a value near zero (~6.12e-17), which virtually halts the wheel instead of scaling it to the intended 1% creep speed.

To Reproduce

  1. Command a spin action (set linear.x = 0.0 m/s, angular.z = 0.5 rad/s).
  2. The controller sets alpha_write to exactly M_PI_2 (~1.5707963268 rad).
  3. At the initial transition state (where current steering angle alpha_read is 0.0 rad), alpha_delta becomes exactly M_PI_2.
  4. The condition alpha_delta > M_PI_2 evaluates to false because they are equal.
  5. The execution flow falls through to the else block, calculating scale = cos(M_PI_2).
  6. The output wheel speed is scaled to near-zero (e.g., 2.47e-16 rad/s for an unattenuated target speed of 4.04 rad/s) during the first control cycle, instead of the intended 1% speed limit (0.04 rad/s).

Here is the empirical CSV printout captured from the cmd_ackermann topic at a 50Hz control rate:

# steering_angle, steering_angle_velocity, speed, acceleration, jerk
0.0,0.0,2.915452003479004,0.0,0.0   # straight driving
0.0,0.0,0.0,0.0,0.0                 # timeout stop
1.5707963705062866,0.0,2.4725010844361235e-16,0.0,0.0  # Transition transient (cos boundary error!)
1.5707963705062866,0.0,4.037900924682617,0.0,0.0       # Steady state (angle tracking complete)

Expected behavior

When the steering error is exactly at or larger than M_PI_2, the speed scale should be limited to 0.01 to allow a slow creep motion rather than dropping to 10^-16 (virtually a zero-command dead zone).

Code Reference

https://github.com/ros-controls/ros2_controllers/blob/jazzy/tricycle_controller/src/tricycle_controller.cpp#L185-L188

Proposed Solution

Change the strict inequality > to >= in the boundary check to catch the exact boundary case:

-  else if (alpha_delta > M_PI_2)
+  else if (alpha_delta >= M_PI_2)
   {
     scale = 0.01;
   }

Environment

  • OS: Ubuntu 24.04 LTS (Noble Numbat)
  • ROS 2 Distro: Jazzy Jalisco
  • Version or commit hash: ros2_controllers version 4.40.1

joseph-ros2-dev avatar Jun 06 '26 16:06 joseph-ros2-dev

This issue is being labeled as stale because it has been open 45 days with no activity. It will be automatically closed after another 45 days without follow-ups.

github-actions[bot] avatar Jul 22 '26 12:07 github-actions[bot]

Correction: I found the existing open PR #2392 after posting this comment. I will not duplicate that work and am stepping back from this issue.

dlanov avatar Aug 06 '26 14:08 dlanov

you can contribute in participating in the discussion there and leave your review

christophfroehlich avatar Aug 07 '26 07:08 christophfroehlich

This issue is being labeled as stale because it has been open 45 days with no activity. It will be automatically closed after another 45 days without follow-ups.

github-actions[bot] avatar Sep 21 '26 12:09 github-actions[bot]

This issue was closed because it has been stalled for 45 days with no activity.

github-actions[bot] avatar Nov 06 '26 12:11 github-actions[bot]