diff --git a/gz_ros2_control_demos/launch/cart_example_effort.launch.py b/gz_ros2_control_demos/launch/cart_example_effort.launch.py index 2f59952f..1b7b88ad 100644 --- a/gz_ros2_control_demos/launch/cart_example_effort.launch.py +++ b/gz_ros2_control_demos/launch/cart_example_effort.launch.py @@ -12,52 +12,45 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os - -from ament_index_python.packages import get_package_share_directory - - from launch import LaunchDescription from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription from launch.actions import RegisterEventHandler from launch.event_handlers import OnProcessExit from launch.launch_description_sources import PythonLaunchDescriptionSource -from launch.substitutions import LaunchConfiguration +from launch.substitutions import Command, FindExecutable, PathJoinSubstitution, LaunchConfiguration from launch_ros.actions import Node - -import xacro +from launch_ros.substitutions import FindPackageShare def generate_launch_description(): # Launch Arguments use_sim_time = LaunchConfiguration('use_sim_time', default=True) - gz_ros2_control_demos_path = os.path.join( - get_package_share_directory('gz_ros2_control_demos')) - - xacro_file = os.path.join(gz_ros2_control_demos_path, - 'urdf', - 'test_cart_effort.xacro.urdf') - - doc = xacro.parse(open(xacro_file)) - xacro.process_doc(doc) - params = {'robot_description': doc.toxml()} + # Get URDF via xacro + robot_description_content = Command( + [ + PathJoinSubstitution([FindExecutable(name="xacro")]), + " ", + PathJoinSubstitution( + [FindPackageShare("gz_ros2_control_demos"), "urdf", "test_cart_effort.xacro.urdf"] + ), + ] + ) + robot_description = {"robot_description": robot_description_content} node_robot_state_publisher = Node( package='robot_state_publisher', executable='robot_state_publisher', output='screen', - parameters=[params] + parameters=[robot_description] ) gz_spawn_entity = Node( package='ros_gz_sim', executable='create', output='screen', - parameters=[{'string': doc.toxml(), - 'name': 'cart', - 'allow_renaming': True}], + arguments=["-topic", "robot_description", "-name", "cart", "-allow_renaming", "true"], ) load_joint_state_broadcaster = ExecuteProcess( @@ -75,8 +68,7 @@ def generate_launch_description(): # Launch gazebo environment IncludeLaunchDescription( PythonLaunchDescriptionSource( - [os.path.join(get_package_share_directory('ros_gz_sim'), - 'launch', 'gz_sim.launch.py')]), + [PathJoinSubstitution([FindPackageShare('ros_gz_sim'), 'launch', 'gz_sim.launch.py'])]), launch_arguments=[('gz_args', [' -r -v 3 empty.sdf'])]), RegisterEventHandler( event_handler=OnProcessExit( diff --git a/gz_ros2_control_demos/launch/cart_example_position.launch.py b/gz_ros2_control_demos/launch/cart_example_position.launch.py index 33e96772..933a361a 100644 --- a/gz_ros2_control_demos/launch/cart_example_position.launch.py +++ b/gz_ros2_control_demos/launch/cart_example_position.launch.py @@ -12,52 +12,45 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os - -from ament_index_python.packages import get_package_share_directory - - from launch import LaunchDescription from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription from launch.actions import RegisterEventHandler from launch.event_handlers import OnProcessExit from launch.launch_description_sources import PythonLaunchDescriptionSource -from launch.substitutions import LaunchConfiguration +from launch.substitutions import Command, FindExecutable, PathJoinSubstitution, LaunchConfiguration from launch_ros.actions import Node - -import xacro +from launch_ros.substitutions import FindPackageShare def generate_launch_description(): # Launch Arguments use_sim_time = LaunchConfiguration('use_sim_time', default=True) - gz_ros2_control_demos_path = os.path.join( - get_package_share_directory('gz_ros2_control_demos')) - - xacro_file = os.path.join(gz_ros2_control_demos_path, - 'urdf', - 'test_cart_position.xacro.urdf') - - doc = xacro.parse(open(xacro_file)) - xacro.process_doc(doc) - params = {'robot_description': doc.toxml()} + # Get URDF via xacro + robot_description_content = Command( + [ + PathJoinSubstitution([FindExecutable(name="xacro")]), + " ", + PathJoinSubstitution( + [FindPackageShare("gz_ros2_control_demos"), "urdf", "test_cart_position.xacro.urdf"] + ), + ] + ) + robot_description = {"robot_description": robot_description_content} node_robot_state_publisher = Node( package='robot_state_publisher', executable='robot_state_publisher', output='screen', - parameters=[params] + parameters=[robot_description] ) gz_spawn_entity = Node( package='ros_gz_sim', executable='create', output='screen', - parameters=[{'string': doc.toxml(), - 'name': 'cart', - 'allow_renaming': True}], + arguments=["-topic", "robot_description", "-name", "cart", "-allow_renaming", "true"], ) load_joint_state_broadcaster = ExecuteProcess( @@ -76,8 +69,7 @@ def generate_launch_description(): # Launch gazebo environment IncludeLaunchDescription( PythonLaunchDescriptionSource( - [os.path.join(get_package_share_directory('ros_gz_sim'), - 'launch', 'gz_sim.launch.py')]), + [PathJoinSubstitution([FindPackageShare('ros_gz_sim'), 'launch', 'gz_sim.launch.py'])]), launch_arguments=[('gz_args', [' -r -v 4 empty.sdf'])]), RegisterEventHandler( event_handler=OnProcessExit( diff --git a/gz_ros2_control_demos/launch/cart_example_velocity.launch.py b/gz_ros2_control_demos/launch/cart_example_velocity.launch.py index 251bdcaf..5c7753fb 100644 --- a/gz_ros2_control_demos/launch/cart_example_velocity.launch.py +++ b/gz_ros2_control_demos/launch/cart_example_velocity.launch.py @@ -12,52 +12,45 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os - -from ament_index_python.packages import get_package_share_directory - - from launch import LaunchDescription from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription from launch.actions import RegisterEventHandler from launch.event_handlers import OnProcessExit from launch.launch_description_sources import PythonLaunchDescriptionSource -from launch.substitutions import LaunchConfiguration +from launch.substitutions import Command, FindExecutable, PathJoinSubstitution, LaunchConfiguration from launch_ros.actions import Node - -import xacro +from launch_ros.substitutions import FindPackageShare def generate_launch_description(): # Launch Arguments use_sim_time = LaunchConfiguration('use_sim_time', default=True) - gz_ros2_control_demos_path = os.path.join( - get_package_share_directory('gz_ros2_control_demos')) - - xacro_file = os.path.join(gz_ros2_control_demos_path, - 'urdf', - 'test_cart_velocity.xacro.urdf') - - doc = xacro.parse(open(xacro_file)) - xacro.process_doc(doc) - params = {'robot_description': doc.toxml()} + # Get URDF via xacro + robot_description_content = Command( + [ + PathJoinSubstitution([FindExecutable(name="xacro")]), + " ", + PathJoinSubstitution( + [FindPackageShare("gz_ros2_control_demos"), "urdf", "test_cart_velocity.xacro.urdf"] + ), + ] + ) + robot_description = {"robot_description": robot_description_content} node_robot_state_publisher = Node( package='robot_state_publisher', executable='robot_state_publisher', output='screen', - parameters=[params] + parameters=[robot_description] ) gz_spawn_entity = Node( package='ros_gz_sim', executable='create', output='screen', - parameters=[{'string': doc.toxml(), - 'name': 'cart', - 'allow_renaming': True}], + arguments=["-topic", "robot_description", "-name", "cart", "-allow_renaming", "true"], ) load_joint_state_broadcaster = ExecuteProcess( @@ -71,19 +64,12 @@ def generate_launch_description(): output='screen' ) - load_imu_sensor_broadcaster = ExecuteProcess( - cmd=['ros2', 'control', 'load_controller', '--set-state', 'active', - 'imu_sensor_broadcaster'], - output='screen' - ) - return LaunchDescription([ # Launch gazebo environment IncludeLaunchDescription( PythonLaunchDescriptionSource( - [os.path.join(get_package_share_directory('ros_gz_sim'), - 'launch', 'gz_sim.launch.py')]), - launch_arguments=[('gz_args', [' -r -v 4 empty.sdf'])]), + [PathJoinSubstitution([FindPackageShare('ros_gz_sim'), 'launch', 'gz_sim.launch.py'])]), + launch_arguments=[('gz_args', [' -r -v 3 empty.sdf'])]), RegisterEventHandler( event_handler=OnProcessExit( target_action=gz_spawn_entity, @@ -96,12 +82,6 @@ def generate_launch_description(): on_exit=[load_joint_velocity_controller], ) ), - RegisterEventHandler( - event_handler=OnProcessExit( - target_action=load_joint_velocity_controller, - on_exit=[load_imu_sensor_broadcaster], - ) - ), node_robot_state_publisher, gz_spawn_entity, # Launch Arguments diff --git a/gz_ros2_control_demos/launch/diff_drive_example.launch.py b/gz_ros2_control_demos/launch/diff_drive_example.launch.py index e109d769..a29796bc 100644 --- a/gz_ros2_control_demos/launch/diff_drive_example.launch.py +++ b/gz_ros2_control_demos/launch/diff_drive_example.launch.py @@ -12,56 +12,48 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os - -from ament_index_python.packages import get_package_share_directory - from launch import LaunchDescription from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription from launch.actions import RegisterEventHandler from launch.event_handlers import OnProcessExit from launch.launch_description_sources import PythonLaunchDescriptionSource -from launch.substitutions import LaunchConfiguration +from launch.substitutions import Command, FindExecutable, PathJoinSubstitution, LaunchConfiguration from launch_ros.actions import Node - -import xacro +from launch_ros.substitutions import FindPackageShare def generate_launch_description(): # Launch Arguments use_sim_time = LaunchConfiguration('use_sim_time', default=True) - gz_ros2_control_demos_path = os.path.join( - get_package_share_directory('gz_ros2_control_demos')) - - xacro_file = os.path.join(gz_ros2_control_demos_path, - 'urdf', - 'test_diff_drive.xacro.urdf') - - doc = xacro.parse(open(xacro_file)) - xacro.process_doc(doc) - params = {'robot_description': doc.toxml(), 'use_sim_time': use_sim_time} - - print(params) + # Get URDF via xacro + robot_description_content = Command( + [ + PathJoinSubstitution([FindExecutable(name="xacro")]), + " ", + PathJoinSubstitution( + [FindPackageShare("gz_ros2_control_demos"), "urdf", "test_diff_drive.xacro.urdf"] + ), + ] + ) + robot_description = {"robot_description": robot_description_content} node_robot_state_publisher = Node( package='robot_state_publisher', executable='robot_state_publisher', output='screen', - parameters=[params], + parameters=[robot_description] ) gz_spawn_entity = Node( package='ros_gz_sim', executable='create', output='screen', - parameters=[{'string': doc.toxml(), - 'name': 'diff_drive', - 'allow_renaming': True}], + arguments=["-topic", "robot_description", "-name", "diff_drive", "-allow_renaming", "true"], ) - load_joint_state_controller = ExecuteProcess( + load_joint_state_broadcaster = ExecuteProcess( cmd=['ros2', 'control', 'load_controller', '--set-state', 'active', 'joint_state_broadcaster'], output='screen' @@ -73,31 +65,21 @@ def generate_launch_description(): output='screen' ) - # Bridge - bridge = Node( - package='ros_gz_bridge', - executable='parameter_bridge', - arguments=['/clock@rosgraph_msgs/msg/Clock[ignition.msgs.Clock'], - output='screen' - ) - return LaunchDescription([ - bridge, # Launch gazebo environment IncludeLaunchDescription( PythonLaunchDescriptionSource( - [os.path.join(get_package_share_directory('ros_gz_sim'), - 'launch', 'gz_sim.launch.py')]), + [PathJoinSubstitution([FindPackageShare('ros_gz_sim'), 'launch', 'gz_sim.launch.py'])]), launch_arguments=[('gz_args', [' -r -v 4 empty.sdf'])]), RegisterEventHandler( event_handler=OnProcessExit( target_action=gz_spawn_entity, - on_exit=[load_joint_state_controller], + on_exit=[load_joint_state_broadcaster], ) ), RegisterEventHandler( event_handler=OnProcessExit( - target_action=load_joint_state_controller, + target_action=load_joint_state_broadcaster, on_exit=[load_diff_drive_controller], ) ), diff --git a/gz_ros2_control_demos/launch/gripper_mimic_joint_example.launch.py b/gz_ros2_control_demos/launch/gripper_mimic_joint_example.launch.py index e4b9f82d..db0cdb7c 100644 --- a/gz_ros2_control_demos/launch/gripper_mimic_joint_example.launch.py +++ b/gz_ros2_control_demos/launch/gripper_mimic_joint_example.launch.py @@ -15,52 +15,45 @@ # Author: Denis Stogl (Stogl Robotics Consulting) # -import os - -from ament_index_python.packages import get_package_share_directory - - from launch import LaunchDescription from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription from launch.actions import RegisterEventHandler from launch.event_handlers import OnProcessExit from launch.launch_description_sources import PythonLaunchDescriptionSource -from launch.substitutions import LaunchConfiguration +from launch.substitutions import Command, FindExecutable, PathJoinSubstitution, LaunchConfiguration from launch_ros.actions import Node - -import xacro +from launch_ros.substitutions import FindPackageShare def generate_launch_description(): - # Launch arguments + # Launch Arguments use_sim_time = LaunchConfiguration('use_sim_time', default=True) - gz_ros2_control_demos_path = os.path.join( - get_package_share_directory('gz_ros2_control_demos')) - - xacro_file = os.path.join(gz_ros2_control_demos_path, - 'urdf', - 'test_gripper_mimic_joint.xacro.urdf') - - doc = xacro.parse(open(xacro_file)) - xacro.process_doc(doc) - params = {'robot_description': doc.toxml()} + # Get URDF via xacro + robot_description_content = Command( + [ + PathJoinSubstitution([FindExecutable(name="xacro")]), + " ", + PathJoinSubstitution( + [FindPackageShare("gz_ros2_control_demos"), "urdf", "test_gripper_mimic_joint.xacro.urdf"] + ), + ] + ) + robot_description = {"robot_description": robot_description_content} node_robot_state_publisher = Node( package='robot_state_publisher', executable='robot_state_publisher', output='screen', - parameters=[params] + parameters=[robot_description] ) gz_spawn_entity = Node( package='ros_gz_sim', executable='create', output='screen', - parameters=[{'string': doc.toxml(), - 'name': 'gripper', - 'allow_renaming': True}], + arguments=["-topic", "robot_description", "-name", "gripper", "-allow_renaming", "true"], ) load_joint_state_broadcaster = ExecuteProcess( @@ -79,8 +72,7 @@ def generate_launch_description(): # Launch gazebo environment IncludeLaunchDescription( PythonLaunchDescriptionSource( - [os.path.join(get_package_share_directory('ros_gz_sim'), - 'launch', 'gz_sim.launch.py')]), + [PathJoinSubstitution([FindPackageShare('ros_gz_sim'), 'launch', 'gz_sim.launch.py'])]), launch_arguments=[('gz_args', [' -r -v 4 empty.sdf'])]), RegisterEventHandler( event_handler=OnProcessExit( diff --git a/gz_ros2_control_demos/launch/gripper_mimic_joint_example.launch.xml b/gz_ros2_control_demos/launch/gripper_mimic_joint_example.launch.xml new file mode 100644 index 00000000..72d5e81d --- /dev/null +++ b/gz_ros2_control_demos/launch/gripper_mimic_joint_example.launch.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gz_ros2_control_demos/launch/tricycle_drive_example.launch.py b/gz_ros2_control_demos/launch/tricycle_drive_example.launch.py index 3b773ddb..bfe3ce0e 100644 --- a/gz_ros2_control_demos/launch/tricycle_drive_example.launch.py +++ b/gz_ros2_control_demos/launch/tricycle_drive_example.launch.py @@ -12,56 +12,48 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os - -from ament_index_python.packages import get_package_share_directory - from launch import LaunchDescription from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription from launch.actions import RegisterEventHandler from launch.event_handlers import OnProcessExit from launch.launch_description_sources import PythonLaunchDescriptionSource -from launch.substitutions import LaunchConfiguration +from launch.substitutions import Command, FindExecutable, PathJoinSubstitution, LaunchConfiguration from launch_ros.actions import Node - -import xacro +from launch_ros.substitutions import FindPackageShare def generate_launch_description(): # Launch Arguments use_sim_time = LaunchConfiguration('use_sim_time', default=True) - gz_ros2_control_demos_path = os.path.join( - get_package_share_directory('gz_ros2_control_demos')) - - xacro_file = os.path.join(gz_ros2_control_demos_path, - 'urdf', - 'test_tricycle_drive.xacro.urdf') - - doc = xacro.parse(open(xacro_file)) - xacro.process_doc(doc) - params = {'robot_description': doc.toxml(), 'use_sim_time': use_sim_time} - - print(params) + # Get URDF via xacro + robot_description_content = Command( + [ + PathJoinSubstitution([FindExecutable(name="xacro")]), + " ", + PathJoinSubstitution( + [FindPackageShare("gz_ros2_control_demos"), "urdf", "test_tricycle_drive.xacro.urdf"] + ), + ] + ) + robot_description = {"robot_description": robot_description_content} node_robot_state_publisher = Node( package='robot_state_publisher', executable='robot_state_publisher', output='screen', - parameters=[params], + parameters=[robot_description] ) gz_spawn_entity = Node( package='ros_gz_sim', executable='create', output='screen', - parameters=[{'string': doc.toxml(), - 'name': 'tricyle', - 'allow_renaming': True}], + arguments=["-topic", "robot_description", "-name", "tricyle", "-allow_renaming", "true"], ) - load_joint_state_controller = ExecuteProcess( + load_joint_state_broadcaster = ExecuteProcess( cmd=['ros2', 'control', 'load_controller', '--set-state', 'active', 'joint_state_broadcaster'], output='screen' @@ -86,18 +78,17 @@ def generate_launch_description(): # Launch gazebo environment IncludeLaunchDescription( PythonLaunchDescriptionSource( - [os.path.join(get_package_share_directory('ros_gz_sim'), - 'launch', 'gz_sim.launch.py')]), + [PathJoinSubstitution([FindPackageShare('ros_gz_sim'), 'launch', 'gz_sim.launch.py'])]), launch_arguments=[('gz_args', [' -r -v 4 empty.sdf'])]), RegisterEventHandler( event_handler=OnProcessExit( target_action=gz_spawn_entity, - on_exit=[load_joint_state_controller], + on_exit=[load_joint_state_broadcaster], ) ), RegisterEventHandler( event_handler=OnProcessExit( - target_action=load_joint_state_controller, + target_action=load_joint_state_broadcaster, on_exit=[load_joint_trajectory_controller], ) ),