"Hands-on learning ROS2" 8.3 to create a mobile robot

Author of this series of tutorials: Xiaoyu
Public account: Yuxiang ROS
QQ exchange group: 139707339
Teaching video address: Xiaoyu's B station
Full document address: Yuxiang ROS official website
Copyright statement: Reprinting and commercial use are prohibited unless permitted.
No public

8.3 Hands-on to create a mobile robot

Hello everyone, I'm Xiaoyu. In this lesson, let's create a two-wheel differential mobile robot fishbot. In the previous lesson, we have installed radar on our robot. In this lesson, we will continue with the next lesson. to continue refining our robot model.

In addition to the radar, the robot also needs an IMUacceleration sensor and wheels that can be driven. In Chapter 7, we introduced the robotics part and introduced the two differential model, so we need to create two more differential drives. wheel and a support wheel.

So in this section, Xiaoyu takes you to add the following parts and joints to the robot:

  1. IMU sensor components and joints
  2. Left wheel parts and joints
  3. Right wheel part and joint
  4. Support wheel parts and joints

image-20220117001030066

1. Add IMU sensor (work in the previous section)

IMU sensor and transparency and color modification are the last lesson, homework, Xiaoyu will take you to complete it first

Exercise 1: Try changing the color of the modified robot body to blue and the opacity to 50%(0.1 0.1 1.0 0.5)

Exercise 2: Try to add imu_link in URDF and use imu_joint to fix it 2cm above the center of the car body. The geometry used by imu is box, and the length, width and height are 2cm each.

1.1 Modify the color

Transparency modification only needs to base_linkbe added inmaterial

<link name="base_link">
    <visual>
    	<origin xyz="0 0 0.0" rpy="0 0 0"/>
    <geometry>
    	<cylinder length="0.12" radius="0.10"/>
    </geometry>
    <material name="blue">
    	<color rgba="0.1 0.1 1.0 0.5" /> 
    </material>
    </visual>
</link>

1.2 Add imu

  <link name="imu_link">
  	<visual>
      <origin xyz="0 0 0.0" rpy="0 0 0"/>
      <geometry>
		    <box size="0.02 0.02 0.02"/>
      </geometry>
    </visual>
  </link>

  <!-- imu joint -->
  <joint name="imu_joint" type="fixed">
      <parent link="base_link" />
      <child link="imu_link" />
      <origin xyz="0 0 0.02" />
  </joint>

2. Add right wheel

2.1 Add joints

The joint name is right_wheel_link, the wheels used by Xiaoyu when making the ros2 car are as follows:

image-20220117193835801

The width of the wheel is 4cm, the diameter is 6.4cm, and the geometry is a cylinder, so the geometryconfiguration is as follows:

<geometry>
	<cylinder length="0.04" radius="0.032"/>
</geometry>

It should be noted that the default orientation of the cylinder is upward

image-20220117004252071

We can change the rotation angle of the wheel to make it originrotate around , so the configuration isrpyx轴pi/2origin

<origin xyz="0 0 0" rpy="1.57079 0 0"/>

Change the color to black to get the following configuration:

  <link name="right_wheel_link">
      <visual>
        <origin xyz="0 0 0" rpy="1.57079 0 0"/>
        <geometry>
          <cylinder length="0.04" radius="0.032"/>
        </geometry>
          <material name="black">
            <color rgba="0.0 0.0 0.0 0.5" /> 
          </material>
      </visual>
  </link>

2.2 Add joint

We fixed the center of the left wheel to the left rear of the robot

It should be noted that the setting of the originsum axisvalue

Look at origin first

Since the height of base_link is 0.12, we

  • z represents the relationship between the child and the parent's z-axis. I want to fix the wheel on the lower surface of the robot, so originthe z is offset downward by 0.12/2=0.06m (the downward sign is negative)

  • y represents the relationship between the child and the parent's y-axis, and the radius of the base_link is 0.10, so we offset the y-axis of the wheel by 0.10m in the negative direction (the sign to the left is negative)

  • x represents the relationship of the child relative to the parent's x-axis, and the backward offset is the offset of the x-axis backward. We use a similar value of 0.02m (the backward sign is negative)

