ROS Components for hexapod_robot
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

105 行
3.5KB

  1. from launch import LaunchDescription
  2. from launch.actions import RegisterEventHandler
  3. from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution
  4. from launch.event_handlers import OnProcessExit
  5. from launch_ros.actions import Node
  6. from launch_ros.substitutions import FindPackageShare
  7. from moveit_configs_utils import MoveItConfigsBuilder
  8. def generate_launch_description():
  9. robot_description_content = Command([
  10. PathJoinSubstitution([FindExecutable(name="xacro")]),
  11. " ",
  12. PathJoinSubstitution(
  13. [
  14. FindPackageShare("hexapod_robot"),
  15. "config",
  16. "urdf",
  17. "hexapod_robot.urdf.xacro"
  18. ]
  19. )
  20. ]
  21. )
  22. robot_description = {"robot_description": robot_description_content}
  23. ros2_controllers = PathJoinSubstitution([FindPackageShare("hexapod_robot"), "config", "ros2_controllers.yaml"])
  24. robot_state_publisher_node = Node(
  25. package = "robot_state_publisher",
  26. executable = "robot_state_publisher",
  27. parameters = [robot_description],
  28. output = "both"
  29. )
  30. ros2_control_node = Node(
  31. package = "controller_manager",
  32. executable = "ros2_control_node",
  33. parameters = [robot_description, ros2_controllers],
  34. output="both"
  35. )
  36. # rviz_node = Node(
  37. # package = "rviz2",
  38. # executable = "rviz2",
  39. # arguments = ['-d', PathJoinSubstitution([FindPackageShare("hexapod_robot"), "config", "hexapod_robot.rviz"])],
  40. # name = "rviz2",
  41. # output = "screen",
  42. # )
  43. joint_state_broadcaster_spawner = Node (
  44. package = "controller_manager",
  45. executable = "spawner",
  46. arguments = ["joint_state_broadcaster", "--controller-manager", "/controller_manager"]
  47. )
  48. # forward_position_controller_spawner = Node(
  49. # package = "controller_manager",
  50. # executable = "spawner",
  51. # arguments = ["forward_position_controller", "--controller-manager", "/controller_manager"]
  52. # )
  53. joint_trajectory_controller_spawner = Node(
  54. package = "controller_manager",
  55. executable = "spawner",
  56. arguments = ["e1_group_controller", "--controller-manager", "/controller_manager"]
  57. )
  58. # delay_rviz_after_joint_state_broadcaster_spawner = RegisterEventHandler(
  59. # event_handler = OnProcessExit(
  60. # target_action = joint_state_broadcaster_spawner,
  61. # on_exit = [rviz_node]
  62. # )
  63. # )
  64. # delay_forward_position_controller_spawner_after_joint_state_broadcaster_spawner = RegisterEventHandler(
  65. # event_handler = OnProcessExit(
  66. # target_action = joint_state_broadcaster_spawner,
  67. # on_exit = [forward_position_controller_spawner]
  68. # )
  69. # )
  70. delay_joint_trajectory_controller_spawner_after_joint_state_broadcaster_spawner = RegisterEventHandler(
  71. event_handler = OnProcessExit(
  72. target_action = joint_state_broadcaster_spawner,
  73. on_exit = [joint_trajectory_controller_spawner]
  74. )
  75. )
  76. nodes = [
  77. ros2_control_node,
  78. robot_state_publisher_node,
  79. joint_state_broadcaster_spawner,
  80. #delay_rviz_after_joint_state_broadcaster_spawner,
  81. # delay_forward_position_controller_spawner_after_joint_state_broadcaster_spawner,
  82. delay_joint_trajectory_controller_spawner_after_joint_state_broadcaster_spawner
  83. ]
  84. return LaunchDescription(nodes)