当前位置:   article > 正文

moveit与gazebo联合仿真_moveit和gazebo联合仿真

moveit和gazebo联合仿真

准备工作:

1.moveit_config已经配置好,各种插件以及软件包装全。

2.创建myrobot_gazebo功能包,需要的依赖为:gazebo_msgs gazebo_plugins gazebo_ros gazebo_ros_control

3.应用下列步骤时将ROBOT改为自己机器人的名字(写文时我是将我的机器人robot改为ROBOT,可能会有疏忽没改过来的)ps:不建议把自己的机器人命名为和robot有关字样,太容易混淆。

1.myrobot_gazebo/launch/ROBOT_world.launch用于将urdf文件在gazebo中显示:

  1. <launch>
  2. <!-- these are the arguments you can pass this launch file, for example paused:=true -->
  3. <arg name="paused" default="false"/>
  4. <arg name="use_sim_time" default="true"/>
  5. <arg name="gui" default="true"/>
  6. <arg name="headless" default="false"/>
  7. <arg name="debug" default="false"/>
  8. <!-- We resume the logic in empty_world.launch -->
  9. <include file="$(find gazebo_ros)/launch/empty_world.launch">
  10. <arg name="debug" value="$(arg debug)" />
  11. <arg name="gui" value="$(arg gui)" />
  12. <arg name="paused" value="$(arg paused)"/>
  13. <arg name="use_sim_time" value="$(arg use_sim_time)"/>
  14. <arg name="headless" value="$(arg headless)"/>
  15. </include>
  16. <!-- Load the URDF into the ROS Parameter Server -->
  17. <param name="robot_description" textfile="$(find ROBOT_package)/urdf/ROBOT.urdf" />
  18. <!-- Run a python script to the send a service call to gazebo_ros to spawn a URDF robot -->
  19. <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
  20. args="-urdf -model ROBOT -param robot_description"/>
  21. </launch>

2.关节状态控制器为可选插件,主要用于发布机器人关节状态和tf状态,否则在rviz的fixed frame的下拉列表中看不到坐标系选项,只能手动输入。

2.1 launch文件:myrobot_gazebo/launch/ROBOT_gazebo_states.launch

  1. <launch>
  2. <!-- 将关节控制器的配置参数加载到参数服务器中 -->
  3. <rosparam file="$(find myrobot_gazebo)/config/ROBOT_gazebo_joint_states.yaml" command="load"/>
  4. <node name="joint_controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
  5. output="screen" ns="/ROBOT" args="joint_state_controller" />
  6. <!-- 运行robot_state_publisher节点,发布tf -->
  7. <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"
  8. respawn="false" output="screen">
  9. <remap from="/joint_states" to="/ROBOT/joint_states" />
  10. </node>
  11. </launch>

2.2launch中的yaml文件:myrobot_gazebo/config/ROBOT_gazebo_joint_states.yaml

  1. ROBOT:
  2. # Publish all joint states -----------------------------------
  3. joint_state_controller:
  4. type: joint_state_controller/JointStateController
  5. publish_rate: 50

3.关节轨迹控制器

3.1launch文件:myrobot_gazebo/launch/ROBOT_trajectory_controller.launch

  1. <launch>
  2. <rosparam file="$(find myrobot_gazebo)/config/trajectory_control.yaml" command="load"/>
  3. <node name="robot_controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
  4. output="screen" ns="/ROBOT" args="ROBOT_joint_controller ROBOT_gripper_controller "/>
  5. </launch>

3.2launch中的yaml文件:

myrobot_gazebo/config/trajectory_control.yaml

  1. ROBOT:
  2. ROBOT_joint_controller:
  3. type: "position_controllers/JointTrajectoryController"
  4. joints:
  5. - j1
  6. - j2
  7. - j3
  8. - j4
  9. - j5
  10. - j6
  11. gains:
  12. j1: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
  13. j2: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
  14. j3: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
  15. j4: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
  16. j5: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
  17. j6: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
  18. #需要末端执行器的在后面添加
  19. ROBOT_gripper_controller:
  20. type: "position_controllers/JointTrajectoryController"
  21. joints:
  22. - finger_j1
  23. - finger_j2
  24. gains:
  25. finger_j1: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
  26. finger_j2: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}

4.moveit控制器的启动文件:myrobot_moveit_config)/launch/moveit_planning_execution.launch

  1. <launch>
  2. # The planning and execution components of MoveIt! configured to
  3. # publish the current configuration of the robot (simulated or real)
  4. # and the current state of the world as seen by the planner
  5. <include file="$(find myrobot_moveit_config)/launch/move_group.launch">
  6. <arg name="publish_monitored_planning_scene" value="true" />
  7. </include>
  8. # The visualization component of MoveIt!
  9. <include file="$(find myrobot_moveit_config)/launch/moveit_rviz.launch"/>
  10. <!-- We do not have a robot connected, so publish fake joint states -->
  11. <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher">
  12. <param name="/use_gui" value="false"/>
  13. <rosparam param="/source_list">[/ROBOT/joint_states]</rosparam>
  14. </node>
  15. </launch>

4.1配置一:添加文件myrobot_moveit_config/config/controllers_gazebo.yaml

  1. controller_manager_ns: controller_manager
  2. controller_list:
  3. - name: ROBOT/ROBOT_joint_controller
  4. action_ns: follow_joint_trajectory
  5. type: FollowJointTrajectory
  6. default: true
  7. joints:
  8. - j1
  9. - j2
  10. - j3
  11. - j4
  12. - j5
  13. - j6
  14. - name: ROBOT/ROBOT_gripper_controller
  15. action_ns: follow_joint_trajectory
  16. type: FollowJointTrajectory
  17. default: true
  18. joints:
  19. - finger_j1
  20. - finger_j2

4.2配置二:更改myrobot_moveit_config/launch/robot_moveit_controller_manager.launch.xml

  1. <launch>
  2. <!-- loads moveit_controller_manager on the parameter server which is taken as argument
  3. if no argument is passed, moveit_simple_controller_manager will be set -->
  4. <arg name="moveit_controller_manager" default="moveit_simple_controller_manager/MoveItSimpleControllerManager" />
  5. <param name="moveit_controller_manager" value="$(arg moveit_controller_manager)"/>
  6. <!-- loads ros_controllers to the param server -->
  7. <rosparam file="$(find myrobot_moveit_config)/config/controllers_gazebo.yaml"/>
  8. </launch>

将读取到参数服务器中的控制文件改为controllers_gazebo.yaml

5.将上述四个launch集成:myrobot_gazebo/launch/robot_bringup_moveit.launch

  1. <launch>
  2. <!-- Launch Gazebo -->
  3. <include file="$(find myrobot_gazebo)/launch/robot_world.launch" />
  4. <!-- ros_control arm launch file -->
  5. <include file="$(find myrobot_gazebo)/launch/robot_gazebo_states.launch" />
  6. <!-- ros_control trajectory control dof arm launch file -->
  7. <include file="$(find myrobot_gazebo)/launch/robot_trajectory_controller.launch" />
  8. <!-- moveit launch file -->
  9. <include file="$(find myrobot_moveit_config)/launch/moveit_planning_execution.launch" />
  10. </launch>

踩坑:

1.Unable to connect to move_group action server 'move_group' within allotted time (30s)

 解决:在rviz里面点击reset

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/818777
推荐阅读
相关标签
  

闽ICP备14008679号