Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor doc for rst syntax #1068

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 62 additions & 45 deletions controller_manager/doc/controller_chaining.rst
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
:github_url: https://github.com/ros-controls/ros2_control/blob/{REPOS_FILE_BRANCH}/controller_manager/doc/controller_chaining.rst

.. _controller_chaining:

Controller Chaining / Cascade Control
======================================

This document proposes a minimal-viable-implementation of serial controller chaining as described in [Chaining Controllers design document](https://github.com/ros-controls/roadmap/blob/master/design_drafts/controller_chaining.md).
This document proposes a minimal-viable-implementation of serial controller chaining as described in `Chaining Controllers design document <https://github.com/ros-controls/roadmap/blob/master/design_drafts/controller_chaining.md>`__.
Cascade control is a specific type of controller chaining.


## Scope of the Document and Background Knowledge
Scope of the Document and Background Knowledge
-------------------------------------------------------

This approach focuses only on serial chaining of controllers and tries to reuse existing mechanisms for it.
It focuses on [inputs and outputs of a controller](https://github.com/ros-controls/roadmap/blob/master/design_drafts/controller_chaining.md#input--outputs-of-a-controller) and their management in the controller manager.
The concept of [controller groups](controller_chaining.md#controller-group) will be introduced only for clarity reasons, and its only meaning is that controllers in that group can be updated in arbitrary order.
This doesn't mean that the controller groups as described [in the controller chaining document](controller_chaining.md#controller-group) will not be introduced and used in the future.
It focuses on `inputs and outputs of a controller <https://github.com/ros-controls/roadmap/blob/master/design_drafts/controller_chaining.md#input--outputs-of-a-controller>`__ and their management in the controller manager.
The concept of `controller groups <https://github.com/ros-controls/roadmap/blob/master/design_drafts/controller_chaining.md#controller-group>`__ will be introduced only for clarity reasons, and its only meaning is that controllers in that group can be updated in arbitrary order.
This doesn't mean that the controller groups as described `in the controller chaining document <https://github.com/ros-controls/roadmap/blob/master/design_drafts/controller_chaining.md#controller-group>`__ will not be introduced and used in the future.
Nevertheless, the author is convinced that this would add only unnecessary complexity at this stage, although in the long term they *could* provide clearer structure and interfaces.

## Motivation, Purpose and Use
Motivation, Purpose and Use
---------------------------------

To describe the intent of this document, lets focus on the simple yet sufficient example `Example 2 from 'controllers_chaining' design docs <https://github.com/ros-controls/roadmap/blob/master/design_drafts/controller_chaining.md#example-2>`__:

To describe the intent of this document, let focus on simple yet sufficient example ([Example 2 from 'controllers_chaining' design docs](controller_chaining.md#example-2)):
.. image:: images/chaining_example2.png
:alt: Example2

![Example2](images/chaining_example2.png)

In this example, we want to chain 'position_tracking' controller with 'diff_drive_controller' and two PID controllers.
Let's now imagine a use-case where we don't only want to run all those controllers as a group, but also flexibly add preceding steps.
This means the following:

1. When a robot is started, we want to check if motor velocity control is working properly and therefore only PID controllers are activated.
At this stage we can control the input of PID controller also externally using topics.
However, these controllers also provide virtual interfaces, so we can chain them.
Expand All @@ -32,71 +41,79 @@ This means the following:
4. If any of the controllers is deactivated, also all preceding controllers are deactivated.


## Implementation
Implementation
--------------

### A Controller Base-Class: ChainableController
A Controller Base-Class: ChainableController
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

A `ChainableController` extends `ControllerInterface` class with `virtual InterfaceConfiguration input_interface_configuration() const = 0` method.
A ``ChainableController`` extends ``ControllerInterface`` class with ``virtual InterfaceConfiguration input_interface_configuration() const = 0`` method.
This method should implement for each controller that **can be preceded** by another controller exporting all the input interfaces.
For simplicity reasons, it is assumed for now that controller's all input interfaces are used.
Therefore, do not try to implement any exclusive combinations of input interfaces, but rather write multiple controllers if you need exclusivity.

The `ChainableController` base class implements `void set_chained_mode(bool activate)` that sets an internal flag that a controller is used by another controller (in chained mode) and calls `virtual void on_set_chained_mode(bool activate) = 0` that implements controller's specific actions when chained modes is activated or deactivated, e.g., deactivating subscribers.
The ``ChainableController`` base class implements ``void set_chained_mode(bool activate)`` that sets an internal flag that a controller is used by another controller (in chained mode) and calls ``virtual void on_set_chained_mode(bool activate) = 0`` that implements controller's specific actions when chained modes is activated or deactivated, e.g., deactivating subscribers.

As an example, PID controllers export one virtual interface ``pid_reference`` and stop their subscriber ``<controller_name>/pid_reference`` when used in chained mode. 'diff_drive_controller' controller exports list of virtual interfaces ``<controller_name>/v_x``, ``<controller_name>/v_y``, and ``<controller_name>/w_z``, and stops subscribers from topics ``<controller_name>/cmd_vel`` and ``<controller_name>/cmd_vel_unstamped``. Its publishers can continue running.

#### Example
Inner Resource Management
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

PID controllers export one virtual interface `pid_reference` and stop their subscriber `<controller_name>/pid_reference` when used in chained mode.
'diff_drive_controller' controller exports list of virtual interfaces `<controller_name>/v_x`, `<controller_name>/v_y`, and `<controller_name>/w_z`, and stops subscribers from topics `<controller_name>/cmd_vel` and `<controller_name>/cmd_vel_unstamped`. Its publishers can continue running.
After configuring a chainable controller, controller manager calls ``input_interface_configuration`` method and takes ownership over controller's input interfaces.
This is the same process as done by ``ResourceManager`` and hardware interfaces.
Controller manager maintains "claimed" status of interface in a vector (the same as done in ``ResourceManager``).

### Inner Resource Management
After configuring a chainable controller, controller manager calls `input_interface_configuration` method and takes ownership over controller's input interfaces.
This is the same process as done by `ResourceManager` and hardware interfaces.
Controller manager maintains "claimed" status of interface in a vector (the same as done in `ResourceManager`).
Activation and Deactivation Chained Controllers
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

### Activation and Deactivation Chained Controllers
Controller Manager has an additional parameter that describes how controllers are chained.
In the first version, the parameter-structure would have some semantic meaning embedded into it, as follows:
```
controller_manager:
ros__parameters:
chained_controllers:

- parallel_group_1:
- controller1_1
- controller1_2

- parallel_group_2:
- controller2_1
.. code-block:: yaml

controller_manager:
ros__parameters:
chained_controllers:

- parallel_group_1:
- controller1_1
- controller1_2

- parallel_group_2:
- controller2_1

- parallel_group_3:
- controller3_1
- controller3_2
- controller3_3

- parallel_group_3:
- controller3_1
- controller3_2
- controller3_3
...

...
- parallel_group_N:
- controllerN_1
- ...
- controllerN_M

- parallel_group_N:
- controllerN_1
- ...
- controllerN_M
```


This structure is motivated by `filter_chain` structure from [ros/filters repository](https://github.com/ros/filters/tree/ros2) (see [this file for implementation](https://github.com/ros/filters/blob/ros2/include/filters/filter_chain.hpp)).
This structure is motivated by ``filter_chain`` structure from `ros/filters repository <https://github.com/ros/filters/tree/ros2>`__, see `this file for implementation <https://github.com/ros/filters/blob/ros2/include/filters/filter_chain.hpp>`__.

This structure is stored internally by controller manager into an ordered map (`std::map<std::string, std::vector<std::string>>`) with group name as key.
This structure is stored internally by controller manager into an ordered map (``std::map<std::string, std::vector<std::string>>``) with group name as key.
When a controller should be deactivated, the controller manager deactivates all the controllers in the preceding groups first.
All other controllers from the group stay active, as well as all controllers in the following groups.
NOTE: In the future this could be done more intelligently, i.e., deactivate only controllers in the preceding groups that actually precede the controller that should be deactivated.

On the other hand, the controller should be manually activated in the reverse order, i.e., from the those closer to the hardware toward those preceding them.


## Debugging outputs
Debugging outputs
----------------------------

Flag `unavailable` on reference interface does not provide much information about anything at the moment. So don't get confused by it. The reason we have it are internal implementation reasons irelevant for the usage.
Flag ``unavailable`` on reference interface does not provide much information about anything at the moment. So don't get confused by it. The reason we have it are internal implementation reasons irelevant for the usage.


## Closing remarks
Closing remarks
----------------------------

- Maybe addition of the new controller's type `ChainableController` is not necessary. It would also be feasible to add implementation of `input_interface_configuration()` method into `ControllerInterface` class with default result `interface_configuration_type::NONE`.
- Maybe addition of the new controller's type ``ChainableController`` is not necessary. It would also be feasible to add implementation of ``input_interface_configuration()`` method into ``ControllerInterface`` class with default result ``interface_configuration_type::NONE``.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
ros2_control
#################

This is the documentation of the ros2_control framework core.

`GitHub Repository <https://github.com/ros-controls/ros2_control>`_

=================
Expand All @@ -14,15 +16,12 @@ API Documentation

API documentation is parsed by doxygen and can be found `here <../../api/index.html>`_



=========
Features
=========

* :ref:`Command Line Interface (CLI) <ros2controlcli_userdoc>`


========
Concepts
========
Expand All @@ -31,5 +30,6 @@ Concepts
:titlesonly:

Controller Manager <../controller_manager/doc/userdoc.rst>
Controller Chaining / Cascade Control <../controller_manager/doc/controller_chaining.rst>
Hardware Components <../hardware_interface/doc/hardware_components_userdoc.rst>
Mock Components <../hardware_interface/doc/mock_components_userdoc.rst>