Moveit+Gazebo联合仿真
ROS下利用moveit+gazebo搭建机器人仿真环境
一 准备工作
solidworks建模导出urdf功能包
转化为xacro文件 将urdf文件转为xacro文件
生成robot_moveit_config功能包
补充:
功能包命名规范(XXX是机器人名字)
模型文件功能包:XXX_discription
moveit功能包:XXX_moveit_config
gazebo功能包:XXX_gazebo
二 配置文件
涉及到的文件
XXX_moveit_config:
config:
| controllers_gazebo.yaml
launch:
| XXX_moveit_controller_manager.launch.xml
| moveit_planning_execution.launch
XXX_gazebo:
config:
| XXX_gazebo_joint_states.yaml
| trajectory_control.yaml
launch
| XXX_world.launch
| XXX_gazebo_states.launch
| XXX_trajectory_controller.launch
| robot_bringup_moveit.launch
三、具体步骤
以下涉及代码可直接复制,并将¨bot¨改为自己机器人的名字。(我为了方便命名为¨bot¨)
1.moveit控制器部分:
XXX_moveit_config/launch:
moveit_planning_execution.launch
<launch>
# The planning and execution components of MoveIt! configured to
# publish the current configuration of the robot (simulated or real)
# and the current state of the world as seen by the planner
<include file="$(find bot_moveit_config)/launch/move_group.launch">
<arg name="publish_monitored_planning_scene" value="true" />
</include>
# The visualization component of MoveIt!
<include file="$(find bot_moveit_config)/launch/moveit_rviz.launch"/>
<!-- We do not have a robot connected, so publish fake joint states -->
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher">
<param name="/use_gui" value="false"/>
<rosparam param="/source_list">[/bot/joint_states]</rosparam>
</node>
</launch>
XXX_moveit_controller_manager.launch.xml
<launch>
<!-- loads moveit_controller_manager on the parameter server which is taken as argument
if no argument is passed, moveit_simple_controller_manager will be set -->
<arg name="moveit_controller_manager" default="moveit_simple_controller_manager/MoveItSimpleControllerManager" />
<param name="moveit_controller_manager" value="$(arg moveit_controller_manager)"/>
<!-- loads ros_controllers to the param server -->
<rosparam file="$(find bot_moveit_config)/config/controllers_gazebo.yaml"/>
</launch>
XXX_moveit_config/config
controllers_gazebo.yaml
controller_manager_ns: controller_manager
controller_list:
- name: bot/bot_joint_controller
action_ns: follow_joint_trajectory
type: FollowJointTrajectory
default: true
joints:
- joint1
- joint2
- joint3
- joint4
- joint5
2.gazebo部分
需要新建XXX_gazebo功能包,需要的依赖:gazebo_msgs gazebo_plugins gazebo_ros gazebo_ros_control
XXX_gazebo/launch:
XXX_world.launch
<launch>
<!-- these are the arguments you can pass this launch file, for example paused:=true -->
<arg name="paused" default="false"/>
<arg name="use_sim_time" default="true"/>
<arg name="gui" default="true"/>
<arg name="headless" default="false"/>
<arg name="debug" default="false"/>
<!-- We resume the logic in empty_world.launch -->
<include file="$(find gazebo_ros)/launch/empty_world.launch">
<arg name="debug" value="$(arg debug)" />
<arg name="gui" value="$(arg gui)" />
<arg name="paused" value="$(arg paused)"/>
<arg name="use_sim_time" value="$(arg use_sim_time)"/>
<arg name="headless" value="$(arg headless)"/>
</include>
<!-- Load the URDF into the ROS Parameter Server -->
<param name="robot_description" command="$(find xacro)/xacro --inorder '$(find bot_description)/urdf/bot.xacro'" />
<!-- Run a python script to the send a service call to gazebo_ros to spawn a URDF robot -->
<node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
args="-urdf -model bot -param robot_description"/>
</launch>
XXX_gazebo_states.launch
<launch>
<!-- 将关节控制器的配置参数加载到参数服务器中 -->
<rosparam file="$(find bot_gazebo)/config/bot_gazebo_joint_states.yaml" command="load"/>
<node name="joint_controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
output="screen" ns="/bot" args="joint_state_controller" />
<!-- 运行robot_state_publisher节点,发布tf -->
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"
respawn="false" output="screen">
<remap from="/joint_states" to="/bot/joint_states" />
</node>
</launch>
XXX_trajectory_controller.launch
<launch>
<rosparam file="$(find bot_gazebo)/config/trajectory_control.yaml" command="load"/>
<node name="robot_controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
output="screen" ns="/bot" args="bot_joint_controller bot_gripper_controller "/>
</launch>
robot_bringup_moveit.launch
<launch>
<!-- Launch Gazebo -->
<include file="$(find bot_gazebo)/launch/bot_world.launch" />
<!-- ros_control arm launch file -->
<include file="$(find bot_gazebo)/launch/bot_gazebo_states.launch" />
<!-- ros_control trajectory control dof arm launch file -->
<include file="$(find bot_gazebo)/launch/bot_trajectory_controller.launch" />
<!-- moveit launch file -->
<include file="$(find bot_moveit_config)/launch/moveit_planning_execution.launch" />
</launch>
XXX_gazebo/config:
trajectory_control.yaml
bot:
bot_joint_controller:
type: "position_controllers/JointTrajectoryController"
joints:
- joint1
- joint2
- joint3
- joint4
- joint5
gains:
joint1: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
joint2: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
joint3: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
joint4: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
joint5: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
XXX_gazebo_joint_states.yaml
bot:
# Publish all joint states -----------------------------------
joint_state_controller:
type: joint_state_controller/JointStateController
publish_rate: 50
至此配置全部完成,终端运行 roslaunch XXX_gazebo robot_bringup_moveit.launch 测试
四、常见问题
- 启动gazebo一些模型爆出Failed to load joint1_position_controller 错误,可以尝试安装control以及controllers
sudo apt-get update
sudo apt-get install ros-noetic-ros-control
sudo apt-get install ros-noetic-ros-controllers
-
[ERROR] : Unable to identify any set of controllers that can actuate the specified joints: [ joint1 joint2 joint3 joint4 joint5 joint6 ]
[ERROR] : Known controllers and their joints:
解决方法:工作空间/src/marm_moveit_config/launch/trajectory_execution.launch.xml
将参数pass_all_args="true"删掉即可。 -
其他问题(目前没有遇到)
MOVEIT!控制GAZEBO仿真机械臂时遇到的一些问题
五、参考文章
以下两篇为主要参考
参考一ROS机械臂开发:MoveIt! + Gazebo仿真
参考二多指灵巧手MoveIt!与Gazebo联合仿真框架搭建
更多推荐
所有评论(0)