panda_moveit_config_demo.launch.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. from pathlib import Path
  2. from launch import LaunchDescription
  3. from launch.actions import DeclareLaunchArgument, OpaqueFunction
  4. from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
  5. from launch.conditions import IfCondition, UnlessCondition
  6. from launch_ros.actions import Node
  7. from launch_ros.substitutions import FindPackageShare
  8. from launch.actions import ExecuteProcess
  9. from ament_index_python.packages import get_package_share_directory
  10. from moveit_configs_utils import MoveItConfigsBuilder
  11. from launch_ros.actions import ComposableNodeContainer
  12. from launch_ros.descriptions import ComposableNode
  13. def generate_launch_description():
  14. declared_arguments = []
  15. return LaunchDescription(
  16. declared_arguments + [OpaqueFunction(function=launch_setup)]
  17. )
  18. def launch_setup(context, *args, **kwargs):
  19. current_file_path = Path(__file__).resolve()
  20. current_directory = str(current_file_path.parent)
  21. use_sim_time = { "use_sim_time": True}
  22. moveit_config = (
  23. MoveItConfigsBuilder("moveit_resources_panda")
  24. .robot_description(file_path="config/panda.urdf.xacro")
  25. .trajectory_execution(file_path="config/gripper_moveit_controllers.yaml")
  26. .planning_scene_monitor(
  27. publish_robot_description=True, publish_robot_description_semantic=True
  28. )
  29. .planning_pipelines(
  30. pipelines=["ompl", "chomp", "pilz_industrial_motion_planner"]
  31. )
  32. .to_moveit_configs()
  33. )
  34. # Start the actual move_group node/action server
  35. run_move_group_node = Node(
  36. package="moveit_ros_move_group",
  37. executable="move_group",
  38. output="screen",
  39. parameters=[moveit_config.to_dict() | use_sim_time],
  40. )
  41. rviz_base = LaunchConfiguration("rviz_config")
  42. rviz_config = PathJoinSubstitution(
  43. [current_directory, "panda_moveit_config_demo.rviz"]
  44. )
  45. # RViz
  46. rviz_node = Node(
  47. package="rviz2",
  48. executable="rviz2",
  49. name="rviz2",
  50. output="log",
  51. arguments=["-d", rviz_config],
  52. parameters=[
  53. moveit_config.robot_description,
  54. moveit_config.robot_description_semantic,
  55. moveit_config.robot_description_kinematics,
  56. moveit_config.planning_pipelines,
  57. moveit_config.joint_limits,
  58. ],
  59. )
  60. # Static TF
  61. static_tf = Node(
  62. package="tf2_ros",
  63. executable="static_transform_publisher",
  64. name="static_transform_publisher",
  65. output="log",
  66. arguments=["0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "world", "panda_link0"],
  67. )
  68. rgbd_pc = ComposableNodeContainer(
  69. name='container0',
  70. namespace='',
  71. package='rclcpp_components',
  72. executable='component_container',
  73. composable_node_descriptions=[
  74. ComposableNode(
  75. package='depth_image_proc',
  76. plugin='depth_image_proc::PointCloudXyzrgbNode',
  77. name='point_cloud_xyzrgb_node',
  78. remappings=[('rgb/camera_info', '/color_camera_info'),
  79. ('rgb/image_rect_color', '/camera_image_color'),
  80. ('depth_registered/image_rect','/camera_image_depth'),
  81. ('/points','/pointcloud')]
  82. ),
  83. ],
  84. output='screen',
  85. parameters=[{'use_sim_time': True}],
  86. )
  87. # Publish TF
  88. robot_state_publisher = Node(
  89. package="robot_state_publisher",
  90. executable="robot_state_publisher",
  91. name="robot_state_publisher",
  92. output="both",
  93. parameters=[moveit_config.robot_description],
  94. )
  95. nodes_to_start = [
  96. rviz_node,
  97. static_tf,
  98. robot_state_publisher,
  99. run_move_group_node,
  100. rgbd_pc,
  101. ]
  102. return nodes_to_start