diff --git a/templates/robot_description/common.xacro b/templates/robot_description/common.xacro index 67d695cd..c1a7d059 100644 --- a/templates/robot_description/common.xacro +++ b/templates/robot_description/common.xacro @@ -1,20 +1,63 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + diff --git a/templates/robot_description/robot.urdf.xacro b/templates/robot_description/robot.urdf.xacro index bfc0f13b..a206158a 100644 --- a/templates/robot_description/robot.urdf.xacro +++ b/templates/robot_description/robot.urdf.xacro @@ -30,27 +30,4 @@ sim_gazebo_classic="$(arg sim_gazebo_classic)" sim_gazebo="$(arg sim_gazebo)"/> - - - - - - - $(arg simulation_controllers) - - - - - - - - - - - $(arg simulation_controllers) - $(arg prefix)controller_manager - - - - diff --git a/templates/robot_description/robot_macro.ros2_control.xacro b/templates/robot_description/robot_macro.ros2_control.xacro index 2e0001ca..2d24670d 100644 --- a/templates/robot_description/robot_macro.ros2_control.xacro +++ b/templates/robot_description/robot_macro.ros2_control.xacro @@ -115,5 +115,28 @@ + + + + + + + $(arg simulation_controllers) + + + + + + + + + + + $(arg simulation_controllers) + $(arg prefix)controller_manager + + + + diff --git a/templates/robot_description/robot_macro.xacro b/templates/robot_description/robot_macro.xacro index 2f1271a8..b421855f 100644 --- a/templates/robot_description/robot_macro.xacro +++ b/templates/robot_description/robot_macro.xacro @@ -11,14 +11,14 @@ to get more realistic behaviour--> - + - + diff --git a/templates/ros2_control/append_to_README.md b/templates/ros2_control/append_to_README.md index 07e52701..8df263bc 100644 --- a/templates/ros2_control/append_to_README.md +++ b/templates/ros2_control/append_to_README.md @@ -27,11 +27,11 @@ The general package structure is the following: Consult the repository and [ros2_control documentation](https://ros-controls.github.io/control.ros.org/) for more details. -## Testing the *fake* robot using ros2_control-framework +## Testing the *mock* robot using ros2_control-framework **ATTENTION**: if the package is not build and sourced do this first -1. Start robot's hardware and load controllers (default configuration starts fake hardware) +1. Start robot's hardware and load controllers (default configuration starts mock hardware) ``` ros2 launch $PKG_NAME$ $ROBOT_NAME$.launch.py ``` diff --git a/templates/ros2_control/robot_ros2_control.launch.py b/templates/ros2_control/robot_ros2_control.launch.py index 5f6195da..d3e8bc91 100644 --- a/templates/ros2_control/robot_ros2_control.launch.py +++ b/templates/ros2_control/robot_ros2_control.launch.py @@ -74,14 +74,14 @@ def generate_launch_description(): DeclareLaunchArgument( "use_mock_hardware", default_value="true", - description="Start robot with fake hardware mirroring command to its states.", + description="Start robot with mock hardware mirroring command to its states.", ) ) declared_arguments.append( DeclareLaunchArgument( "mock_sensor_commands", default_value="false", - description="Enable fake command interfaces for sensors used for simple simulations. \ + description="Enable mock command interfaces for sensors used for simple simulations. \ Used only if 'use_mock_hardware' parameter is true.", ) ) @@ -160,9 +160,9 @@ def generate_launch_description(): arguments=["joint_state_broadcaster", "--controller-manager", "/controller_manager"], ) - robot_controllers = [robot_controller] + robot_controller_names = [robot_controller] robot_controller_spawners = [] - for controller in robot_controllers: + for controller in robot_controller_names: robot_controller_spawners += [ Node( package="controller_manager", @@ -171,6 +171,17 @@ def generate_launch_description(): ) ] + inactive_robot_controller_names = ["add_some_controller_name"] + inactive_robot_controller_spawners = [] + for controller in inactive_robot_controller_names: + inactive_robot_controller_spawners += [ + Node( + package="controller_manager", + executable="spawner", + arguments=[controller, "-c", "/controller_manager", "--inactive"], + ) + ] + # Delay loading and activation of `joint_state_broadcaster` after start of ros2_control_node delay_joint_state_broadcaster_spawner_after_ros2_control_node = RegisterEventHandler( event_handler=OnProcessStart( @@ -184,19 +195,30 @@ def generate_launch_description(): ) ) - # Delay loading and activation of robot_controller after `joint_state_broadcaster` + # Delay loading and activation of robot_controller_names after `joint_state_broadcaster` delay_robot_controller_spawners_after_joint_state_broadcaster_spawner = [] - for controller in robot_controller_spawners: + for i, controller in enumerate(robot_controller_spawners): delay_robot_controller_spawners_after_joint_state_broadcaster_spawner += [ RegisterEventHandler( event_handler=OnProcessExit( - target_action=joint_state_broadcaster_spawner, - on_exit=[ - TimerAction( - period=3.0, - actions=[controller], - ), - ], + target_action=robot_controller_spawners[i - 1] + if i > 0 + else joint_state_broadcaster_spawner, + on_exit=[controller], + ) + ) + ] + + # Delay start of inactive_robot_controller_names after other controllers + delay_inactive_robot_controller_spawners_after_joint_state_broadcaster_spawner = [] + for i, controller in enumerate(inactive_robot_controller_spawners): + delay_inactive_robot_controller_spawners_after_joint_state_broadcaster_spawner += [ + RegisterEventHandler( + event_handler=OnProcessExit( + target_action=inactive_robot_controller_spawners[i - 1] + if i > 0 + else robot_controller_spawners[-1], + on_exit=[controller], ) ) ] @@ -210,4 +232,5 @@ def generate_launch_description(): delay_joint_state_broadcaster_spawner_after_ros2_control_node, ] + delay_robot_controller_spawners_after_joint_state_broadcaster_spawner + + delay_inactive_robot_controller_spawners_after_joint_state_broadcaster_spawner )