当前位置:网站首页>[advanced ROS chapter] Lecture 10 gadf integrated simulation process and examples based on gazebo
[advanced ROS chapter] Lecture 10 gadf integrated simulation process and examples based on gazebo
2022-07-28 02:22:00 【Life is like Zhaoxu】
【ROS Advanced 】 Lecture 10 be based on Gazebo Of URDF Integrated simulation process and examples

List of articles
Preface
In the last blog section, we systematically learned how to RVIZ Use in Arbotix Implement for using URDF Motion control of robot model generated by file , The specific simulation process is explained through a simple motion example , This section mainly focuses on How to be in Gazebo In the integration URDF The robot model corresponding to the file , Lay a foundation for future joint simulation , I also have a preliminary understanding Gazebo How to use simulation software .
\qquad
One 、URDF And Gazebo Basic integration process
1. Basic process introduction
First step , Create Feature Pack :
\qquad Dependencies :urdf、xacro、gazebo_ros、gazebo_ros_control、gazebo_plugins etc.
The second step , To write URDF File build robot model :
<!-- Create a robot model ( Just box ), Displayed in the Gazebo in -->
<robot name="mycar">
<link name="base_link">
<visual>
<geometry>
<box size="0.5 0.2 0.1" />
</geometry>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
<material name="yellow">
<color rgba="0.5 0.3 0.0 1" />
</material>
</visual>
<collision>
<geometry>
<box size="0.5 0.2 0.1" />
</geometry>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
</collision>
<inertial>
<origin xyz="0 0 0" />
<mass value="6" />
<inertia ixx="1" ixy="0" ixz="0" iyy="1" iyz="0" izz="1" />
</inertial>
</link>
<gazebo reference="base_link">
<material>Gazebo/Black</material>
</gazebo>
</robot>
Be careful : Here, URDF The document has key requirements , The use of labels exists with Rviz Additional requirements beyond , It is detailed in the relevant settings of integration ;
The third step , start-up Gazebo And display the model :launch Documentation
<launch>
<!-- take Urdf The contents of the file are loaded into the parameter server -->
<param name="robot_description" textfile="$(find demo02_urdf_gazebo)/urdf/urdf01_helloworld.urdf" />
<!-- start-up gazebo -->
<include file="$(find gazebo_ros)/launch/empty_world.launch" />
<!-- stay gazebo The robot model is displayed in -->
<node pkg="gazebo_ros" type="spawn_model" name="model" args="-urdf -model mycar -param robot_description" />
<!-- stay Gazebo Load a robot model in , The function consists of gazebo_ros Under the spawn_model Provide : -urdf Load is urdf file -model mycar The model name is mycar -param robot_description From parameter robot_description Load model in -x Model loaded x coordinate -y Model loaded y coordinate -z Model loaded z coordinate -->
</launch>
2. Integration related settings
The first one is , You must add collision label
- reason : about Gazebo For simulation , First, we need to realize the complete simulation of the environment , It must involve collision detection , You need to add collision Provide evidence ;
\qquad Be a robot link When it belongs to standard geometry , Collision settings and link Of visual The properties are consistent ;
The second item , You must add inertial label
reason : This label indicates the inertia matrix of a rigid part of the current robot , Used for some mechanics related simulation calculation , except base_footprint Outside , Each rigid body part of the robot needs to set up an inertia matrix , And this matrix must be accurately obtained , Otherwise, jitter and other phenomena will occur ;
Setup method : combination link Dynamic generation of quality and shape parameters , Examples of standard matrices are as follows :
- Sphere inertia matrix
<!-- Macro for inertia matrix --> <xacro:macro name="sphere_inertial_matrix" params="m r"> <inertial> <mass value="${m}" /> <inertia ixx="${2*m*r*r/5}" ixy="0" ixz="0" iyy="${2*m*r*r/5}" iyz="0" izz="${2*m*r*r/5}" /> </inertial> </xacro:macro>
- Cylindrical inertia matrix
<xacro:macro name="cylinder_inertial_matrix" params="m r h"> <inertial> <mass value="${m}" /> <inertia ixx="${m*(3*r*r+h*h)/12}" ixy = "0" ixz = "0" iyy="${m*(3*r*r+h*h)/12}" iyz = "0" izz="${m*r*r/2}" /> </inertial> </xacro:macro>
- Cubic inertia matrix
<xacro:macro name="Box_inertial_matrix" params="m l w h"> <inertial> <mass value="${m}" /> <inertia ixx="${m*(h*h + l*l)/12}" ixy = "0" ixz = "0" iyy="${m*(w*w + l*l)/12}" iyz= "0" izz="${m*(w*w + h*h)/12}" /> </inertial> </xacro:macro>
The third one , Use gazebo Color the label again
- reason : The previous color settings include transparency for ease of debugging , And in the gazebo This option is not available in the simulation environment ;
- Setup method : Use the specified label to display , Examples are as follows :
<gazebo reference="link The name of the node ">
<material>Gazebo/Blue</material>
</gazebo>
Two 、 Integrated simulation example
First step , Write inertia matrix algorithm related xacro file
<robot name="base" xmlns:xacro="http://wiki.ros.org/xacro">
<!-- Macro for inertia matrix -->
<xacro:macro name="sphere_inertial_matrix" params="m r">
<inertial>
<mass value="${m}" />
<inertia ixx="${2*m*r*r/5}" ixy="0" ixz="0" iyy="${2*m*r*r/5}" iyz="0" izz="${2*m*r*r/5}" />
</inertial>
</xacro:macro>
<xacro:macro name="cylinder_inertial_matrix" params="m r h">
<inertial>
<mass value="${m}" />
<inertia ixx="${m*(3*r*r+h*h)/12}" ixy = "0" ixz = "0" iyy="${m*(3*r*r+h*h)/12}" iyz = "0" izz="${m*r*r/2}" />
</inertial>
</xacro:macro>
<xacro:macro name="Box_inertial_matrix" params="m l w h">
<inertial>
<mass value="${m}" />
<inertia ixx="${m*(h*h + l*l)/12}" ixy = "0" ixz = "0" iyy="${m*(w*w + l*l)/12}" iyz= "0" izz="${m*(w*w + h*h)/12}" />
</inertial>
</xacro:macro>
</robot>
The second step , For each in the robot model link Add related settings (collision、inertial、 Color )
\qquad 1. chassis Xacro file
<!-- Use xacro Optimize URDF Implementation of car chassis based on version : Realize the idea : 1. Put some constants 、 Variables are encapsulated as xacro:property such as :PI value 、 Trolley chassis radius 、 Distance from the ground 、 Wheel radius 、 Width .... 2. Use macro Encapsulate the driving wheel and supporting wheel to realize , Call relevant macros to generate driving wheel and supporting wheel -->
<!-- Root tag , You must declare xmlns:xacro -->
<robot name="my_base" xmlns:xacro="http://www.ros.org/wiki/xacro">
<!-- Encapsulate variables 、 Constant -->
<!-- PI Value setting accuracy needs to be higher , Otherwise, when calculating the subsequent wheel turnover , There may be wheel inclination that cannot be detected by the naked eye , This leads to model jitter -->
<xacro:property name="PI" value="3.1415926"/>
<!-- macro : Black setting -->
<material name="black">
<color rgba="0.0 0.0 0.0 1.0" />
</material>
<!-- Chassis properties -->
<xacro:property name="base_footprint_radius" value="0.001" /> <!-- base_footprint radius -->
<xacro:property name="base_link_radius" value="0.1" /> <!-- base_link radius -->
<xacro:property name="base_link_length" value="0.08" /> <!-- base_link Long -->
<xacro:property name="earth_space" value="0.015" /> <!-- Distance from the ground -->
<xacro:property name="base_link_m" value="0.5" /> <!-- quality -->
<!-- chassis -->
<link name="base_footprint">
<visual>
<geometry>
<sphere radius="${base_footprint_radius}" />
</geometry>
</visual>
</link>
<link name="base_link">
<visual>
<geometry>
<cylinder radius="${base_link_radius}" length="${base_link_length}" />
</geometry>
<origin xyz="0 0 0" rpy="0 0 0" />
<material name="yellow">
<color rgba="0.5 0.3 0.0 0.5" />
</material>
</visual>
<collision>
<geometry>
<cylinder radius="${base_link_radius}" length="${base_link_length}" />
</geometry>
<origin xyz="0 0 0" rpy="0 0 0" />
</collision>
<xacro:cylinder_inertial_matrix m="${base_link_m}" r="${base_link_radius}" h="${base_link_length}" />
</link>
<joint name="base_link2base_footprint" type="fixed">
<parent link="base_footprint" />
<child link="base_link" />
<origin xyz="0 0 ${earth_space + base_link_length / 2 }" />
</joint>
<gazebo reference="base_link">
<material>Gazebo/Yellow</material>
</gazebo>
<!-- Driving wheel -->
<!-- Drive wheel properties -->
<xacro:property name="wheel_radius" value="0.0325" /><!-- radius -->
<xacro:property name="wheel_length" value="0.015" /><!-- Width -->
<xacro:property name="wheel_m" value="0.05" /> <!-- quality -->
<!-- Drive wheel macro implementation -->
<xacro:macro name="add_wheels" params="name flag">
<link name="${name}_wheel">
<visual>
<geometry>
<cylinder radius="${wheel_radius}" length="${wheel_length}" />
</geometry>
<origin xyz="0.0 0.0 0.0" rpy="${PI / 2} 0.0 0.0" />
<material name="black" />
</visual>
<collision>
<geometry>
<cylinder radius="${wheel_radius}" length="${wheel_length}" />
</geometry>
<origin xyz="0.0 0.0 0.0" rpy="${PI / 2} 0.0 0.0" />
</collision>
<xacro:cylinder_inertial_matrix m="${wheel_m}" r="${wheel_radius}" h="${wheel_length}" />
</link>
<joint name="${name}_wheel2base_link" type="continuous">
<parent link="base_link" />
<child link="${name}_wheel" />
<origin xyz="0 ${flag * base_link_radius} ${-(earth_space + base_link_length / 2 - wheel_radius) }" />
<axis xyz="0 1 0" />
</joint>
<gazebo reference="${name}_wheel">
<material>Gazebo/Red</material>
</gazebo>
</xacro:macro>
<xacro:add_wheels name="left" flag="1" />
<xacro:add_wheels name="right" flag="-1" />
<!-- Supporting wheel -->
<!-- Support wheel properties -->
<xacro:property name="support_wheel_radius" value="0.0075" /> <!-- Radius of supporting wheel -->
<xacro:property name="support_wheel_m" value="0.03" /> <!-- quality -->
<!-- Support wheel macro -->
<xacro:macro name="add_support_wheel" params="name flag" >
<link name="${name}_wheel">
<visual>
<geometry>
<sphere radius="${support_wheel_radius}" />
</geometry>
<origin xyz="0 0 0" rpy="0 0 0" />
<material name="black" />
</visual>
<collision>
<geometry>
<sphere radius="${support_wheel_radius}" />
</geometry>
<origin xyz="0 0 0" rpy="0 0 0" />
</collision>
<xacro:sphere_inertial_matrix m="${support_wheel_m}" r="${support_wheel_radius}" />
</link>
<joint name="${name}_wheel2base_link" type="continuous">
<parent link="base_link" />
<child link="${name}_wheel" />
<origin xyz="${flag * (base_link_radius - support_wheel_radius)} 0 ${-(base_link_length / 2 + earth_space / 2)}" />
<axis xyz="1 1 1" />
</joint>
<gazebo reference="${name}_wheel">
<material>Gazebo/Red</material>
</gazebo>
</xacro:macro>
<xacro:add_support_wheel name="front" flag="1" />
<xacro:add_support_wheel name="back" flag="-1" />
</robot>
\qquad 2. camera Xacro file
<!-- Camera related xacro file -->
<robot name="my_camera" xmlns:xacro="http://wiki.ros.org/xacro">
<!-- Camera properties -->
<xacro:property name="camera_length" value="0.01" /> <!-- Camera length (x) -->
<xacro:property name="camera_width" value="0.025" /> <!-- Camera width (y) -->
<xacro:property name="camera_height" value="0.025" /> <!-- Camera height (z) -->
<xacro:property name="camera_x" value="0.08" /> <!-- Camera installation x coordinate -->
<xacro:property name="camera_y" value="0.0" /> <!-- Camera installation y coordinate -->
<xacro:property name="camera_z" value="${base_link_length / 2 + camera_height / 2}" /> <!-- Camera installation z coordinate : Ride height / 2 + Camera height / 2 -->
<xacro:property name="camera_m" value="0.01" /> <!-- Camera quality -->
<!-- Camera joints and link -->
<link name="camera">
<visual>
<geometry>
<box size="${camera_length} ${camera_width} ${camera_height}" />
</geometry>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
<material name="black" />
</visual>
<collision>
<geometry>
<box size="${camera_length} ${camera_width} ${camera_height}" />
</geometry>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
</collision>
<xacro:Box_inertial_matrix m="${camera_m}" l="${camera_length}" w="${camera_width}" h="${camera_height}" />
</link>
<joint name="camera2base_link" type="fixed">
<parent link="base_link" />
<child link="camera" />
<origin xyz="${camera_x} ${camera_y} ${camera_z}" />
</joint>
<gazebo reference="camera">
<material>Gazebo/Blue</material>
</gazebo>
</robot>
\qquad 3. radar Xacro file
<!-- Add radar to the car chassis -->
<robot name="my_laser" xmlns:xacro="http://wiki.ros.org/xacro">
<!-- Radar support -->
<xacro:property name="support_length" value="0.15" /> <!-- Support length -->
<xacro:property name="support_radius" value="0.01" /> <!-- Support radius -->
<xacro:property name="support_x" value="0.0" /> <!-- Bracket mounted x coordinate -->
<xacro:property name="support_y" value="0.0" /> <!-- Bracket mounted y coordinate -->
<xacro:property name="support_z" value="${base_link_length / 2 + support_length / 2}" /> <!-- Bracket mounted z coordinate : Ride height / 2 + Support height / 2 -->
<xacro:property name="support_m" value="0.02" /> <!-- Support quality -->
<link name="support">
<visual>
<geometry>
<cylinder radius="${support_radius}" length="${support_length}" />
</geometry>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
<material name="red">
<color rgba="0.8 0.2 0.0 0.8" />
</material>
</visual>
<collision>
<geometry>
<cylinder radius="${support_radius}" length="${support_length}" />
</geometry>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
</collision>
<xacro:cylinder_inertial_matrix m="${support_m}" r="${support_radius}" h="${support_length}" />
</link>
<joint name="support2base_link" type="fixed">
<parent link="base_link" />
<child link="support" />
<origin xyz="${support_x} ${support_y} ${support_z}" />
</joint>
<gazebo reference="support">
<material>Gazebo/White</material>
</gazebo>
<!-- Radar properties -->
<xacro:property name="laser_length" value="0.05" /> <!-- Radar length -->
<xacro:property name="laser_radius" value="0.03" /> <!-- Radar radius -->
<xacro:property name="laser_x" value="0.0" /> <!-- Radar installation x coordinate -->
<xacro:property name="laser_y" value="0.0" /> <!-- Radar installation y coordinate -->
<xacro:property name="laser_z" value="${support_length / 2 + laser_length / 2}" /> <!-- Radar installation z coordinate : Support height / 2 + Radar altitude / 2 -->
<xacro:property name="laser_m" value="0.1" /> <!-- Radar quality -->
<!-- Radar joints and link -->
<link name="laser">
<visual>
<geometry>
<cylinder radius="${laser_radius}" length="${laser_length}" />
</geometry>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
<material name="black" />
</visual>
<collision>
<geometry>
<cylinder radius="${laser_radius}" length="${laser_length}" />
</geometry>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
</collision>
<xacro:cylinder_inertial_matrix m="${laser_m}" r="${laser_radius}" h="${laser_length}" />
</link>
<joint name="laser2support" type="fixed">
<parent link="support" />
<child link="laser" />
<origin xyz="${laser_x} ${laser_y} ${laser_z}" />
</joint>
<gazebo reference="laser">
<material>Gazebo/Black</material>
</gazebo>
</robot>
\qquad 4. Combine Xacro file
<!-- Combine the car chassis and camera -->
<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" />
</robot>
The third step , To write launch file , stay gazebo In the implementation of
<launch>
<!-- take Urdf The contents of the file are loaded into the parameter server -->
<param name="robot_description" command="$(find xacro)/xacro $(find demo02_urdf_gazebo)/urdf/xacro/my_base_camera_laser.urdf.xacro" />
<!-- start-up gazebo -->
<include file="$(find gazebo_ros)/launch/empty_world.launch" />
<!-- stay gazebo The robot model is displayed in -->
<node pkg="gazebo_ros" type="spawn_model" name="model" args="-urdf -model mycar -param robot_description" />
</launch>
n" command="$(find xacro)/xacro $(find demo02_urdf_gazebo)/urdf/xacro/my_base_camera_laser.urdf.xacro" />
<!-- start-up gazebo -->
<include file="$(find gazebo_ros)/launch/empty_world.launch" />
<!-- stay gazebo The robot model is displayed in -->
<node pkg="gazebo_ros" type="spawn_model" name="model" args="-urdf -model mycar -param robot_description" />
</launch>
The display effect is as follows :

