ROS 学习笔记 (一)—rviz gazebo
描述:本例程基于古月居的博客:https://www.guyuehome.com/1159 和开源的大族机器人的elfin_description。
工具准备:默认安装ros-noetic Visual Studio Code
一、运行 display
node 节点的类型修改为:robot_state_publisher
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" />
roslaunch elfin_description display.launch
配置moveit 助手
1、启动 ros 并启动 moveit 助手
一个终端
roscore
另一个终端
rosrun moveit_setup_assistant moveit_setup_assistant
具体配置过程详见其他教程。(记得安装一些必要的ros 功能包)效果展示
roslaunch elfin_probot_gazebo probot_elfin_bringup_moveit.launch
具体配置过程–参照古月居anno机器人配置代码代码
如果使用rviz 和 gazebo 需要添加几个文件:
elfin_moveit_config中配置:
controllers_gazebo.yaml 用来配置控制器
moveit_planning_execution.launch 用来启动
controllers_gazebo.yaml
controller_manager_ns: controller_manager
controller_list:
- name: probot_elfin/arm_joint_controller #命名空间/名称
action_ns: follow_joint_trajectory
type: FollowJointTrajectory
default: true
joints:
- elfin_joint1 #六个关节的名称
- elfin_joint2
- elfin_joint3
- elfin_joint4
- elfin_joint5
- elfin_joint6
moveit_planning_execution.launch
<?xml version="1.0"?>
<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 elfin_moveit_config_lhl)/launch/move_group.launch">
<arg name="publish_monitored_planning_scene" value="true" />
</include>
# The visualization component of MoveIt!
<include file="$(find elfin_moveit_config_lhl)/launch/moveit_rviz.launch">
<arg name="config" value="true" />
<arg name="debug" value="false"/>
</include>
<!-- 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"/>
<!--source_list 为命名空间的名字 启动ros节点发布 joint_states-->
<rosparam param="/source_list">[/probot_elfin/joint_states]</rosparam>
</node>
<!--arm_joint_controller-->
</launch>
elfin_probot_gazebo 配置
新建文件夹 config
probot_elfin_gazebo_joint_states.yaml 文件
probot_elfin: #命名空间
joint_state_controller: #控制器
type: joint_state_controller/JointStateController
publish_rate: 50 #发布频率
probot_elfin_trajectory_control.yaml 文件
probot_elfin: #命名空间
arm_joint_controller: #controllers_gazebo.yaml 中的名称
type: "position_controllers/JointTrajectoryController"
joints:
- elfin_joint1 #六个关机名称
- elfin_joint2
- elfin_joint3
- elfin_joint4
- elfin_joint5
- elfin_joint6
gains:
elfin_joint1: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
elfin_joint2: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
elfin_joint3: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
elfin_joint4: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
elfin_joint5: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
elfin_joint6: {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
新建文件夹 launch
probot_elfin_bringup_moveit.launch 启动所以文件
<?xml version="1.0"?>
<launch>
<!--打开gazebo仿真环境-->
<include file="$(find elfin_probot_gazebo)/launch/probot_elfin_gazebo_world.launch"/>
<!--机械臂控制文件-->
<include file="$(find elfin_probot_gazebo)/launch/probot_elfin_gazebo_states.launch"/>
<!--ros_control trajectory control dof arm launch file-->
<include file="$(find elfin_probot_gazebo)/launch/probot_elfin_trajectory_controller.launch"/>
<!-- moveit launch file -->
<include file="$(find elfin_moveit_config_lhl)/launch/moveit_planning_execution.launch"/>
</launch>
probot_elfin_gazebo_world.launch 启动gazebo环境
<!-- 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 elfin_description)/urdf/elfin3.urdf.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 probot_elfin -param robot_description"/>
<node name="fake_joint_calibration" pkg="rostopic" type="rostopic" args ="pub /calibrate std_msgs/Bool true" >
</node>
</launch>
probot_elfin_gazebo_states.launch
<?xml version="1.0"?>
<launch>
<!--将关节控制器参数加载到服务器中-->
<rosparam command="load" file="$(find elfin_probot_gazebo)/config/probot_elfin_gazebo_joint_states.yaml"/>
<node name="joint_controller_spawner" pkg="controller_manager" type="spawner" output="screen" ns="/probot_elfin" args="joint_state_controller"/>
<!--运行robot_state_publisher节点,发布tf-->
<!--probot_elfin 命名空间-->
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" output="screen" respawn="false" >
<remap from="/joint_states" to="/probot_elfin/joint_states"/>
</node>
</launch>
probot_elfin_trajectory_controller.launch
<?xml version="1.0"?>
<launch>
<rosparam command="load" file="$(find elfin_probot_gazebo)/config/probot_elfin_trajectory_control.yaml"/>
<!--probot_elfin 命名空间-->
<node name="arm_controller_spawner" pkg="controller_manager" type="spawner" output="screen" ns="/probot_elfin" args="arm_joint_controller"/>
</launch>
对urdf 文件进行修改
<!-- ros_control plugin -->
<gazebo>
<plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
<!--添加命名空间-->
<robotNamespace>/probot_elfin</robotNamespace>
</plugin>
</gazebo>
可以了:
文件链接:在我的gazebo配置压缩包中,不希望被下载。
https://download.csdn.net/download/qq_40569926/13909861
压缩包中:
probot_elfin_gazebo_joint_states.yaml 文件 的 joint_state_controller: #控制器写错了。改一下错误就没有了