当前位置:   article > 正文

ros2-humble使用moveit,自己创建的机械臂模型无法运行demo.launch.py_ros2 moveit

ros2 moveit

报错大概是这样的,当时我没截取屏幕,用了一下别人的报错,原主在这里:https://blog.csdn.net/m0_59796104/article/details/138900371#comments_33466284

实际上打开demo.launch.py文件会发现里面什么都没有

类似下面的情况:

  1. from moveit_configs_utils import MoveItConfigsBuilder
  2. from moveit_configs_utils.launches import generate_move_group_launch
  3. def generate_launch_description():
  4. moveit_config = MoveItConfigsBuilder("xxx", package_name="xxx_config").to_moveit_configs()
  5. return generate_move_group_launch(moveit_config)

把demo.launch.py里面东西替换成下面的内容:

  1. import os
  2. from launch import LaunchDescription
  3. from launch.actions import DeclareLaunchArgument
  4. from launch.substitutions import LaunchConfiguration
  5. from launch.conditions import IfCondition, UnlessCondition
  6. from launch_ros.actions import Node
  7. from launch.actions import ExecuteProcess
  8. from ament_index_python.packages import get_package_share_directory
  9. from moveit_configs_utils import MoveItConfigsBuilder
  10. def generate_launch_description():
  11. # Command-line arguments
  12. db_arg = DeclareLaunchArgument(
  13. "db", default_value="False", description="Database flag"
  14. )
  15. moveit_config = (
  16. MoveItConfigsBuilder("xxx")
  17. .robot_description(file_path="config/xxx.urdf.xacro")
  18. .robot_description_semantic(file_path="config/xxx.srdf")
  19. .trajectory_execution(file_path="config/moveit_controllers.yaml")
  20. .to_moveit_configs()
  21. )
  22. # Start the actual move_group node/action server
  23. run_move_group_node = Node(
  24. package="moveit_ros_move_group",
  25. executable="move_group",
  26. output="screen",
  27. parameters=[moveit_config.to_dict()],
  28. )
  29. # RViz
  30. rviz_base = os.path.join(
  31. get_package_share_directory("xxx_moveit_config"), "config"
  32. )
  33. rviz_full_config = os.path.join(rviz_base, "moveit.rviz")
  34. rviz_node = Node(
  35. package="rviz2",
  36. executable="rviz2",
  37. name="rviz2",
  38. output="log",
  39. arguments=["-d", rviz_full_config],
  40. parameters=[
  41. moveit_config.robot_description,
  42. moveit_config.robot_description_semantic,
  43. moveit_config.planning_pipelines,
  44. moveit_config.robot_description_kinematics,
  45. ],
  46. )
  47. # Static TF
  48. static_tf = Node(
  49. package="tf2_ros",
  50. executable="static_transform_publisher",
  51. name="static_transform_publisher",
  52. output="log",
  53. arguments=["0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "world", "base_link"],
  54. )
  55. # Publish TF
  56. robot_state_publisher = Node(
  57. package="robot_state_publisher",
  58. executable="robot_state_publisher",
  59. name="robot_state_publisher",
  60. output="both",
  61. parameters=[moveit_config.robot_description],
  62. )
  63. # ros2_control using FakeSystem as hardware
  64. ros2_controllers_path = os.path.join(
  65. get_package_share_directory("xxx_moveit_config"),
  66. "config",
  67. "ros2_controllers.yaml",
  68. )
  69. ros2_control_node = Node(
  70. package="controller_manager",
  71. executable="ros2_control_node",
  72. parameters=[ros2_controllers_path],
  73. remappings=[
  74. ("/controller_manager/robot_description", "/robot_description"),
  75. ],
  76. output="both",
  77. )
  78. joint_state_broadcaster_spawner = Node(
  79. package="controller_manager",
  80. executable="spawner",
  81. arguments=[
  82. "joint_state_broadcaster",
  83. "--controller-manager",
  84. "/controller_manager",
  85. ],
  86. )
  87. xxx_xx_controller_spawner = Node(
  88. package="controller_manager",
  89. executable="spawner",
  90. arguments=[
  91. "xxx_xx_controller",
  92. "--controller-manager",
  93. "/controller_manager",
  94. ],
  95. )
  96. # Warehouse mongodb server
  97. db_config = LaunchConfiguration("db")
  98. mongodb_server_node = Node(
  99. package="warehouse_ros_mongo",
  100. executable="mongo_wrapper_ros.py",
  101. parameters=[
  102. {"warehouse_port": 33829},
  103. {"warehouse_host": "localhost"},
  104. {"warehouse_plugin": "warehouse_ros_mongo::MongoDatabaseConnection"},
  105. ],
  106. output="screen",
  107. condition=IfCondition(db_config),
  108. )
  109. return LaunchDescription(
  110. [
  111. db_arg,
  112. rviz_node,
  113. static_tf,
  114. robot_state_publisher,
  115. run_move_group_node,
  116. ros2_control_node,
  117. mongodb_server_node,
  118. joint_state_broadcaster_spawner,
  119. xxx_xx_controller_spawner,
  120. ]
  121. )

xxx的地方根据自己的文件名进行替换,.urdf.xacro、.srdf、_moveit_config的地方都替换自己的文件名。

xxx_xx的是在创建moveit_setup_assistant配置机械臂包的时候自己填写的Group Name。

一共有8个地方需要改。

改完以后,编译,再source一下,应该就可以运行demo.launch.py了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/979151
推荐阅读
相关标签
  

闽ICP备14008679号