Skip to content

Commit

Permalink
Add CM switch_controller service timeout as parameter to spawner.py (
Browse files Browse the repository at this point in the history
…#1790)

Co-authored-by: Felix Exner (fexner) <[email protected]>
Co-authored-by: Sai Kishor Kothakota <[email protected]>
(cherry picked from commit 23bd1c3)

# Conflicts:
#	controller_manager/doc/userdoc.rst
#	doc/release_notes.rst
  • Loading branch information
christophfroehlich authored and mergify[bot] committed Nov 18, 2024
1 parent 099e68e commit a55d9d0
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 8 deletions.
36 changes: 32 additions & 4 deletions controller_manager/controller_manager/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,16 @@ def main(args=None):
"--controller-manager-timeout",
help="Time to wait for the controller manager",
required=False,
default=0,
default=0.0,
type=float,
)
parser.add_argument(
"--switch-timeout",
help="Time to wait for a successful state switch of controllers."
" Useful when switching cannot be performed immediately, e.g.,"
" paused simulations at startup",
required=False,
default=5.0,
type=float,
)
parser.add_argument(
Expand All @@ -139,6 +148,7 @@ def main(args=None):
controller_manager_name = args.controller_manager
param_file = args.param_file
controller_manager_timeout = args.controller_manager_timeout
switch_timeout = args.switch_timeout

if param_file and not os.path.isfile(param_file):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), param_file)
Expand Down Expand Up @@ -216,7 +226,13 @@ def main(args=None):

