ROS Components for hexapod_robot
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

102 Zeilen
3.4KB

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