当前位置:网站首页>[Advanced ROS] Lecture 11 Robot co-simulation based on Gazebo and Rviz (motion control and sensors)
[Advanced ROS] Lecture 11 Robot co-simulation based on Gazebo and Rviz (motion control and sensors)
2022-07-30 13:55:00 【Born as Zhaoxu】
【ROS进阶篇】基于Gazebo和Rvizrobot co-simulation(Motion Control and Sensors)

文章目录
前言
In the previous blog, we systematically learned how to useGazebo对使用URDFFile the completed robot model for integrated simulation,Starting from the basic simulation process,Specific robot examples are given in the follow-up,and attached at the end usingGazeboTutorial for Creating a Simulation Environment,This section mainly focuses on使用URDF、Gazebo、Rviz进行联合仿真,URDF 用于创建机器人模型、Rviz 可以显示机器人感知到的环境信息,Gazebo 用于仿真,可以模拟外界环境,and robotic sensors,,This section focuses more on usingGazebo模拟传感器数据,并在RvizComplete display and analysis in.
一、机器人运动控制(ros_control)
1. 组件介绍
- 引入原因:在RVIZ中,我们通过ArbotixAuxiliary realized based onURDFFile the motion control of the robot model,而在Gazebo仿真中,Although we have established a specific simulation environment,But want to really control the robot movement,A key component package is also required.

应用场景:同样的ROSProgram deployment on different actual concrete robot systems.

介绍:ROS_CONTROL,是一组软件包,包含控制器、管理器、硬件、interface for transmission,Essentially a control middleware,提供了一套规范,除了这些,ros_controlAlso provides a hardware abstraction layer,Responsible for hardware resource management,controllerJust request resources from the abstraction layer.

