ROS simulation robot study notes 2: Create a 4-wheel car model and modify related xraco files

Series Article Directory

提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加
For example: the use of pandas in Chapter 1 Introduction to Python Machine Learning


提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档


foreword

提示:这里可以添加本文要记录的大概内容:

Following the blogger's tutorial in the previous section, you can roughly walk through the robot simulation in ROS. But you'd better run it on a machine with better performance. Later, I copied the virtual machine to the desktop, and it ran much smoother.
Next, I am going to walk through it according to my own model.
My own model is a model of a four-wheeled cart with four drive wheels. The original model had a circular differential chassis with two drive wheels. So the first step is to make an XACRO file that describes the robot model.


提示:以下是本篇文章正文内容,下面案例可供参考

1. Build a new XACRO file

The XACRO file is an optimized version of the URDF file, which can be modified according to the URDF file, and the URDF file can also be imported from SOLIDWORKS, so it feels like this path is very smooth, but it still underestimates the process.
One is that solidworks itself needs to be learned for a period of time to get started, and there are many details in importing URDF from solidworks. The follow-up process will be relatively troublesome.

One is the solidworks engineering entity, which is not a simple box and wheel, but there are many irregular structures, connectors, etc. These need to be processed when exporting the URDF file, usually the fixed structure and the moving structure are separated and merged separately. Then export.
The second is that in the Gazebo simulation environment, each node must be configured with an inertia matrix. If it is too complicated, the configuration will be too complicated.
This is currently understood, so it is still simpler, use rectangles and circles to implement it simply.

Modify the original project:

1. Change the round chassis to a square chassis

    <xacro:property name="base_width" value="0.46"/>  
    <xacro:property name="base_length" value="0.66"/> 
    <xacro:property name="base_height" value="0.2"/>
 
    <link name="base_link">
      <visual>
        <geometry>
           <box size="${base_length} ${base_width} ${base_height}"/>
        </geometry>
        <origin xyz="0 0 ${base_height/2 + earth_space}" rpy="0 0 0" />
        <material name="yellow">
          <color rgba="0.5 0.3 0.0 0.5" />
        </material>
      </visual>

    </link>

Define the three variables of length, width and height of the BOX type, and then copy the template. The main thing is the z coordinate of origin. If it is 0, the robot will be seen below the horizon in RVIZ.

2. Set left and right 4 wheels

<!-- 驱动轮 -->
    <!-- 驱动轮属性 -->
    <xacro:property name="wheel_radius" value="0.084" /><!-- 半径 -->
    <xacro:property name="wheel_length" value="0.05" /><!-- 宽度 -->
    <xacro:property name="wheel_x" value="0.18"/>  
    <xacro:property name="wheel_y" value="0.18"/> 
    <!-- 驱动轮宏实现 -->
    <xacro:macro name="add_wheels" params="name flag flag1" >
      <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>
      </link>

      <joint name="${name}_wheel2base_link" type="continuous">
        <parent link="base_link" />
        <child link="${name}_wheel" />
        <origin xyz="${flag1 * wheel_x} ${flag * wheel_y} ${-(earth_space + base_link_length / 2 - wheel_radius) }" />
        <axis xyz="0 1 0" />
      </joint>
    </xacro:macro>

    <xacro:add_wheels name="fleft" flag="1" flag1="1"/>
    <xacro:add_wheels name="fright" flag="-1" flag1="1"/>
    <xacro:add_wheels name="rleft" flag="1" flag1="-1"/>
    <xacro:add_wheels name="rright" flag="-1" flag1="-1"/>

The original wheel macro definition only has one flag parameter to set the left and right, here one is added to set the front and rear. wheel_x wheel_y refers to the distance between the wheel and the center point, where the four wheels are centered and symmetrical.

3. Setting up LiDAR

    <!-- 雷达属性 -->
    <xacro:property name="laser_length" value="0.05" /> <!-- 雷达长度 -->
    <xacro:property name="laser_radius" value="0.03" /> <!-- 雷达半径 -->
    <xacro:property name="laser_x" value="0.2" /> <!-- 雷达安装的x坐标 -->
    <xacro:property name="laser_y" value="0.0" /> <!-- 雷达安装的y坐标 -->
    <xacro:property name="laser_z" value="0.24" /> <!-- 雷达安装的z坐标:支架高度 / 2 + 雷达高度 / 2  -->

    <!-- 雷达关节以及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>
    </link>

    <joint name="laser2support" type="fixed">
        <parent link="base_link" />
        <child link="laser" />
        <origin xyz="${laser_x} ${laser_y} ${laser_z}" />
    </joint>

