You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: controller_manager/doc/userdoc.rst
+78Lines changed: 78 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -356,6 +356,84 @@ Note that not all controllers have to be restarted, e.g., broadcasters.
356
356
Restarting hardware
357
357
^^^^^^^^^^^^^^^^^^^^^
358
358
359
+
<<<<<<< HEAD
359
360
If hardware gets restarted then you should go through its lifecycle again.
360
361
This can be simply achieved by returning ``ERROR`` from ``write`` and ``read`` methods of interface implementation.
361
362
**NOT IMPLEMENTED YET - PLEASE STOP/RESTART ALL CONTROLLERS MANUALLY FOR NOW** The controller manager detects that and stops all the controllers that are commanding that hardware and restarts broadcasters that are listening to its states.
363
+
=======
364
+
If hardware gets restarted then you should go through its lifecycle again in order to reconfigure and export the interfaces
365
+
366
+
Hardware and Controller Errors
367
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
368
+
369
+
If the hardware during it's ``read`` or ``write`` method returns ``return_type::ERROR``, the controller manager will stop all controllers that are using the hardware's command and state interfaces.
370
+
Likewise, if a controller returns ``return_type::ERROR`` from its ``update`` method, the controller manager will deactivate the respective controller. In future, the controller manager will try to start any fallback controllers if available.
371
+
372
+
Factors that affect Determinism
373
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
374
+
When run under the conditions determined in the above section, the determinism is assured up to the limitations of the hardware and the real-time kernel. However, there are some situations that can affect determinism:
375
+
376
+
* When a controller fails to activate, the controller_manager will call the methods ``prepare_command_mode_switch`` and ``perform_command_mode_switch`` to stop the started interfaces. These calls can cause jitter in the main control loop.
377
+
378
+
Support for Asynchronous Updates
379
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
380
+
For some applications, it is desirable to run a controller at a lower frequency than the controller manager's update rate. For instance, if the ``update_rate`` for the controller manager is 100Hz, the sum of the execution times of all controllers' ``update`` calls and hardware components ``read`` and ``write`` calls must be below 10ms. If one controller requires 15ms of execution time, it cannot be executed synchronously without affecting the overall system update rate. Running a controller asynchronously can be beneficial in this scenario.
381
+
382
+
The async update support is transparent to each controller implementation. A controller can be enabled for asynchronous updates by setting the ``is_async`` parameter to ``true``. The controller manager will load the controller accordingly. For example:
383
+
384
+
.. code-block:: yaml
385
+
386
+
controller_manager:
387
+
ros__parameters:
388
+
update_rate: 100# Hz
389
+
...
390
+
391
+
example_async_controller:
392
+
ros__parameters:
393
+
type: example_controller/ExampleAsyncController
394
+
is_async: true
395
+
update_rate: 20# Hz
396
+
...
397
+
398
+
will result in the controller being loaded and configured to run at 20Hz, while the controller manager runs at 100Hz. The description of the parameters can be found in the `Common Controller Parameters <https://control.ros.org/master/doc/ros2_controllers/doc/controllers_index.html#common-controller-parameters>`_ section of the ros2_controllers documentation.
399
+
400
+
Scheduling Behavior
401
+
----------------------
402
+
From a design perspective, the controller manager functions as a scheduler that triggers updates for asynchronous controllers during the control loop.
403
+
404
+
In this case, the ``ControllerInterfaceBase`` calls ``AsyncFunctionHandler`` to handle the actual ``update`` callback of the controller, which is the same mechanism used by the resource manager to support read/write operations for asynchronous hardware. When a controller is configured to run asynchronously, the controller interface creates an async handler during the controller's configuration and binds it to the controller's update method. The async handler thread created by the controller interface has either the same thread priority as the controller manager or the priority specified by the ``thread_priority`` parameter. When triggered by the controller manager, the async handler evaluates if the previous trigger is successfully finished and then calls the update method.
405
+
406
+
If the update takes significant time and another update is triggered while the previous update is still running, the result of the previous update will be used. When this situation occurs, the controller manager will print a missing update cycle message, informing the user that they need to lower their controller's frequency as the computation is taking longer than initially estimated, as shown in the following example:
407
+
408
+
.. code-block:: console
409
+
410
+
[ros2_control_node-1] [WARN] [1741626670.311533972] [example_async_controller]: The controller missed xx update cycles out of yy total triggers.
411
+
412
+
If the async controller's update method throws an unhandled exception, the controller manager will handle it the same way as the synchronous controllers, deactivating the controller. It will also print an error message, similar to the following:
413
+
414
+
.. code-block:: console
415
+
416
+
[ros2_control_node-1] [ERROR] [1741629098.352771957] [AsyncFunctionHandler]: AsyncFunctionHandler: Exception caught in the async callback thread!
417
+
...
418
+
[ros2_control_node-1] [ERROR] [1741629098.352874151] [controller_manager]: Caught exception of type : St13runtime_error while updating controller
419
+
[ros2_control_node-1] [ERROR] [1741629098.352940701] [controller_manager]: Deactivating controllers : [example_async_controller] as their update resulted in an error!
420
+
421
+
Monitoring and Tuning
422
+
----------------------
423
+
424
+
ros2_control ``controller_interface`` has a ``ControllerUpdateStats`` structure which can be used to monitor the controller update rate and the missed update cycles. The data is published to the ``/diagnostics`` topic. This can be used to fine tune the controller update rate.
425
+
426
+
427
+
Different Clocks used by Controller Manager
428
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
429
+
430
+
The controller manager internally uses the following two different clocks for a non-simulation setup:
431
+
432
+
- ``RCL_ROS_TIME``: This clock is used mostly in the non-realtime loops.
433
+
- ``RCL_STEADY_TIME``: This clock is used mostly in the realtime loops for the ``read``, ``update``, and ``write`` loops. However, when the controller manager is used in a simulation environment, the ``RCL_ROS_TIME`` clock is used for triggering the ``read``, ``update``, and ``write`` loops.
434
+
435
+
The ``time`` argument in the ``read`` and ``write`` methods of the hardware components is of type ``RCL_STEADY_TIME``, as most of the hardware expects the time to be monotonic and not affected by the system time changes. However, the ``time`` argument in the ``update`` method of the controller is of type ``RCL_ROS_TIME`` as the controller is the one that interacts with other nodes or topics to receive the commands or publish the state. This ``time`` argument can be used by the controllers to validate the received commands or to publish the state at the correct timestamp.
436
+
The ``period`` argument in the ``read``, ``update`` and ``write`` methods is calculated using the trigger clock of type ``RCL_STEADY_TIME`` so it is always monotonic.
437
+
438
+
The reason behind using different clocks is to avoid the issues related to the affect of system time changes in the realtime loops. The ``ros2_control_node`` now also detects the overruns caused by the system time changes and longer execution times of the controllers and hardware components. The controller manager will print a warning message if the controller or hardware component misses the update cycle due to the system time changes or longer execution times.
439
+
>>>>>>> ff52562 (Fix exclusive hardware control mode switching on controller failed activation (#1522))
0 commit comments