- Function introduction of each data flow layer:
- Controller Manager:
Each robot may have multiplecontroller,So here is the concept of a controller manager,Provides a common interface to manage differentcontroller.controller manager的输入就是ROSThe output of the upper application.- Controller:
完成每个joint的控制,Request the underlying hardware resources,提供了PID控制器,读取硬件资源接口中的状态,issuing control commands.- Hardware Rescource:
An interface that provides hardware resources for the upper and lower layers.- RobotHW:
The hardware abstraction layer deals directly with the hardware,通过write和readmethod to complete the operation of the hardware,This layer also contains joint limits、torque conversion、State transition and other functions.- Real Robot:
The actual robot also needs its own embedded controller,After receiving the command, it needs to be reflected on the actuator,such as receiving the location1的命令后,Then you need to make the actuator fast、stable arrival position1.
- 特点:For different robotic platforms,ros_controlProvides a standard canonical interface architecture,Improved program compatibility、Efficiency and flexible portability,使用时直接调用gazebo中的相关接口即可.
2. Motion Control Implementation
- 基本流程:
- 创建机器人模型;
- 编写一个单独的xacro文件,添加传动装置及控制器,and integrated together;
- 启动Gazebo发布/cmd_velmessage control movement
- basic robotURDF文件略,传动、The control file example below:
<robot name="my_car_move" xmlns:xacro="http://wiki.ros.org/xacro">
<!-- 传动实现:用于连接控制器与关节 -->
<xacro:macro name="joint_trans" params="joint_name">
<!-- Transmission is important to link the joints and the controller -->
<transmission name="${joint_name}_trans">
<type>transmission_interface/SimpleTransmission</type>
<joint name="${joint_name}">
<hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
</joint>
<actuator name="${joint_name}_motor">
<hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
<mechanicalReduction>1</mechanicalReduction>
</actuator>
</transmission>
</xacro:macro>
<!-- 每一个驱动轮都需要配置传动装置 -->
<xacro:joint_trans joint_name="left_wheel2base_link" />
<xacro:joint_trans joint_name="right_wheel2base_link" />
<!-- 控制器 -->
<gazebo>
<plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so">
<rosDebugLevel>Debug</rosDebugLevel>
<publishWheelTF>true</publishWheelTF>
<robotNamespace>/</robotNamespace>
<publishTf>1</publishTf>
<publishWheelJointState>true</publishWheelJointState>
<alwaysOn>true</alwaysOn>
<updateRate>100.0</updateRate>
<legacyMode>true</legacyMode>
<leftJoint>left_wheel2base_link</leftJoint> <!-- 左轮 -->
<rightJoint>right_wheel2base_link</rightJoint> <!-- 右轮 -->
<wheelSeparation>${base_link_radius * 2}</wheelSeparation> <!-- 车轮间距 -->
<wheelDiameter>${wheel_radius * 2}</wheelDiameter> <!-- 车轮直径 -->
<broadcastTF>1</broadcastTF>
<wheelTorque>30</wheelTorque>
<wheelAcceleration>1.8</wheelAcceleration>
<commandTopic>cmd_vel</commandTopic> <!-- 运动控制话题 -->
<odometryFrame>odom</odometryFrame>
<odometryTopic>odom</odometryTopic> <!-- 里程计话题 -->
<robotBaseFrame>base_footprint</robotBaseFrame> <!-- 根坐标系 -->
</plugin>
</gazebo>
</robot>
- 集成xacro文件:
<!-- 组合小车底盘与摄像头 -->
<robot name="my_car_camera" xmlns:xacro="http://wiki.ros.org/xacro">
<xacro:include filename="my_head.urdf.xacro" />
<xacro:include filename="my_base.urdf.xacro" />
<xacro:include filename="my_camera.urdf.xacro" />
<xacro:include filename="my_laser.urdf.xacro" />
<xacro:include filename="move.urdf.xacro" />
</robot>
- 启动launch文件:
<launch>
<!-- 将 Urdf 文件的内容加载到参数服务器 -->
<param name="robot_description" command="$(find xacro)/xacro $(find demo02_urdf_gazebo)/urdf/xacro/my_base_camera_laser.urdf.xacro" />
<!-- 启动 gazebo -->
<include file="$(find gazebo_ros)/launch/empty_world.launch">
<arg name="world_name" value="$(find demo02_urdf_gazebo)/worlds/hello.world" />
</include>
<!-- 在 gazebo 中显示机器人模型 -->
<node pkg="gazebo_ros" type="spawn_model" name="model" args="-urdf -model mycar -param robot_description" />
</launch>
- 控制机器人运动:命令行控制/Writing Node Controls:

二、Sensor information simulation and display
1. 里程计信息
里程计信息:The pose state of the robot relative to the starting point coordinate system(Position Coordinates and Movement Orientation)
操作流程:
- Start with a startup fileRviz,Open state publishing node:
<launch> <!-- 启动 rviz --> <node pkg="rviz" type="rviz" name="rviz" /> <!-- 关节以及机器人状态发布节点 --> <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" /> <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" /> </launch>
- 在Rviz中添加组件:
2. 雷达信息
- 2.1 编写xacro文件,Add radar sensor information
<robot name="my_sensors" xmlns:xacro="http://wiki.ros.org/xacro">
<!-- 雷达 -->
<gazebo reference="laser">
<sensor type="ray" name="rplidar">
<pose>0 0 0 0 0 0</pose>
<visualize>true</visualize>
<update_rate>5.5</update_rate>
<ray>
<scan>
<horizontal>
<samples>360</samples>
<resolution>1</resolution>
<min_angle>-3</min_angle>
<max_angle>3</max_angle>
</horizontal>
</scan>
<range>
<min>0.10</min>
<max>30.0</max>
<resolution>0.01</resolution>
</range>
<noise>
<type>gaussian</type>
<mean>0.0</mean>
<stddev>0.01</stddev>
</noise>
</ray>
<plugin name="gazebo_rplidar" filename="libgazebo_ros_laser.so">
<topicName>/scan</topicName>
<frameName>laser</frameName>
</plugin>
</sensor>
</gazebo>
</robot>
- 2.2 Integrate files into robot models:
<!-- Combined trolley chassis and sensors -->
<robot name="my_car_camera" xmlns:xacro="http://wiki.ros.org/xacro">
<xacro:include filename="my_head.urdf.xacro" />
<xacro:include filename="my_base.urdf.xacro" />
<xacro:include filename="my_camera.urdf.xacro" />
<xacro:include filename="my_laser.urdf.xacro" />
<xacro:include filename="move.urdf.xacro" />
<!-- radar simulation xacro 文件 -->
<xacro:include filename="my_sensors_laser.urdf.xacro" />
</robot>
- 2.3 启动gazebo,启动rviz,Add radar information display plugin:

3. 摄像头信息
- 3.1 Configure the camera sensor
<robot name="my_sensors" xmlns:xacro="http://wiki.ros.org/xacro">
<!-- 被引用的link -->
<gazebo reference="camera">
<!-- 类型设置为 camara -->
<sensor type="camera" name="camera_node">
<update_rate>30.0</update_rate> <!-- 更新频率 -->
<!-- 摄像头基本信息设置 -->
<camera name="head">
<horizontal_fov>1.3962634</horizontal_fov>
<image>
<width>1280</width>
<height>720</height>
<format>R8G8B8</format>
</image>
<clip>
<near>0.02</near>
<far>300</far>
</clip>
<noise>
<type>gaussian</type>
<mean>0.0</mean>
<stddev>0.007</stddev>
</noise>
</camera>
<!-- 核心插件 -->
<plugin name="gazebo_camera" filename="libgazebo_ros_camera.so">
<alwaysOn>true</alwaysOn>
<updateRate>0.0</updateRate>
<cameraName>/camera</cameraName>
<imageTopicName>image_raw</imageTopicName>
<cameraInfoTopicName>camera_info</cameraInfoTopicName>
<frameName>camera</frameName>
<hackBaseline>0.07</hackBaseline>
<distortionK1>0.0</distortionK1>
<distortionK2>0.0</distortionK2>
<distortionK3>0.0</distortionK3>
<distortionT1>0.0</distortionT1>
<distortionT2>0.0</distortionT2>
</plugin>
</sensor>
</gazebo>
</robot>
- 3.2 Integrated Robot Model,Similar to the first two sensors,略
- 3.3 启动仿真环境gazebo,启动rviz显示数据,添加组件:

4. kinect摄像头信息
- 4.1 配置kinect传感器:
<robot name="my_sensors" xmlns:xacro="http://wiki.ros.org/xacro">
<gazebo reference="kinect link名称">
<sensor type="depth" name="camera">
<always_on>true</always_on>
<update_rate>20.0</update_rate>
<camera>
<horizontal_fov>${60.0*PI/180.0}</horizontal_fov>
<image>
<format>R8G8B8</format>
<width>640</width>
<height>480</height>
</image>
<clip>
<near>0.05</near>
<far>8.0</far>
</clip>
</camera>
<plugin name="kinect_camera_controller" filename="libgazebo_ros_openni_kinect.so">
<cameraName>camera</cameraName>
<alwaysOn>true</alwaysOn>
<updateRate>10</updateRate>
<imageTopicName>rgb/image_raw</imageTopicName>
<depthImageTopicName>depth/image_raw</depthImageTopicName>
<pointCloudTopicName>depth/points</pointCloudTopicName>
<cameraInfoTopicName>rgb/camera_info</cameraInfoTopicName>
<depthImageCameraInfoTopicName>depth/camera_info</depthImageCameraInfoTopicName>
<frameName>kinect link名称</frameName>
<baseline>0.1</baseline>
<distortion_k1>0.0</distortion_k1>
<distortion_k2>0.0</distortion_k2>
<distortion_k3>0.0</distortion_k3>
<distortion_t1>0.0</distortion_t1>
<distortion_t2>0.0</distortion_t2>
<pointCloudCutoff>0.4</pointCloudCutoff>
</plugin>
</sensor>
</gazebo>
</robot>
- 4.2 Integrated Robot Model,Similar to the previous sensor,略
- 4.3 启动仿真环境gazebo,启动rviz显示数据,添加组件:

总结
- 声明:本节博客部分参考了CSDN用户赵虚左的ROS教程,本文主要内容是使用URDFfile to build the robot model,并通过Gazebo创建仿真环境,Analog sensor using,在RVIZDone for the sensor data visualization analysis and processing,In the second half of the analysis, we found that,对于传感器(里程计、雷达、摄像头)分析来说,都是从xacro文件出发,添加相应配置,Integrate into robot model file,Finally, start each simulation component to modify the configuration to complete the co-simulation,Each simulation component,complete the corresponding effect.
- 至此,ROSThe advanced part of the tutorial is over,对于ROSThe content of the part mainly includes the content of the navigation part, which will be supplemented in the future.,针对于GazeboThe usage tutorial will also have a separate column,敬请期待.
边栏推荐
- R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化分组箱图、使用ggpar函数改变图形化参数(xlab、ylab、改变可视化图像的坐标轴标签内容)
- 简单理解精确率(Precision),召回率(Recall),准确率(Accuracy),TP,TN,FP,FN
- 一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
- LeetCode二叉树系列——102.二叉树的层序遍历
- 12、 学习MySQL 排序
- SQL 改写系列七:谓词移动
- CF1320E Treeland and Viruses
- 二手手机销量突破3亿部,与降价的iPhone夹击国产手机
- 【软考软件评测师】基于规则说明的测试技术上篇
- 判断链表是否有环
猜你喜欢

程序员修炼之道:务以己任,实则明心——通向务实的最高境界

The way of programmers' cultivation: do one's own responsibilities, be clear in reality - lead to the highest realm of pragmatism

自从外包干了四年,基本废了...

svg波浪动画js特效代码

树形dp小总结(换根,基环树,杂七杂八的dp)

LeetCode二叉树系列——145.二叉树的后序遍历

PyQt5快速开发与实战 8.6 设置样式

BUUCTF刷题十一道(06)

Raja Koduri澄清Arc GPU跳票传闻 AXG年底前新推四条产品线
SQL 26 calculation under 25 years of age or older and the number of users
随机推荐
R语言ggpubr包的ggboxplot函数可视化分组箱图、自定义移除可视化图像的特定对象(移除可视化图像轴坐标轴的刻度线标签文本、both x and y axis ticks labels)
SQL 26 calculation under 25 years of age or older and the number of users
C语言学习练习题:汉诺塔(函数与递归)
R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化分组箱图、使用ggpar函数改变图形化参数(xlab、ylab、改变可视化图像的坐标轴标签内容)
Eleven BUUCTF questions (06)
js男女身高体重关系图
CF1677E Tokitsukaze and Beautiful Subsegments
VLAN实验
LeetCode二叉树系列——107.二叉树的层序遍历II
树形dp小总结(换根,基环树,杂七杂八的dp)
CMake库搜索函数居然不搜索LD_LIBRARY_PATH
重保特辑|筑牢第一道防线,云防火墙攻防演练最佳实践
Current and voltage acquisition module DAM-6160
外包干了七年,废了。。。
Self-tuning PID self-tuning control 】 【
R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化分组箱图、使用ggpar函数改变图形化参数(ylim、修改可视化图像y轴坐标轴数值范围)
CF780G Andryusha and Nervous Barriers
[C# 循环跳转]-C# 中的 while/do-while/for/foreach 循环结构以及 break/continue 跳转语句
AT4108 [ARC094D] Normalization
[PostgreSQL] - explain SQL analysis introduction
