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: doc/migration.rst
+24
Original file line number
Diff line number
Diff line change
@@ -75,12 +75,36 @@ hardware_interface
75
75
******************
76
76
* ``test_components`` was moved to its own package. Update the dependencies if you are using them. (`#1325 <https://github.com/ros-controls/ros2_control/pull/1325>`_)
77
77
* With (`#1683 <https://github.com/ros-controls/ros2_control/pull/1683>`_) the ``rclcpp_lifecycle::State & get_state()`` and ``void set_state(const rclcpp_lifecycle::State & new_state)`` are replaced by ``rclcpp_lifecycle::State & get_lifecycle_state()`` and ``void set_lifecycle_state(const rclcpp_lifecycle::State & new_state)``. This change affects controllers and hardware. This is related to (`#1240 <https://github.com/ros-controls/ros2_control/pull/1240>`_) as variant support introduces ``get_state`` and ``set_state`` methods for setting/getting state of handles.
78
+
* A new ``get_value`` that returns a ``std::optional`` was added to the ``CommandInterface`` and ``StateInterface``. This can be used to check if the value is available or not. (`#1976 <https://github.com/ros-controls/ros2_control/pull/1976>`_)
78
79
79
80
Adaption of Command-/StateInterfaces
80
81
***************************************
81
82
83
+
* The handles for ``Command-/StateInterfaces`` have new set/get methods to access the values.
82
84
* ``Command-/StateInterfaces`` are now created and exported automatically by the framework via the ``on_export_command_interfaces()`` or ``on_export_state_interfaces()`` methods based on the interfaces defined in the ``ros2_control`` XML-tag, which get parsed and the ``InterfaceDescription`` is created accordingly (check the `hardware_info.hpp <https://github.com/ros-controls/ros2_control/tree/{REPOS_FILE_BRANCH}/hardware_interface/include/hardware_interface/hardware_info.hpp>`__). The memory is now allocated in the handle itself.
83
85
86
+
Access to Command-/StateInterfaces
87
+
----------------------------------
88
+
89
+
Earlier code will issue compile-time warnings like:
90
+
91
+
.. code::
92
+
93
+
warning: ‘double hardware_interface::Handle::get_value() const’ is deprecated: Use std::optional<T> get_value() or bool get_value(double & value) instead to retrieve the value. [-Wdeprecated-declarations]
94
+
warning: ignoring return value of ‘bool hardware_interface::Handle::set_value(const T&) [with T = double]’ [-Wunused-result]
95
+
96
+
The old methods are deprecated and will be removed in the future. The new methods are:
97
+
98
+
* ``std::optional<T> get_value()`` or ``bool get_value(T & value)`` for getting the value.
99
+
* ``bool set_value(const T & value)`` for setting the value.
100
+
101
+
The return value ``bool`` or ``std::optional<T>`` with ``get_value`` can be used to check if the value is available or not. Similarly, the ``set_value`` method returns a ``bool`` to check if the value was set or not.
102
+
The ``get_value`` method will return an empty ``std::nullopt`` or ``false`` if the value is not available. The ``set_value`` method will return ``false`` if the value was not set.
103
+
104
+
.. note::
105
+
Checking the result of these operations is important as the value might not be available or the value might not be set.
106
+
This is usually the case when the ros2_control framework has some asynchronous operations due to asynchronous controllers or asynchronous hardware components where different threads are involved to access the same data.
107
+
84
108
Migration of Command-/StateInterfaces
85
109
-------------------------------------
86
110
To adapt to the new way of creating and exporting ``Command-/StateInterfaces`` follow those steps:
0 commit comments