3、 ... and 、Gazebo Simulation environment construction
1. How to create simulation environment
- The way 1: start-up Gazebo, Add built-in components to create environment ;
- The way 2: Customization complete , Draw the simulation environment manually ;
- The way 3: Download the third party directly / Official simulation environment plug-in ;
2. Built in components create simulation environment
- 2.1 start-up gazebo, Add basic plug-ins

- 2.2 Save the simulation environment (.world file )

- 2.3 Write startup file
<launch>
<!-- take Urdf The contents of the file are loaded into the parameter server -->
<param name="robot_description" command="$(find xacro)/xacro $(find demo02_urdf_gazebo)/urdf/xacro/my_base_camera_laser.urdf.xacro" />
<!-- start-up gazebo -->
<include file="$(find gazebo_ros)/launch/empty_world.launch">
<arg name="world_name" value="$(find demo02_urdf_gazebo)/worlds/hello.world" />
</include>
<!-- stay gazebo The robot model is displayed in -->
<node pkg="gazebo_ros" type="spawn_model" name="model" args="-urdf -model mycar -param robot_description" />
</launch>
3. Draw the simulation environment manually
- 3.1 Edit->Building Editor, Open the construction panel drawing environment

- 3.2 file->save,file->Exit Building Editor, Save the environment file after adding the plug-in ;
- 3.3 Write startup file ( ditto )
4. Download the simulation environment directly
- 4.1 Download the model library
Take the official model library as an example ,git Downloading is time-consuming , You can find the target file by yourself
git clone https://github.com/osrf/gazebo_models
- 4.2 Apply template file
- Copy file :
take gazebo_models Copy folder contents to /usr/share/gazebo-*/models- restart gazebo, Application files :
Choose... From the menu bar on the left insert You can select and insert relevant props
summary
- Statement : The blog section of this section refers to CSDN User zhaoxuzuo ROS course , The main content of this paper is in Gazebo Integrated by URDF File generated robot model , Start from the integration process , Deep understanding of how to use Gazebo The simulation component simulates the robot , A pair of Gazebo Creation of simulation environment and integration of simulation instances , The next blog will enter the joint simulation stage , Focus on how to collect sensor data and pass Rviz Realize visual analysis , Coming soon .
边栏推荐
猜你喜欢