if not args.stopped and not args.inactive and not args.activate_as_group:
ret = switch_controllers(
node, controller_manager_name, [], [controller_name], True, True, 5.0
node,
controller_manager_name,
[],
[controller_name],
True,
True,
switch_timeout,
)
if not ret.ok:
node.get_logger().error(
Expand All @@ -234,7 +250,13 @@ def main(args=None):

if not args.stopped and not args.inactive and args.activate_as_group:
ret = switch_controllers(
node, controller_manager_name, [], controller_names, True, True, 5.0
node,
controller_manager_name,
[],
controller_names,
True,
True,
switch_timeout,
)
if not ret.ok:
node.get_logger().error(
Expand Down Expand Up @@ -262,7 +284,13 @@ def main(args=None):
node.get_logger().info("Interrupt captured, deactivating and unloading controller")
# TODO(saikishor) we might have an issue in future, if any of these controllers is in chained mode
ret = switch_controllers(
node, controller_manager_name, controller_names, [], True, True, 5.0
node,
controller_manager_name,
controller_names,
[],
True,
True,
switch_timeout,
)
if not ret.ok:
node.get_logger().error(
Expand Down
18 changes: 17 additions & 1 deletion controller_manager/controller_manager/unspawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,33 @@ def main(args=None):
default="/controller_manager",
required=False,
)
parser.add_argument(
"--switch-timeout",
help="Time to wait for a successful state switch of controllers."
" Useful when switching cannot be performed immediately, e.g.,"
" paused simulations at startup",
required=False,
default=5.0,
type=float,
)

command_line_args = rclpy.utilities.remove_ros_args(args=sys.argv)[1:]
args = parser.parse_args(command_line_args)
controller_names = args.controller_names
controller_manager_name = args.controller_manager
switch_timeout = args.switch_timeout

node = Node("unspawner_" + controller_names[0])
try:
# Ignore returncode, because message is already printed and we'll try to unload anyway
ret = switch_controllers(
node, controller_manager_name, controller_names, [], True, True, 5.0
node,
controller_manager_name,
controller_names,
[],
True,
True,
switch_timeout,
)
node.get_logger().info("Deactivated controller")

Expand Down
22 changes: 19 additions & 3 deletions controller_manager/doc/userdoc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,15 @@ There are two scripts to interact with controller manager from launch files:
.. code-block:: console
$ ros2 run controller_manager spawner -h
<<<<<<< HEAD
usage: spawner [-h] [-c CONTROLLER_MANAGER] [-p PARAM_FILE] [--load-only] [--stopped] [-t CONTROLLER_TYPE] [-u]
[--controller-manager-timeout CONTROLLER_MANAGER_TIMEOUT]
controller_name
=======
usage: spawner [-h] [-c CONTROLLER_MANAGER] [-p PARAM_FILE] [-n NAMESPACE] [--load-only] [--inactive] [-u] [--controller-manager-timeout CONTROLLER_MANAGER_TIMEOUT]
[--switch-timeout SWITCH_TIMEOUT] [--activate-as-group]
controller_names [controller_names ...]
>>>>>>> 23bd1c3 (Add CM `switch_controller` service timeout as parameter to spawner.py (#1790))

positional arguments:
controller_name Name of the controller
Expand All @@ -110,6 +116,13 @@ There are two scripts to interact with controller manager from launch files:
-u, --unload-on-kill Wait until this application is interrupted and unload controller
--controller-manager-timeout CONTROLLER_MANAGER_TIMEOUT
Time to wait for the controller manager
<<<<<<< HEAD
=======
--switch-timeout SWITCH_TIMEOUT
Time to wait for a successful state switch of controllers. Useful if controllers cannot be switched immediately, e.g., paused
simulations at startup
--activate-as-group Activates all the parsed controllers list together instead of one by one. Useful for activating all chainable controllers altogether
>>>>>>> 23bd1c3 (Add CM `switch_controller` service timeout as parameter to spawner.py (#1790))


The parsed controller config file can follow the same conventions as the typical ROS 2 parameter file format. Now, the spawner can handle config files with wildcard entries and also the controller name in the absolute namespace. See the following examples on the config files:
Expand Down Expand Up @@ -172,15 +185,18 @@ The parsed controller config file can follow the same conventions as the typical
.. code-block:: console
$ ros2 run controller_manager unspawner -h
usage: unspawner [-h] [-c CONTROLLER_MANAGER] controller_name
usage: unspawner [-h] [-c CONTROLLER_MANAGER] [--switch-timeout SWITCH_TIMEOUT] controller_names [controller_names ...]
positional arguments:
controller_name Name of the controller
controller_names Name of the controller
optional arguments:
options:
-h, --help show this help message and exit
-c CONTROLLER_MANAGER, --controller-manager CONTROLLER_MANAGER
Name of the controller manager ROS node
--switch-timeout SWITCH_TIMEOUT
Time to wait for a successful state switch of controllers. Useful if controllers cannot be switched immediately, e.g., paused
simulations at startup
``hardware_spawner``
^^^^^^^^^^^^^^^^^^^^^^
Expand Down
44 changes: 44 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,50 @@ controller_interface
controller_manager
******************

<<<<<<< HEAD
=======
* Configured chainable controller: Listed exported interfaces are unavailable and unclaimed
* Active chainable controller (not in chained mode): Listed exported interfaces are available but unclaimed
* Active chainable controller (in chained mode): Listed exported interfaces are available and claimed
* Try using SCHED_FIFO on any kernel (`#1142 <https://github.com/ros-controls/ros2_control/pull/1142>`_)
* A method to get node options to setup the controller node was added (`#1169 <https://github.com/ros-controls/ros2_control/pull/1169>`_): ``get_node_options`` can be overridden by controllers, this would make it easy for other controllers to be able to setup their own custom node options
* CM now subscribes to ``robot_description`` topic instead of ``~/robot_description`` (`#1410 <https://github.com/ros-controls/ros2_control/pull/1410>`_).
* Change the controller sorting with an approach similar to directed acyclic graphs (`#1384 <https://github.com/ros-controls/ros2_control/pull/1384>`_)
* Changes from `(PR #1256) <https://github.com/ros-controls/ros2_control/pull/1256>`__

* All ``joints`` defined in the ``<ros2_control>``-tag have to be present in the URDF received :ref:`by the controller manager <doc/ros2_control/controller_manager/doc/userdoc:subscribers>`, otherwise the following error is shown:

The published robot description file (URDF) seems not to be genuine. The following error was caught: <unknown_joint> not found in URDF.

This is to ensure that the URDF and the ``<ros2_control>``-tag are consistent. E.g., for configuration ports use ``gpio`` interface types instead.

* The syntax for mimic joints is changed to the `official URDF specification <https://wiki.ros.org/urdf/XML/joint>`__.

.. code-block:: xml
<joint name="right_finger_joint" type="prismatic">
<axis xyz="0 1 0"/>
<origin xyz="0.0 -0.48 1" rpy="0.0 0.0 0.0"/>
<parent link="base"/>
<child link="finger_right"/>
<limit effort="1000.0" lower="0" upper="0.38" velocity="10"/>
</joint>
<joint name="left_finger_joint" type="prismatic">
<mimic joint="right_finger_joint" multiplier="1" offset="0"/>
<axis xyz="0 1 0"/>
<origin xyz="0.0 0.48 1" rpy="0.0 0.0 3.1415926535"/>
<parent link="base"/>
<child link="finger_left"/>
<limit effort="1000.0" lower="0" upper="0.38" velocity="10"/>
</joint>
The parameters within the ``ros2_control`` tag are not supported any more.
* The support for the ``description`` parameter for loading the URDF was removed (`#1358 <https://github.com/ros-controls/ros2_control/pull/1358>`_).
* The ``--controller-type`` or ``-t`` spawner arg is removed. Now the controller type is defined in the controller configuration file with ``type`` field (`#1639 <https://github.com/ros-controls/ros2_control/pull/1639>`_).
* The ``--namespace`` or ``-n`` spawner arg is deprecated. Now the spawner namespace can be defined using the ROS 2 standard way (`#1640 <https://github.com/ros-controls/ros2_control/pull/1640>`_).
* Added support for the wildcard entries for the controller configuration files (`#1724 <https://github.com/ros-controls/ros2_control/pull/1724>`_).
* ``--switch-timeout`` was added as parameter to the helper scripts ``spawner.py`` and ``unspawner.py``. Useful if controllers cannot be switched immediately, e.g., paused simulations at startup (`#1790 <https://github.com/ros-controls/ros2_control/pull/1790>`_).
>>>>>>> 23bd1c3 (Add CM `switch_controller` service timeout as parameter to spawner.py (#1790))
* ``ros2_control_node`` can now handle the sim time used by different simulators, when ``use_sim_time`` is set to true (`#1810 <https://github.com/ros-controls/ros2_control/pull/1810>`_).
* The ``ros2_control_node`` node now accepts the ``thread_priority`` parameter to set the scheduler priority of the controller_manager's RT thread (`#1820 <https://github.com/ros-controls/ros2_control/pull/1820>`_).
* Added support for the wildcard entries for the controller configuration files (`#1724 <https://github.com/ros-controls/ros2_control/pull/1724>`_).
Expand Down

0 comments on commit a55d9d0

Please sign in to comment.