Robot Learning Project - Project1: Go Chase it! (2)

4. Basic settings of the robot

Let's build a basic mobile robot model by creating a URDF file and start it in an empty Gazebo world. We can break down the work into smaller components - the robot base, wheels and sensors.

For this model we will create a cube base with two casters. The casters help stabilize the model, they are not always necessary, but they can help distribute the weight and keep the robot from tipping along the z-axis.

Create URDF file

1) Create the urdf directory in the my_robot package

$ cd /home/workspace/catkin_ws/src/my_robot/
$ mkdir urdf

2) Create the robot's xacro file in the urdf directory

$ cd /home/workspace/catkin_ws/src/my_robot/urdf/
$ touch my_robot.xacro

3) Copy the following code to my_robot.xacro file

<?xml version='1.0'?>

<robot name="my_robot" xmlns:xacro="http://www.ros.org/wiki/xacro">

  <link name="robot_footprint"></link>

  <joint name="robot_footprint_joint" type="fixed">
    <originxyz="0 0 0" rpy="0 0 0" />
    <parent link="robot_footprint"/>
    <child link="chassis" />
  </joint>

  <linkname='chassis'>
    <pose>0 0 0.1 0 0 0</pose>

    <inertial>
      <massvalue="15.0"/>
      <origin xyz="0.0 0 0"rpy=" 0 0 0"/>
      <inertia
          ixx="0.1" ixy="0" ixz="0"
          iyy="0.1" iyz="0"
          izz="0.1"
      />
     </inertial>

     <collision name='collision'>
       <origin xyz="0 0 0" rpy=" 0 0 0"/>
       <geometry>
         <box size=".4 .2 .1"/>
       </geometry>
     </collision>

     <visual name='chassis_visual'>
       <origin xyz="0 0 0" rpy=" 0 0 0"/>
       <geometry>
         <box size=".4 .2 .1"/>
       </geometry>
     </visual>

     <collision name='back_caster_collision'>
       <origin xyz="-0.15 0 -0.05" rpy=" 0 0 0"/>
       <geometry>
         <spherer adius="0.0499"/>
       </geometry>
     </collision>

     <visual name='back_caster_visual'>
       <origin xyz="-0.15 0 -0.05" rpy=" 0 0 0"/>
       <geometry>
         <sphere radius="0.05"/>
       </geometry>
     </visual>

     <collision name='front_caster_collision'>
       <origin xyz="0.15 0 -0.05" rpy=" 0 0 0"/>
       <geometry>
         <sphereradius="0.0499"/>
       </geometry>
     </collision>

     <visual name='front_caster_visual'>
       <origin xyz="0.15 0 -0.05" rpy=" 0 0 0"/>
       <geometry>
         <sphereradius="0.05"/>
       </geometry>
     </visual>
  
  </link>

</robot>

There is a single link with a name defined as "chassis", which includes the base as well as the casters. Each link has specific elements, such as inertial elements or collision elements. You can quickly review the details of these elements introduced in the previous section. The chassis is a cube, while the casters are spherical, indicated by their <geometry> tags. Each link (or joint) also has an origin (or pose). Each element of that link or joint will have its own origin, which will be relative to that link's frame of reference.

For this base, the casters are included as part of the stabilizing links, no additional links are required to define the castors and therefore no joints to connect them. But casters have friction defined for them , these friction coefficients are temporarily set to 0, allowing free movement when moving.

Start the robot

Now that the basic robot model has been built, let's create a startup file to load into an empty Gazebo world.

1) Create a new startup file to load the URDF model file

$ cd /home/workspace/catkin_ws/src/my_robot/launch/
$ touch robot_description.launch

2) Copy the following code to the robot_description.launch file

<?xml version="1.0"?>
<launch>

  <!-- send urdf to param server -->
  <paramname="robot_description" command="$(find xacro)/xacro --inorder '$(find my_robot)/urdf/my_robot.xacro'" />

</launch>

To generate a URDF file from an Xacro file, a parameter robot_description must first be defined. This parameter will set a command to generate a URDF from an xacro file using the xacro package ( urdf/Tutorials/Using Xacro to Clean Up a URDF File - ROS Wiki ) .

3) Update the world.launch file so that Gazebo can load the robot URDF model

Add the following to your launch file (after <launch> ):

<!-- Robot pose -->
<argname="x"default="0"/>
<argname="y"default="0"/>
<argname="z"default="0"/>
<argname="roll"default="0"/>
<argname="pitch"default="0"/>
<argname="yaw"default="0"/>

<!-- Launch other relevant files-->
<includefile="$(find my_robot)/launch/robot_description.launch"/>

Add the following to your startup file (before </launch> ):

<!-- Find my robot Description-->
  <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find my_robot)/urdf/my_robot.xacro'"/>

<!-- Spawn My Robot -->
<node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen" 
      args="-urdf -param robot_description -model my_robot 
            -x $(arg x) -y $(arg y) -z $(arg z)
            -R $(arg roll) -P $(arg pitch) -Y $(arg yaw)"/>

The gazebo_ros package ( gazebo_ros - ROS Wiki ) generates models from the URDF generated with the help of robot_description.

start up

$ cd /home/workspace/catkin_ws/
$ catkin_make
$ source devel/setup.bash
$ roslaunch my_robot world.launch

NOTE: Starting Gazebo with a model for the first time may take some time for everything to load.

NOTE: Follow the steps below to model a basic robot using a URDF file

5. Robot enhancement

Having built the basic model of the robot, it is time to enhance it and add wheels, each wheel is represented as a link ( link) and is connected to the base link (chassis) by a joint (joint).

Create Wheel Links ( Links)

First, create links for each wheel using the specifications given below and add them to the Xacro file. For each wheel, there is a collision, inertial and visual elements, and the following properties:

link name link name - "SIDE_wheel", where SIDE is left or right.

geometry - "Cylinder", radius 0.1, length 0.05.

origin The origin of each element - [0,0,0,0,1.5707,1.5707]

Mass of each wheel - "5".

For simplicity, the same inertia values ​​as for the chassis can be used:

ixx="0.1" ixy="0" ixz="0"
iyy="0.1" iyz="0"
izz="0.1"

Create Joints for the two wheels

Once the links are defined, the corresponding joints need to be created. The following elements will create a joint between the left wheel (child link) and the robot chassis (parent link):

<joint type="continuous" name="left_wheel_hinge">
  <origin xyz="0 0.15 0" rpy="0 0 0"/>
  <child link="left_wheel"/>
  <parent link="chassis"/>
  <axis xyz="0 1 0" rpy="0 0 0"/>
  <limit effort="10000" velocity="1000"/>
  <dynamics damping="1.0" friction="1.0"/>
</joint>

The joint type joint type is set to "continuous", which is similar to a rotary joint, but there is no limit to its rotation, which means that the joint can rotate continuously. A joint has its own axis of rotation . Additionally, joints have certain limits that enforce a maximum "effort" and "velocity" for that joint. These limits are useful constraints for real robots and are also helpful in simulations. ROS has good documentation on safety limits ( pr2_controller_manager/safety_limits - ROS Wiki ) . In addition, joints will have specific joint dynamics , corresponding to the physical properties of the joint, such as "damping" and "friction".

Add the left wheel joint to the Xacro file. Then use this as a template to create the joint between the right wheel and the chassis.

start up

Excellent work! The empty.world file can now be launched to visualize the augmented robot model in Gazebo.

NOTE: Follow the steps below to enhance the basic robot model created earlier.

Guess you like

Origin blog.csdn.net/jeffliu123/article/details/129720067