image-20220125114933059

Look at the axis again

The wheel will turn, which axis should it turn on? It can be seen from the above figure that it is counterclockwise around the y-axis, so the axis setting is:

<axis xyz="0 1 0" />
  <joint name="right_wheel_joint" type="continuous">
      <parent link="base_link" />
      <child link="right_wheel_link" />
      <origin xyz="-0.02 -0.10 -0.06" />
      <axis xyz="0 1 0" />
  </joint>

3. Add a revolver

The left wheel is the mapping of the right wheel, so I won't repeat it.

  <link name="left_wheel_link">
      <visual>
        <origin xyz="0 0 0" rpy="1.57079 0 0"/>
        <geometry>
          <cylinder length="0.04" radius="0.032"/>
        </geometry>
          <material name="black">
            <color rgba="0.0 0.0 0.0 0.5" /> 
          </material>
      </visual>
  </link>
    
  <joint name="left_wheel_joint" type="continuous">
      <parent link="base_link" />
      <child link="left_wheel_link" />
      <origin xyz="-0.02 0.10 -0.06" />
      <axis xyz="0 1 0" />
  </joint>

4. Add support wheels

The support wheel is fixed in front of the robot, and a sphere is used for the radius 0.016m. The diameter of the small ball is 0.032m, which is the same as the radius of the left and right wheels, and then offset 0.016+0.06=0.076mdownward, and the downward value is negative. At the same time, move the support theory forward a little, select indivual0.06m

The final result is as follows:

<link name="caster_link">
    <visual>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <geometry>
          <sphere radius="0.016"/>
      </geometry>
        <material name="black">
          <color rgba="0.0 0.0 0.0 0.5" /> 
        </material>
    </visual>
  </link>
    
  <joint name="caster_joint" type="fixed">
      <parent link="base_link" />
      <child link="caster_link" />
      <origin xyz="0.06 0.0 -0.076" />
  </joint>

Final URDF file: https://raw.githubusercontent.com/fishros/fishbot/master/src/fishbot_description/urdf/fishbot_base.urdf

5. Test run

5.1 Compile and test

colcon build
source install/setup.bash
ros2 launch fishbot_description display_rviz2.launch.py

5.2 Final result

rviz configuration

image-20220117012057367

Final Results

image-20220117012033644

two more sliders for jointstate

image-20220117012528123

Node relationship

image-20220117012331955

print joint_statestopic

ros2 topic echo /joint_states

image-20220117012745344

5.3 Change the joint angle in joint tf through joint_state_gui

In the JointStatePublisher, drag the slider and observe

  1. rviz2tftransformation in
  2. joint_statestransformation of the values ​​in

image-20220117012946727

It can be seen that as the progress bar is dragged, the values ​​in the topic and the robot joints in rviz2 are rotating synchronously. The joint_states topic can also be sent manually. In the next lesson, Xiaoyu will take you joint_statesto control the rotation of the robot wheel by sending it manually.


Technical exchange && problem assistance:

  • WeChat public account and communication group: Yuxiang ROS

  • Xiaoyu WeChat: AiIotRobot

  • QQ exchange group: 139707339

  • Copyright Protection: Joined the Copyright Protection Program of Rights Knights (rightknights.com)

about the author:

I am Xiaoyu, a senior player in the field of robotics. I am currently a unipod robot algorithm engineer in Shenzhen,
learning programming in junior high school. I began to get in touch with robots in high school. During college, I played robot-related competitions and achieved a monthly income of 2W+ (competition bonus).
Currently, I am outputting robot learning guides , paper notes, work experience, welcome everyone to pay attention to Xiaoyu, exchange technology together, and learn robots

Guess you like

Origin blog.csdn.net/qq_27865227/article/details/122829025