From a4fbac49346f403909dde61629cfeef99e78930c Mon Sep 17 00:00:00 2001 From: Nikhil Singhal Date: Wed, 25 Sep 2024 12:05:17 +0200 Subject: [PATCH] cleanup --- .../launch/controller_manager_launch.py | 53 ++++++++---- .../launch/ignition_launch.py | 82 ++++--------------- .../launch/sim_moveit_scenario_launch.py | 7 +- .../gazebo/arm_sim_scenario/package.xml | 4 +- 4 files changed, 59 insertions(+), 87 deletions(-) diff --git a/simulation/gazebo/arm_sim_scenario/launch/controller_manager_launch.py b/simulation/gazebo/arm_sim_scenario/launch/controller_manager_launch.py index f3da4d71..fe408f68 100644 --- a/simulation/gazebo/arm_sim_scenario/launch/controller_manager_launch.py +++ b/simulation/gazebo/arm_sim_scenario/launch/controller_manager_launch.py @@ -18,9 +18,10 @@ from ament_index_python.packages import get_package_share_directory from launch import LaunchDescription -from launch.actions import DeclareLaunchArgument +from launch.actions import DeclareLaunchArgument, ExecuteProcess from launch.substitutions.launch_configuration import LaunchConfiguration from launch_ros.actions import Node +from launch.conditions import LaunchConfigurationNotEquals import os ARGUMENTS = [ @@ -28,6 +29,9 @@ description='arm_group_controller name'), DeclareLaunchArgument('gripper_group_controller', default_value='panda_hand_controller', description='gripper_group_controller name'), + DeclareLaunchArgument('ros2_control_hardware_type', default_value='mock_components', + choices=['ignition', 'mock_components'], + description='ROS2 control hardware interface type to use for the launch file'), ] @@ -51,34 +55,51 @@ def generate_launch_description(): ("/controller_manager/robot_description", "/robot_description"), ], output="screen", + condition=LaunchConfigurationNotEquals( + "ros2_control_hardware_type", "ignition" + ), ) - joint_state_broadcaster_spawner = Node( - package="controller_manager", - executable="spawner", - arguments=[ + joint_state_broadcaster = ExecuteProcess( + cmd=[ + "ros2", + "control", + "load_controller", + "--set-state", + "active", "joint_state_broadcaster", - "--controller-manager", - "/controller_manager", ], + output="screen", ) - arm_controller_spawner = Node( - package="controller_manager", - executable="spawner", - arguments=[arm_group_controller, "-c", "/controller_manager"], + arm_controller_spawner = ExecuteProcess( + cmd=[ + "ros2", + "control", + "load_controller", + "--set-state", + "active", + arm_group_controller, + ], + output="screen", ) - gripper_controller_spawner = Node( - package="controller_manager", - executable="spawner", - arguments=[gripper_group_controller, "-c", "/controller_manager"], + gripper_controller_spawner = ExecuteProcess( + cmd=[ + "ros2", + "control", + "load_controller", + "--set-state", + "active", + gripper_group_controller + ], + output="screen", ) # Define LaunchDescription variable ld = LaunchDescription(ARGUMENTS) ld.add_action(ros2_control_node) - ld.add_action(joint_state_broadcaster_spawner) + ld.add_action(joint_state_broadcaster) ld.add_action(arm_controller_spawner) ld.add_action(gripper_controller_spawner) return ld diff --git a/simulation/gazebo/arm_sim_scenario/launch/ignition_launch.py b/simulation/gazebo/arm_sim_scenario/launch/ignition_launch.py index bdf5422e..b53a41ad 100644 --- a/simulation/gazebo/arm_sim_scenario/launch/ignition_launch.py +++ b/simulation/gazebo/arm_sim_scenario/launch/ignition_launch.py @@ -17,9 +17,8 @@ import os from ament_index_python.packages import get_package_share_directory from launch import LaunchDescription -from launch.actions import DeclareLaunchArgument, ExecuteProcess, Shutdown, RegisterEventHandler +from launch.actions import DeclareLaunchArgument, ExecuteProcess, Shutdown from launch.substitutions import LaunchConfiguration -from launch.event_handlers import OnProcessExit from launch_ros.actions import Node ARGUMENTS = [ @@ -56,78 +55,29 @@ def generate_launch_description(): ) spawn_robot_node = Node( - package='ros_ign_gazebo', - executable='create', - arguments=['-name', 'panda', - '-x', '0.0', - '-y', '0.0', - '-z', '0.0', - '-Y', '0.0', - '-topic', 'robot_description', - "allow-renaming", "true", - "--ros-args", '--log-level', 'warn'], - output={'both': 'log'}, - ) - - clock_bridge = Node(package='ros_gz_bridge', executable='parameter_bridge', - name='clock_bridge', - output='screen', - arguments=[ - '/clock' + '@rosgraph_msgs/msg/Clock' + '[ignition.msgs.Clock' - ]) - - spawn_joint_state_broadcaster_node = Node( - name='joint_state_broadcaster_spawner', - package='controller_manager', - executable='spawner', + package="ros_gz_sim", + executable="create", + output="screen", arguments=[ - '-c', - 'controller_manager', - 'joint_state_broadcaster', + "-topic", + "robot_description", + "-name", + "panda", + "-allow-renaming", + "true", ], - parameters=[{ - 'use_sim_time': use_sim_time, - }], - ) - - arm_controller_spawner = Node( - package="controller_manager", - executable="spawner", - arguments=["panda_arm_controller", "-c", "/controller_manager"], - ) - - gripper_controller_spawner = Node( - package="controller_manager", - executable="spawner", - arguments=["panda_hand_controller", "-c", "/controller_manager"], - ) - - load_joint_state_broadcaster_event = RegisterEventHandler( - event_handler=OnProcessExit( - target_action=spawn_robot_node, - on_exit=[spawn_joint_state_broadcaster_node] - ) - ) - - load_arm_controller_event = RegisterEventHandler( - event_handler=OnProcessExit( - target_action=spawn_joint_state_broadcaster_node, - on_exit=[arm_controller_spawner] - ) ) - load_gripper_controller_event = RegisterEventHandler( - event_handler=OnProcessExit( - target_action=spawn_joint_state_broadcaster_node, - on_exit=[gripper_controller_spawner] - ) + # Clock Bridge + clock_bridge = Node( + package="ros_gz_bridge", + executable="parameter_bridge", + arguments=["/clock@rosgraph_msgs/msg/Clock[ignition.msgs.Clock"], + output="screen", ) ld = LaunchDescription(ARGUMENTS) ld.add_action(ignition_gazebo) ld.add_action(clock_bridge) ld.add_action(spawn_robot_node) - ld.add_action(load_joint_state_broadcaster_event) - ld.add_action(load_arm_controller_event) - ld.add_action(load_gripper_controller_event) return ld diff --git a/simulation/gazebo/arm_sim_scenario/launch/sim_moveit_scenario_launch.py b/simulation/gazebo/arm_sim_scenario/launch/sim_moveit_scenario_launch.py index 77892d23..c599c1bc 100644 --- a/simulation/gazebo/arm_sim_scenario/launch/sim_moveit_scenario_launch.py +++ b/simulation/gazebo/arm_sim_scenario/launch/sim_moveit_scenario_launch.py @@ -73,10 +73,9 @@ def generate_launch_description(): controller_manager = IncludeLaunchDescription( PythonLaunchDescriptionSource([PathJoinSubstitution([arm_sim_scenario_dir, 'launch', 'controller_manager_launch.py'])]), - condition=LaunchConfigurationEquals( - launch_configuration_name='arg_ros2_control_hardware_type', - expected_value='mock_components' - ), + launch_arguments={ + 'arg_ros2_control_hardware_type': ros2_control_hardware_type, + }.items() ) ignition = IncludeLaunchDescription( diff --git a/simulation/gazebo/arm_sim_scenario/package.xml b/simulation/gazebo/arm_sim_scenario/package.xml index 0a8af533..cf51d2fa 100644 --- a/simulation/gazebo/arm_sim_scenario/package.xml +++ b/simulation/gazebo/arm_sim_scenario/package.xml @@ -20,7 +20,9 @@ moveit_planners_chomp gripper_controllers joint_trajectory_controller - + ros2_control + ros_gz_bridge + ros_gz_sim ament_lint_auto ament_lint_common