Using ROS to make our robot car (i): URDF profile _ros

Source: Internet
Author: User

It is believed that many enthusiasts stop at expensive robot prices. Although with Arduino, but a very weak capacity of the robot car cost also one hundred or two hundred yuan. It is more time-consuming and laborious to build your own robot.

So if you're just an ordinary robot enthusiast, or haven't figured out what to do with a robot, let's start with the simulator ...


Urdf

In order to make our simulator, first we have to understand what is URDF

What is URDF. Unified Robot Description format--Unified Robot description format. Always feel that this and sensor support is the essence of ROS, communication frameworks is not necessarily brilliant.

Probably most readers are as poor as I am <bi~ background sound > have no money to buy Ros-supported robots, but Ros is nice to consider this group, providing simulator support. (Obviously for faster software development, hello.) )

I would like to start Http://wiki.ros.org/urdf/Tutorials from the ROS website training course, but in the purpose of practice, we still take "Learning Ros for Robostic programming" as the basis.


Reference documents

1. ROS URDF Tutorial: http://wiki.ros.org/urdf/Tutorials

2. "Learning ROS for Robostic Programming"


Preparatory work

Install Urdf_tutorial Package

sudo apt-get install ros-hydro-urdf-tutorial

Perform

Rosrun Rviz Rviz

Of course, your rviz can't start without running Roscore. However, if the error shows that your rviz cannot find the execution file, please refer to the Http://wiki.ros.org/rviz

URDF Basic Syntax

Unified Robot Description format URDF, in fact, is to be able to abstract describe a robot's hardware. And URDF is xml-based, so it should be easy to read.

The author thought to understand URDF to use the Top-down way faster. Start with a solution to a problem. Here we first use a simple scene to familiarize ourselves with the tools we use.

Have to say that the car is the most simple and practical robot, a body plus four wheels on the composition of the most basic car structure, and a certain capacity of the car will not be too expensive.

See the picture below.

(Figure I)



First edition

In URDF languages, robots are connected by various parts (link) through joints (joint). And the key here is to describe the relationship between the parts and the joints.

In this simple car model, a total of 5 parts: Body + 4 wheels. 4 Joints: one per wheel.

So we got the original URDF version 01_CAR_SKELETON.URDF

<robot name= "Test_robot" >
<link name= "Base_link"/> <link name=
"Wheel_1"/> <link
N Ame= "wheel_2"/> <link name= "Wheel_3"/> <link name= "wheel_4" "/> <joint name=


" Joint_ba Se_wheel1 "type=" fixed "> <parent link=" base_link "/> <child link=
" Wheel_1 "/>
</join t>


<joint name= "Joint_base_wheel2" type= "fixed" >
<parent link= "Base_link"/>
LD link= "wheel_2"/>
</joint>


<joint name= "joint_base_wheel3" type= "fixed" >
<pare NT link= "Base_link"/>
<child link= "Wheel_3"/>
</joint>


<joint name= "Joint_base_w Heel4 "type=" fixed "> <parent link=" base_link "/> <child link=
" Wheel_4 "/>
</joint >
</robot>

It's simple, right?

Use <link> tag to describe each part,<joint> tag to describe each joint. Use <parent> and <child> to describe joints connected parts.

As long as the relationship between link and joint is described, it is easy to build a robotic framework.

We can use the following command to check whether the URDF file has a syntax problem.

CHECK_URDF 01_SKELETON.URDF

As long as the following results show that the syntax is no problem.

Robot name Is:test_robot
----------successfully parsed XML---------------
root Link:base_link has 4 child (ren) Child
    (1):  wheel_1 Child (
    2):  wheel_2 (
    3):  wheel_3
    (4):  wheel_4
But note that while this describes the relationship between the parts, it is still an incomplete URDF and cannot be displayed in the emulator.


Second Edition

<visual>tag is used to describe the visual effects of a module.

<geometry>tag is used to describe the shape and size of a module.

<origin>tag is used to describe the location of the module.

Plus the size of the module after the car file is shown below. 02_visual.urdf

