|
| 1 | +:github_url: https://github.com/ros-controls/ros2_controllers/blob/{REPOS_FILE_BRANCH}/joint_trajectory_controller/doc/decelerate_on_cancel.rst |
| 2 | + |
| 3 | +.. _joint_trajectory_controller_decelerate_on_cancel: |
| 4 | + |
| 5 | +Decelerate on cancel |
| 6 | +==================== |
| 7 | + |
| 8 | +By default, when a trajectory is canceled or preempted, the controller immediately holds the current position. |
| 9 | +This can cause problems for hardware that is moving at high velocity, as the abrupt stop may trigger faults or cause excessive wear. |
| 10 | + |
| 11 | +When the ``decelerate_on_cancel`` feature is enabled, the controller instead generates a smooth stop trajectory that decelerates each joint to zero velocity using a constant deceleration profile before holding position. |
| 12 | + |
| 13 | +.. image:: decelerate_hold_position.png |
| 14 | + :alt: Default behavior: immediate hold position on cancel |
| 15 | + |
| 16 | +*Default behavior: the controller instantly sets the command position to the current position when a trajectory is canceled, causing an abrupt stop.* |
| 17 | + |
| 18 | +.. image:: decelerate_to_stop.png |
| 19 | + :alt: Decelerate to stop behavior on cancel |
| 20 | + |
| 21 | +*With decelerate on cancel enabled: the controller generates a ramped stop trajectory that smoothly decelerates each joint before holding position.* |
| 22 | + |
| 23 | +How it works |
| 24 | +------------ |
| 25 | + |
| 26 | +When a trajectory is canceled or preempted and ``decelerate_on_cancel`` is enabled, the controller: |
| 27 | + |
| 28 | +1. Reads the current velocity of each joint from the velocity state interface. |
| 29 | +2. Computes the stopping distance and time for each joint using its configured ``max_deceleration_on_cancel`` value: |
| 30 | + |
| 31 | + .. math:: |
| 32 | +
|
| 33 | + t_{stop} = \frac{|v|}{a_{max}} |
| 34 | +
|
| 35 | + .. math:: |
| 36 | +
|
| 37 | + d_{stop} = \frac{v \cdot t_{stop}}{2} |
| 38 | +
|
| 39 | + where :math:`v` is the current velocity and :math:`a_{max}` is the configured maximum deceleration. |
| 40 | + |
| 41 | +3. Generates a trajectory with intermediate waypoints that linearly ramp velocity to zero over the computed stopping time. |
| 42 | +4. Appends a final hold-position point at the computed stop position. |
| 43 | + |
| 44 | +Each joint decelerates independently based on its own ``max_deceleration_on_cancel`` value, but the trajectory is synchronized so all joints finish at the same time (the slowest joint's stop time). |
| 45 | + |
| 46 | +Requirements |
| 47 | +------------ |
| 48 | + |
| 49 | +* The hardware must provide a ``velocity`` state interface for all joints in the controller. If velocity state feedback is not available, the controller falls back to the default hold-position behavior. |
| 50 | +* Each joint must have a valid (greater than zero) ``max_deceleration_on_cancel`` value. Joints with a value of ``0.0`` cause the controller to fall back to hold-position behavior. |
| 51 | + |
| 52 | +Configuration |
| 53 | +------------- |
| 54 | + |
| 55 | +Enable the feature by setting ``constraints.decelerate_on_cancel`` to ``true`` and providing a ``max_deceleration_on_cancel`` value (in rad/s^2 or m/s^2) for each joint under ``constraints.<joint_name>``: |
| 56 | + |
| 57 | +.. code-block:: yaml |
| 58 | +
|
| 59 | + controller_name: |
| 60 | + ros__parameters: |
| 61 | + joints: |
| 62 | + - joint_1 |
| 63 | + - joint_2 |
| 64 | + - joint_3 |
| 65 | +
|
| 66 | + constraints: |
| 67 | + decelerate_on_cancel: true |
| 68 | + stopped_velocity_tolerance: 0.01 |
| 69 | + goal_time: 0.0 |
| 70 | + joint_1: |
| 71 | + max_deceleration_on_cancel: 10.0 |
| 72 | + joint_2: |
| 73 | + max_deceleration_on_cancel: 3.0 |
| 74 | + joint_3: |
| 75 | + max_deceleration_on_cancel: 6.0 |
| 76 | +
|
| 77 | +.. note:: |
| 78 | + |
| 79 | + Both ``decelerate_on_cancel`` and ``max_deceleration_on_cancel`` are read-only parameters. They can only be set at controller configuration time and cannot be changed at runtime. |
| 80 | + |
| 81 | +.. note:: |
| 82 | + |
| 83 | + Choose ``max_deceleration_on_cancel`` values that are within the physical limits of your hardware. Values that are too high may still cause faults, while values that are too low will result in longer stopping distances. |
0 commit comments