The lidar here deletes the original support rod and fixes it directly above the chassis. Remember to change the parent link to base_link here. Otherwise, the reference plane cannot be found.

2. Inertia matrix setting

1.head.xacro

    <xacro:macro name="box_inertia" params="m w h d">
        <inertial>
        <origin xyz="0 0 0" rpy="${pi/2} 0 ${pi/2}"/>
        <mass value="${m}"/>
        <inertia ixx="${(m/12) * (h*h + d*d)}" ixy="0.0" ixz="0.0" iyy="${(m/12) * (w*w + d*d)}" iyz="0.0" izz="${(m/12) * (w*w + h*h)}"/>
        </inertial>
    </xacro:macro>

    <xacro:macro name="cylinder_inertia" params="m r h">
        <inertial>
        <origin xyz="0 0 0" rpy="${pi/2} 0 0" />
        <mass value="${m}"/>
        <inertia ixx="${(m/12) * (3*r*r + h*h)}" ixy = "0" ixz = "0" iyy="${(m/12) * (3*r*r + h*h)}" iyz = "0" izz="${(m/2) * (r*r)}"/>
        </inertial>
    </xacro:macro>

Here, two kinds of inertia matrix macro definitions are added in head.xacro. In fact, it is the same as above, and it is also copied from other references. are to calculate the inertia matrices of the cuboid and the ring, respectively.

2. Modify car_base.xacro

      <collision>
        <geometry>
          <box size="${base_length} ${base_width} ${base_height}"/>
        </geometry>
      </collision>
      <xacro:box_inertia m="15" w="${base_width}" d="${base_length}" h="${base_height}"/>

Follow the steps here, just add the corresponding code in it.

        <collision>
          <origin xyz="0 0 0" rpy="${pi/2} 0 0"/>
          <geometry>
            <cylinder radius="${wheel_radius}" length="${wheel_length}"/>
          </geometry>
        </collision>

        <xacro:cylinder_inertia m="0.5" r="${wheel_radius}" h="${wheel_length}"/> 

After doing this, you can see the corresponding model in Gazebo.

3. Motion Control Settings

Motion control is described in the example move.xacro request.
Since our model has 4 wheels, we first add two sports wheels to the original and modify the name.

    <xacro:joint_trans joint_name="fleft_wheel2base_link" />
    <xacro:joint_trans joint_name="fright_wheel2base_link" />
    <xacro:joint_trans joint_name="rleft_wheel2base_link" />
    <xacro:joint_trans joint_name="rright_wheel2base_link" />

1. Modify the motion model

The sport mode plugin referenced by the original document is
libgazebo_ros_diff_drive.so
this plugin is suitable for 2-wheel differential chassis. This should be changed to:
libgazebo_ros_planar_move.so
The model of the four-wheel differential.
There should be many more of these plug-ins, which have not been studied in depth here, at least including models such as four-wheel differential belt steering.
Only when the model is matched, and then do navigation and the like later, the effect will be the best.
Then modify it according to the reference given.

    <gazebo>
    <plugin name="object_controller" filename="libgazebo_ros_planar_move.so">

    <updateRate>100.0</updateRate>
    <robotNamespace>/</robotNamespace>
    <leftFrontJoint>fleft_wheel2base_link</leftFrontJoint>
    <rightFrontJoint>fright_wheel2base_link</rightFrontJoint>
    <leftRearJoint>rleft_wheel2base_link</leftRearJoint>
    <rightRearJoint>rright_wheel2base_link</rightRearJoint>
    <wheelSeparation>4</wheelSeparation>
    <wheelDiameter>0.1</wheelDiameter>
    <robotBaseFrame>base_link</robotBaseFrame>
    <torque>1</torque>
    <topicName>cmd_vel</topicName>
    <broadcastTF>0</broadcastTF>

    <odometryTopic>odom</odometryTopic>
    <odometryFrame>odom</odometryFrame>

    </plugin>
  </gazebo>

In this way, our chassis can be controlled by motion commands in Gazebo.

Summarize

提示:这里对文章进行总结:

For example: the above is what we will talk about today. This article only briefly introduces the use of pandas, and pandas provides a large number of functions and methods that allow us to process data quickly and easily.

Guess you like

Origin blog.csdn.net/lunzilx/article/details/129726407