Flex layout - fixed positioning + flow layout - main axis alignment - side axis alignment - expansion ratio

go 学习01

LeetCode 热题 HOT 100 -> 3. 无重复字符的最长子串

Clear the cause of floating and six methods (solve the problem that floating affects the parent element and the global)

Plato Farm在Elephant Swap上铸造的ePLATO是什么?

Unity 保存图片到相册以及权限管理

华为APP UI自动化测试岗面试真题,真实面试经历。

小米网站主页面大模块——小模块+导航(浮动案例)

一文读懂Plato&nbsp;Farm的ePLATO,以及其高溢价缘由

How to put app on the app store?
随机推荐
「冒死上传」Proe/Creo产品结构设计-止口与扣位
小程序毕设作品之微信校园浴室预约小程序毕业设计成品(3)后台功能
Appium click operation sorting
They are all talking about Devops. Do you really understand it?
A lock faster than read-write lock. Don't get to know it quickly
Two ways for wechat applet to realize dynamic horizontal step bar
Flume(5个demo轻松入门)
In it, there is a million talent gap, and the salary rises, but it is not capped
【愚公系列】2022年07月 Tabby集成终端的使用
上课笔记(5)(1)——#593. 二分查找(binary)
[website construction] update SSL certificate with acme.sh: change zerossl to letsencrypt
feign调用get和post记录
Data output - image annotation and annotation
Flex layout learning completed on PC side
Execute add migration migration and report build failed
Starfish Os打造的元宇宙生态,跟MetaBell的合作只是开始
Codeforces Round #810 (Div. 2)A~C题解
The level "trap" of test / development programmers is not a measure of one-dimensional ability
新零售业态下,零售电商RPA助力重塑增长
Appium 点击操作梳理