<robot name= "Test_robot" > <link name= "Base_link" > <visual> <geometry> <bo X size= "0.2 3.1"/> </geometry> <origin rpy= "0 0 0" xyz= "0 0 0.05"/> </visual> & lt;/link> <link name= "Wheel_1" > <visual> <geometry> <cylinder length= "0.05" R adius= "0.05"/> </geometry> <origin rpy= "0 1.5 0" xyz= "0.1 0.1 0"/> </visual> </l ink> <link name= "wheel_2" > <visual> <geometry> <cylinder length= "0.05" radius = "0.05"/> </geometry> <origin rpy= "0 1.5 0" xyz= " -0.1 0.1 0"/> </visual> </link&

  Gt <link name= "Wheel_3" > <visual> <geometry> <cylinder length= "0.05" radius= "0.05"/&gt
      ; </geometry> <origin rpy= "0 1.5 0" xyz= "0.1-0.1 0"/> </visual> </link> <link nam E= "Wheel_4 "> <visual> <geometry> <cylinder length=" 0.05 "radius=" 0.05 "/> </geometry > <origin rpy= "0 1.5 0" xyz= " -0.1-0.1 0"/> </visual> </link> <joint name= "Joint_ba Se_wheel1 "type=" fixed "> <parent link=" base_link "/> <child link=" Wheel_1 "/> </joint>
  Joint name= "Joint_base_wheel2" type= "fixed" > <parent link= "base_link"/> <child link= "wheel_2"/> </joint> <joint name= "joint_base_wheel3" type= "fixed" > <parent link= "Base_link"/> <child l ink= "Wheel_3"/> </joint> <joint name= "Joint_base_wheel4" type= "fixed" > <parent link= "Base_link" /> <child link= "wheel_4"/> </joint> </robot>

Now, with the following command, you can view your car model through Rviz.

Roslaunch urdf_tutorial Display.launch MODEL:=02_VISUAL.URDF



Step Three: Color

Mmm, our car is almost finished, but red is always strange and difficult to identify.

But coloring is also very simple. Use <material> tag and set <color> tag

We got a third version: 03_COLOR.URDF

<robot name= "Test_robot" > <link name= "Base_link" > <visual> <geometry> <bo X size= "0.2 3.1"/> </geometry> <origin rpy= "0 0 0" xyz= "0 0 0.05"/> <material nam E= "White" > <color rgba= "1 1 1 1"/> </material> </visual> </link> <l
      Ink name= "Wheel_1" > <visual> <geometry> <cylinder length= "0.05" radius= "0.05"/> </geometry> <origin rpy= "0 1.5 0" xyz= "0.1 0.1 0"/> <material name= "Black" > <c Olor rgba= "0 0 0 1"/> </material> </visual> </link> <link name= "wheel_2" > &L t;visual> <geometry> <cylinder length= "0.05" radius= "0.05"/> </geometry> &l T;origin rpy= "0 1.5 0" xyz= " -0.1 0.1 0"/> <material name= "Black"/> </visual> </link> & Lt;link name= "Wheel_3" &GT
      <visual> <geometry> <cylinder length= "0.05" radius= "0.05"/> </geometry>

  <origin rpy= "0 1.5 0" xyz= "0.1-0.1 0"/> "<material name=" Black "/> </visual> </link> <link name= "Wheel_4" > <visual> <geometry> <cylinder length= "0.05" radius= "0.05"/&G
      T </geometry> <origin rpy= "0 1.5 0" xyz= -0.1-0.1 0 "/> <material name=" Black "/> </visu al> </link> <joint name= "Joint_base_wheel1" type= "fixed" > <parent link= "Base_link"/> ; child link= "Wheel_1"/> </joint> <joint name= "Joint_base_wheel2" type= "fixed" > <parent link= "ba
    Se_link "/> <child link=" wheel_2 "/> </joint> <joint name=" joint_base_wheel3 "type=" fixed "> <parent link= "Base_link"/> <child link= "Wheel_3"/> </joint> <joint name= "Joint_base_wheel4 "Type="Fixed "> <parent link=" base_link "/> <child link=" wheel_4 "/> </joint> </robot> 


We can see the results of the Rviz, as shown in figure one.

We're almost done here. We'll be able to move our car in a minute.

But wait, in our URDF file, the size parameters and location of each part are embedded. These are, of course, calculated using a calculator based on sketches.

But this kind of extensibility is too bad. Do we have to calculate that for each model? We have to recalculate the different sizes for the same model.


Fourth Step: Xacro

What is Xacro? We can understand it as a macro language (macro language) Designed for extensibility and configuration of URDF.

With Xacro, we can write URDF files like programming.

First we look at the variable definition of the Xacro file:

