In this tutorial we will learn how to build our own robot in SDFormat. We will build a simple two wheeled robot.本文用SDF文件建立一个2轮机器人
You can find the finished SDF file for the tutorial here.SDF文件点击下载
SDFormat (Simulation Description Format), sometimes abbreviated as SDF, is an XML format that describes objects and environments for robot simulators, visualization, and control.
SDF格式文件是一个用来描述仿真时候的各种配置的文件
We will start by building a simple world and then build our robot in it. Open a new file called building_robot.sdf
and copy the following code to it.
0.001
1.0
true
0 0 10 0 0 0
0.8 0.8 0.8 1
0.2 0.2 0.2 1
1000
0.9
0.01
0.001
-0.5 0.1 -0.9
true
0 0 1
0 0 1
100 100
0.8 0.8 0.8 1
0.8 0.8 0.8 1
0.8 0.8 0.8 1
Save the file, navigate to the directory where you saved the file and launch the simulator:
gz sim building_robot.sdf
Note: You can name your file any name and save it anywhere on your computer.
You should see an empty world with just a ground plane and a sun light. Check World demo to learn how to build your own world.
Under the tag we will add our robot model as follows:
0 0 0 0 0 0
Here we define the name of our model vehicle_blue
, which should be a unique name among its siblings (other tags or models on the same level). Each model may have one link designated as the canonical_link
, the implicit frame of the model is attached to this link. If not defined, the first will be chosen as the canonical link. The
tag is used to define the position and orientation of our model and the relative_to
attribute is used to define the pose of the model relative to any other frame. If relative_to
is not defined, the model's
will be relative to the world.
Let's make our pose relative to the world
. The values inside the pose tag are as follows:
, where the X Y Z
represent the position of the frame and R P Y
represent the orientation in roll pitch yaw. We set them to zeros which makes the two frames (the model and the world) identical.
Every model is a group of links
(can be just one link) connected together with joints
.
0.5 0 0.4 0 0 0
We define the first link, the chassis
of our car and it's pose relative to the model
.
1.14395
0.095329
0
0
0.381317
0
0.476646
Here we define the inertial properties of the chassis like the
and the
matrix. The values of the inertia matrix for primitive shapes can be calculated using this tool.
2.0 1.0 0.5
0.0 0.0 1.0 1
0.0 0.0 1.0 1
0.0 0.0 1.0 1
As the name suggests, the
tag is responsible for how our link will look. We define the shape of our link inside the
tag as a
(cuboid) and then specify the three dimensions (in meters) of this box inside the
tag. Then, inside the
tag we define the material of our link. Here we defined the
,
and
colors in a set of four numbers red/green/blue/alpha each in range [0, 1].
2.0 1.0 0.5
The
tag defines the collision properties of the link, how our link will react with other objects and the effect of the physics engine on it.
Note:
can be different from the visual properties, for example, simpler collision models are often used to reduce computation time.
After copying all the parts above into the world file in order, run the world again:
gz sim building_robot.sdf
Our model should look like this:
In the top left toolbar, click the Translate icon, then select your model. You should see three axes like this:
These are the axes of our model where red is the x-axis, green is the y-axis and blue is the z-axis.
Let's add wheels to our robot. The following code goes after the tag and before the
tag. All the links and joints belonging to the same model should be defined before the
.
-0.5 0.6 0 -1.5707 0 0
1
0.043333
0
0
0.043333
0
0.08
We defined the name of our link left_wheel
and then defined its relative_to
the chassis
link. The wheel needed to be placed on the left to the back of the chassis
so that's why we chose the values for pose
as -0.5 0.6 0
. Also, our wheel is a cylinder, but on its side. That's why we defined the orientation value as -1.5707 0 0
which is a -90
degree rotation around the x-axis (the angles are in radians). Then we defined the inertial
properties of the wheel, the mass
and the inertia
matrix.
0.4
0.2
1.0 0.0 0.0 1
1.0 0.0 0.0 1
1.0 0.0 0.0 1
0.4
0.2
The
and the
properties are similar to the previous link, except the shape of our link has the shape of
that requires two attributes: the
and the
of the cylinder. Save the file and run the world again, our model should look like this:
-0.5 -0.6 0 -1.5707 0 0
1
0.043333
0
0
0.043333
0
0.08
0.4
0.2
1.0 0.0 0.0 1
1.0 0.0 0.0 1
1.0 0.0 0.0 1
0.4
0.2
The right wheel is similar to the left wheel except for its position.
As of SDF 1.7 (Fortress uses SDF 1.8), we can define arbitrary frames. It takes two attributes:
name
: the name of the frameattached_to
: the name of the frame or the link to which this frame is attached.Let's add a frame for our caster wheel as follows:
0.8 0 -0.2 0 0 0
We gave our frame name caster_frame
and attached it to the chassis
link, then the
tag to define the position and orientation of the frame. We didn't use the relative_to
attribute so the pose is with respect to the frame named in the attached_to
attribute, chassis
in our case.
1
0.016
0
0
0.016
0
0.016
0.2
0.0 1 0.0 1
0.0 1 0.0 1
0.0 1 0.0 1
0.2
Our last link is the caster
and its pose is with respect to the frame caster_frame
we defined above. As you could notice we closed the pose
tag without defining the position or the orientation; in this case the pose of the link is the same as (identity) the frame in relative_to
.
In the
and
tags we defined a different shape
which requires the
of the sphere.
We need to connect these links together; here comes the job of the
tag. The joint tag connects two links together and defines how they will move with respect to each other. Inside the
tag we need to define the two links to connect and their relations (way of movement).
Our first joint is the left_wheel_joint
. It takes two attributes: the name name='left_wheel_joint'
and the type type='revolute'
. the revolute
type gives 1 rotational degree of freedom with joint limits. The pose of the joint is the same as the child link frame, which is the left_wheel
frame.
chassis
left_wheel
Every joint connects two links (bodies) together. Here we connect the chassis
with the left_wheel
. chassis
is the parent link and left_wheel
is the child link.
0 1 0
-1.79769e+308
1.79769e+308
Here we define the axis of rotation. The axis of rotation can be any frame, not just the parent
or the child
link. We chose the y-axis with respect to the model
frame so we put 1
in the y element and zeros in the others. For the revolute joint we need to define the
of our rotation angle in the
and
tags.
Note: The angles are in radians.
The right_wheel_joint
is very similar except for the pose of the joint. This joint connects the right_wheel
with the chassis
.
chassis
right_wheel
0 1 0
-1.79769e+308
1.79769e+308
For the caster we need a different type of joint (connection). We used type='ball'
which gives 3 rotational degrees of freedom.
chassis
caster
Run the world:
gz sim building_robot.sdf
It should look like this:
Hurray! We build our first robot. You can learn more details about SDFormat tags here. In the next tutorial we will learn how to move our robot around.
A video walk-through of this tutorial is available from our YouTube channel: Gazebo tutorials: Building a robot.