ROS Components for hexapod_robot
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

91 行
3.0KB

  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. control_node = Node(
  24. package = "controller_manager",
  25. executable = "ros2_control_node",
  26. parameters = [robot_description, robot_controllers],
  27. output="both"
  28. )
  29. robot_state_publisher_node = Node(
  30. package = "robot_state_publisher",
  31. executable = "robot_state_publisher",
  32. parameters = [robot_description],
  33. output = "both"
  34. )
  35. joint_state_publisher_gui = Node(
  36. package="joint_state_publisher_gui",
  37. executable="joint_state_publisher_gui"
  38. )
  39. rviz_node = Node(
  40. package = "rviz2",
  41. executable = "rviz2",
  42. arguments = ['-d', PathJoinSubstitution([FindPackageShare("hexapod_robot"), "config", "hexapod_robot.rviz"])],
  43. name = "rviz2",
  44. output = "screen",
  45. )
  46. joint_state_broadcaster_spawner = Node (
  47. package = "controller_manager",
  48. executable = "spawner",
  49. arguments = ["joint_state_broadcaster", "--controller-manager", "/controller_manager"]
  50. )
  51. robot_controller_spawner = Node(
  52. package = "controller_manager",
  53. executable = "spawner",
  54. arguments = ["forward_position_controller", "--controller-manager", "/controller_manager"]
  55. )
  56. delay_rviz_after_joint_state_broadcaster_spawner = RegisterEventHandler(
  57. event_handler = OnProcessExit(
  58. target_action = joint_state_broadcaster_spawner,
  59. on_exit = [rviz_node]
  60. )
  61. )
  62. delay_robot_controller_spawner_after_joint_state_broadcaster_spawner = RegisterEventHandler(
  63. event_handler = OnProcessExit(
  64. target_action = joint_state_broadcaster_spawner,
  65. on_exit = [robot_controller_spawner]
  66. )
  67. )
  68. nodes = [
  69. control_node,
  70. robot_state_publisher_node,
  71. joint_state_broadcaster_spawner,
  72. delay_rviz_after_joint_state_broadcaster_spawner,
  73. delay_robot_controller_spawner_after_joint_state_broadcaster_spawner
  74. ]
  75. return LaunchDescription(nodes)