Skip to content

Commit 9b7aeb1

Browse files
Removed empty callbacks in controllers and updated documentation (#731)
--------- Co-authored-by: Christoph Fröhlich <[email protected]>
1 parent 999824e commit 9b7aeb1

File tree

3 files changed

+11
-64
lines changed

3 files changed

+11
-64
lines changed

example_7/controller/include/ros2_control_demo_example_7/r6bot_controller.hpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,6 @@ class RobotController : public controller_interface::ControllerInterface
6262
controller_interface::CallbackReturn on_deactivate(
6363
const rclcpp_lifecycle::State & previous_state) override;
6464

65-
controller_interface::CallbackReturn on_cleanup(
66-
const rclcpp_lifecycle::State & previous_state) override;
67-
68-
controller_interface::CallbackReturn on_error(
69-
const rclcpp_lifecycle::State & previous_state) override;
70-
71-
controller_interface::CallbackReturn on_shutdown(
72-
const rclcpp_lifecycle::State & previous_state) override;
73-
7465
protected:
7566
std::vector<std::string> joint_names_;
7667
std::vector<std::string> command_interface_types_;

example_7/controller/r6bot_controller.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,6 @@ controller_interface::CallbackReturn RobotController::on_deactivate(const rclcpp
181181
return CallbackReturn::SUCCESS;
182182
}
183183

184-
controller_interface::CallbackReturn RobotController::on_cleanup(const rclcpp_lifecycle::State &)
185-
{
186-
return CallbackReturn::SUCCESS;
187-
}
188-
189-
controller_interface::CallbackReturn RobotController::on_error(const rclcpp_lifecycle::State &)
190-
{
191-
return CallbackReturn::SUCCESS;
192-
}
193-
194-
controller_interface::CallbackReturn RobotController::on_shutdown(const rclcpp_lifecycle::State &)
195-
{
196-
return CallbackReturn::SUCCESS;
197-
}
198-
199184
} // namespace ros2_control_demo_example_7
200185

201186
#include "pluginlib/class_list_macros.hpp"

example_7/doc/userdoc.rst

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -333,17 +333,21 @@ Certain interface methods are called during transitions between these states. Du
333333

334334
The following code blocks will explain the requirements for writing a new controller.
335335

336-
The controller plugin for the tutorial robot is a class called ``RobotController`` that inherits from ``controller_interface::ControllerInterface``. The ``RobotController`` must implement nine public methods. The last six are `managed node <https://design.ros2.org/articles/node_lifecycle.html>`__ transitions callbacks.
336+
The controller plugin for the tutorial robot is a class called ``RobotController`` that inherits from ``controller_interface::ControllerInterface``. The ``RobotController`` must implement the following public methods:
337337

338338
1. ``command_interface_configuration``
339339
2. ``state_interface_configuration``
340340
3. ``update``
341-
4. ``on_configure``
342-
5. ``on_activate``
343-
6. ``on_deactivate``
344-
7. ``on_cleanup``
345-
8. ``on_error``
346-
9. ``on_shutdown``
341+
342+
The following methods are `managed node <https://design.ros2.org/articles/node_lifecycle.html>`__ transitions callbacks. These overrides are optional and only the ``on_configure``, ``on_activate`` and ``on_deactivate`` have been used in this example.
343+
The ``on_cleanup`` and ``on_shutdown`` methods are called when the controller's lifecycle node transitions to the shutdown state. They should handle memory deallocation and general cleanup. The ``on_error`` method is invoked if the managed node encounters a failure during a state transition.
344+
345+
1. ``on_configure``
346+
2. ``on_activate``
347+
3. ``on_deactivate``
348+
4. ``on_cleanup``
349+
5. ``on_error``
350+
6. ``on_shutdown``
347351

348352

349353
.. code-block:: c++
@@ -357,9 +361,6 @@ The controller plugin for the tutorial robot is a class called ``RobotController
357361
controller_interface::CallbackReturn on_configure(const rclcpp_lifecycle::State &previous_state) override;
358362
controller_interface::CallbackReturn on_activate(const rclcpp_lifecycle::State &previous_state) override;
359363
controller_interface::CallbackReturn on_deactivate(const rclcpp_lifecycle::State &previous_state) override;
360-
controller_interface::CallbackReturn on_cleanup(const rclcpp_lifecycle::State &previous_state) override;
361-
controller_interface::CallbackReturn on_error(const rclcpp_lifecycle::State &previous_state) override;
362-
controller_interface::CallbackReturn on_shutdown(const rclcpp_lifecycle::State &previous_state) override;
363364
// private members
364365
// ...
365366
}
@@ -442,36 +443,6 @@ The ``on_deactivate`` is called when a controller stops running. It is important
442443
return CallbackReturn::SUCCESS;
443444
}
444445

445-
The ``on_cleanup`` and ``on_shutdown`` are called when the controller's lifecycle node is transitioning to shutting down. Freeing any allocated memory and general cleanup should be done in these methods.
446-
447-
.. code-block:: c++
448-
449-
controller_interface::CallbackReturn on_cleanup(const rclcpp_lifecycle::State &previous_state){
450-
// Callback function for cleanup transition
451-
// ...
452-
return CallbackReturn::SUCCESS;
453-
}
454-
455-
456-
.. code-block:: c++
457-
458-
controller_interface::CallbackReturn on_shutdown(const rclcpp_lifecycle::State &previous_state){
459-
// Callback function for shutdown transition
460-
// ...
461-
return CallbackReturn::SUCCESS;
462-
}
463-
464-
465-
The ``on_error`` method is called if the managed node fails a state transition. This should generally never happen.
466-
467-
.. code-block:: c++
468-
469-
controller_interface::CallbackReturn on_error(const rclcpp_lifecycle::State &previous_state){
470-
// Callback function for erroneous transition
471-
// ...
472-
return CallbackReturn::SUCCESS;
473-
}
474-
475446

476447
Plugin description file (controller)
477448
************************************

0 commit comments

Comments
 (0)