gazebo simulation of four car

step

1. Set up the workspace

mkdir -p ~/smartcar/src
cd ~/smartcar/src
catkin_init_workspace
cd ~/smartcar/
catkin_make
source devel/setup.bash

Note: After compilation has been to solve the problem source:

gedit ~/.bashrc  

In the end of the file add: source ~ / smartcar / devel / setup.bash

2. Create ROS trolley bag description

cd ~/smartcar/src
roscreate-pkg smartcar_description urdf

Write 3.urdf file

1. smartcar_description create a folder under the folder: urdf , and urdf folder created smart.urdf file

cd ~/smartcar/src/smartcar_description/
mkdir urdf
cd ~/smartcar/src/smartcar_description/urdf/
touch smartcar.urdf

2. In the description file smartcar.urdf, writing the following codes:

<?xml version="1.0"?> 
<robot name="smartcar">
    <link name="base_link">      <!-- 连杆名为base_link-->
        <visual>		<!--visual设置连杆的可视化信息-->
            <geometry>		<!--geometry输入模型的形状-->
                <box size="0.25 .16 .05"/>  <!--"box"类型,长宽高分别为0.25,0.16,0.05-->
            </geometry>

            <origin rpy="0 0 1.57075" xyz="0 0 0"/>    <!--origin设置相对于连杆相对坐标系的移动和旋转-->

            <material name="blue">     			<!--material设置连杆的颜色和纹理-->
                <color rgba="0 .5 .8 1"/>
            </material>
        </visual>
    </link>

    <link name="right_front_wheel">            <!--设置右前轮连杆信息-->
        <visual>  
            <geometry>  
                <cylinder length=".02" radius="0.025"/>  
            </geometry>  

            <material name="black">  
                <color rgba="0 0 0 1"/>  
            </material>  
        </visual>  
    </link>  
    
    <joint name="right_front_wheel_joint" type="continuous">    <!--设置关节信息 type="continuous"表示旋转关节,可以绕单轴无线旋转-->
        <axis xyz="0 0 1"/>  					<!--axis设置旋转轴-->
        <parent link="base_link"/>  				<!--parent关节的父连杆-->
        <child link="right_front_wheel"/>  			<!--child关节的子连杆-->
        <origin rpy="0 1.57075 0" xyz="0.08 0.1 -0.03"/>  	<!--origin将父连杆坐标系转换为子连杆坐标系-->
        <limit effort="100" velocity="100"/>  			<!--limit 设置关节的速度、力和半径(仅当关节是revolute或prismatic时)-->
        <joint_properties damping="0.0" friction="0.0"/>  	<!--joint_properties设置一些属性 阻尼系数 摩擦系数-->
    </joint>  
    
    <link name="right_back_wheel">  
    <visual>  
        <geometry>  
        <cylinder length=".02" radius="0.025"/>  
        </geometry>  
        <material name="black">  
        <color rgba="0 0 0 1"/>  
        </material>  
    </visual>  
    </link>  
    
    <joint name="right_back_wheel_joint" type="continuous">  
        <axis xyz="0 0 1"/>  
        <parent link="base_link"/>  
        <child link="right_back_wheel"/>  
        <origin rpy="0 1.57075 0" xyz="0.08 -0.1 -0.03"/>  
        <limit effort="100" velocity="100"/>  
        <joint_properties damping="0.0" friction="0.0"/>  
    </joint>  
    
    <link name="left_front_wheel">  
        <visual>  
            <geometry>  
                <cylinder length=".02" radius="0.025"/>  
            </geometry>  
            <material name="black">  
                <color rgba="0 0 0 1"/>  
            </material>  
        </visual>  
    </link>  
    
    <joint name="left_front_wheel_joint" type="continuous">  
        <axis xyz="0 0 1"/>  
        <parent link="base_link"/>  
        <child link="left_front_wheel"/>  
        <origin rpy="0 1.57075 0" xyz="-0.08 0.1 -0.03"/>  
        <limit effort="100" velocity="100"/>  
        <joint_properties damping="0.0" friction="0.0"/>  
    </joint>  
    
    <link name="left_back_wheel">  
        <visual>  
            <geometry>  
                <cylinder length=".02" radius="0.025"/>  
            </geometry>  
            <material name="black">  
                <color rgba="0 0 0 1"/>  
            </material>  
        </visual>  
    </link>  
    
    <joint name="left_back_wheel_joint" type="continuous">  
        <axis xyz="0 0 1"/>  
        <parent link="base_link"/>  
        <child link="left_back_wheel"/>  
        <origin rpy="0 1.57075 0" xyz="-0.08 -0.1 -0.03"/>  
        <limit effort="100" velocity="100"/>  
        <joint_properties damping="0.0" friction="0.0"/>  
    </joint>  
    
    <link name="head">  
        <visual>  
            <geometry>  
                <box size=".02 .03 .03"/>  
            </geometry>  
            <material name="white">
                <color rgba="1 1 1 1"/>  
            </material>  
        </visual>  
    </link>  
    
    <joint name="tobox" type="fixed">  
       <parent link="base_link"/>  
      <child link="head"/>  <!--将子link(right_front_wheel)连接到父link(base_link)上-->
        <origin xyz="0 0.08 0.025"/>  
    </joint>  
</robot>

Note: . 1
... urdf configuration file has two parts: and wherein the attribute information ... describes the hardware configuration of the model, which information shape, color, mass, inertia of the wheels will be described in language; to be understood as two ... ... inter-connection between, as shown in the blue box, it describes a position between two fixed connection information ... and the like.
2. The wheel and car body connection is through the establishment of the bridge.
3. In the formal go smarter.launch when writing code which do not have Chinese notes , or can not read the contents

4. launch the preparation of documents

Establish launch folder under / smartcar_description folder, and create a smart car launch file display.launch

<launch>
	<arg name="model" />
	<arg name="gui" default="False" />
	<param name="robot_description" textfile="$(find smartcar_description)/urdf/smartcar.urdf" />
	<param name="use_gui" value="$(arg gui)"/>
	<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" ></node>
	<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
	<node name="rviz" pkg="rviz" type="rviz" args="-d $(find urdf_tutorial)/urdf.rviz" />
</launch>

5. rviz model display

Run display.launch file

roslaunch smartcar_description display.launch

6.rviz set some parameters

1. Add Displays,
A click on the Add added to the lower left corner of the display contents Display.
B Select RobotModel, and click OK to add Display.
2. Modify Fixed Frame option parameter
modification base_link Fixed Frame is normal to display, as shown below:

Published 23 original articles · won praise 17 · views 4178

Guess you like

Origin blog.csdn.net/qq_43786066/article/details/104330150