<xacro:property name= "Body_width" value= ". 2"/>
As long as the body_width is defined, we can refer to its value by ${body_width}. With this, at least we can manage the variables that need to be configured uniformly.

Second, let's take a look at how XACRO defines macros.

The macros here are similar to the C language macros, and the compiler will expand them when converting to URDF files. Its basic syntax is:

  <xacro:macro name= "Wheel" params= "param1 param2" >
  </xacro:macro>

Let's take a look at the size description of the car body and wheel in the Urdf file.

<box size= "0.2.3.1"/>

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

<cylinder length= "0.05" radius= "0.05"/>

<origin rpy= "0 1.5 0" xyz= " -0.1 0.1 0"/>

The parameters involved here are:

The size of the body (body_size), the position of the Body Center (body_pos).

Wheel radius (Wheel_radius) and tyre width (wheel_width), Position of wheel Center (Wheel1_pos, Wheel2_pos, Wheel3_pos, Wheel4_pos).

The corresponding syntax for defining parameters in Xacro is:

<xacro:property name= "Body_size" value= ". 2.3.1"/> <xacro:property name=
"Body_pos" value= "0 0 0.05"/>
<xacro:property name= "Wheel_radius" value= "0.05"/> <xacro:property name= "Wheel_length"
0.05 "/> <xacro:property name=" Wheel1_pos "value=" 0.1 0.1 0 "/> <xacro:property name=
" Wheel2_pos " Value= " -0.1 0.1 0"/>
<xacro:property name= "Wheel3_pos" value= "0.1-0.1 0"/> <xacro:property
Nam E= "Wheel4_pos" value= " -0.1-0.1 0"/>

and the code for each wheel and connection is basically the same.

Based on the above highlights, we can get the following xacro files. 04_xacro.xacro

<?xml version= "1.0"?> <robot xmlns:sensor= "http://playerstage.sourceforge.net/gazebo/xmlschema/#sensor" xmlns:controller= "http://playerstage.sourceforge.net/gazebo/xmlschema/#controller" xmlns:interface= "http:// playerstage.sourceforge.net/gazebo/xmlschema/#interface "xmlns:xacro=" Http://playerstage.sourceforge.net/gazebo /xmlschema/#interface "name=" Test_robot "> <xacro:property name=" body_size "value=". 2.3.1 "/> <xacro:pro Perty name= "Body_pos" value= "0 0 0.05"/> <xacro:property name= "Wheel_radius" value= "0.05"/> <xacro:prope Rty name= "Wheel_length" value= "0.05"/> <xacro:property name= "Wheel1_pos" value= "0.1 0.1 0"/> <xacro:prop Erty name= "Wheel2_pos" value= " -0.1 0.1 0"/> <xacro:property name= "Wheel3_pos" value= "0.1-0.1 0"/> &LT;XACR
    O:property name= "Wheel4_pos" value= " -0.1-0.1 0"/> <xacro:macro name= "Wheel" params= "Wheelname position" > <link name= "${wheelname}";
        <visual> <geometry> <cylinder length= "${wheel_length}" radius= "${wheel_radius}"/>
          </geometry> <origin rpy= "0 1.5 0" xyz= "${position}"/> <material name= "BLACK" > <color rgba= "0 0 0 1"/> </material> </visual> </link> <joint name= "J
    Oint_base_${wheelname} "type=" fixed > <parent link= "base_link"/> <child link= "${wheelname}"/> </joint> </xacro:macro> <xacro:wheel wheelname= "Wheel1" position= "${wheel1_pos}"/> <xacro:wh Eel wheelname= "Wheel2" position= "${wheel2_pos}"/> <xacro:wheel wheelname= "wheel3" position= "${wheel3_pos}"/ > <xacro:wheel wheelname= "wheel4" position= "${wheel4_pos}"/> <link name= "Base_link" > <visual&gt
       ; <geometry> <box size= "${body_size}"/> </geometry> <origin rpy= "0 0 0" xyz= "${b Ody_pos} "/>
       <material name= "White" > <color rgba= "1 1 1 1"/> </material> </visual> </link> </robot>

There are two ways to verify the correctness of this file.

1. Convert to URDF file and use CHECK_URDF

Rosrun xacro xacro.py 04_xacro.xacro > 04_XACRO.URDF

2. Use of Xacrodisplay.launch

Roslaunch urdf_tutorial Xacrodisplay.launch Model:=04_xacro.xacro

We all get the same car model as Figure 1. So we can use Xacro to build the robot model.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.