Webots User Guide - chapter 7 - section 7

Webots User Guide


7.7 Tutorial 6: 4-Wheels Robot

The aim of this tutorial is to create your first robot from scratch. This robot will be made of a body, four wheels, and two distance sensors. The result is depicted in figure 7.13. The figure 7.14 shows the robot from a top view.

tutorial_4_wheels_robot

Figure 7.13: 3D view of the 4 wheels robot. Note that the coordinate system representations of the robot body and of its wheels are oriented the same way. Their +x-vector (in red) defines the left of the robot, their +y-vector (in green) defines the top of the robot, and their +z-vector (in blue) defines the front of the robot. The distance sensors are oriented in a different way, their +x-vector indicates the direction of the sensor.

tutorial_4_wheels_top_schema

Figure 7.14: Top view of the 4 wheels robot. The grid behind the robot has a dimension of 0.2 x 0.3 [m]. The text labels correspond to the name of the devices.

7.7.1 New simulation

Save the world of the previous tutorial as 4_wheels_robot.wbt.
Remove the nodes defining the e-puck, the ball, the dumbbell and the contact properties. The ground, the walls and the lighting are kept.

7.7.2 Separating the Robot in Solid Nodes

Some definitions are required before giving rules to create a robot model.

The set of all the classes derived by the Solid node is called the solid nodes. The Solid node is inherited by the device nodes (for example: a Servo or a DistanceSensor node) and by the robot nodes (for example: a Robot or a DifferentialWheels node). You can get more information about the node hierarchy in the Reference Manual.

The main structure of a robot model is a tree of solid nodes directly linked together. The root node of this tree should be a robot node. A device node should be the direct child of either a robot node or either a Servo node.
A Servo node is used to add a joint, i.e. one degree of freedom (DOF), between himself and its direct parent. The parent of a Servo node is either a robot node or either a Servo node. The number of Servo nodes of a robot is equivalent to the number of DOF of the robot.

Having these rules in mind, we can start to design the node hierarchy used to model the robot. The first step is to determine which part of the robot should be modeled as a solid node.

In our example, this operation is quite obvious. The robot has 4 DOF corresponding to the wheel motors. It can be divided in five solid nodes: the body and the four wheels.

Depending on the expected application of the robot model, reducing the number of DOF when modeling could be important to get an efficient simulation. For example, when modeling a caster wheel, a realistic approach implies to model 2 DOF. But if this degree of precision is useless for the simulation, a more efficient approach can be found. For example, to model the caster wheel as a Sphere having a null friction coefficient with the ground.

The second step is to determine which solid node is the robot node (the root node). This choice is arbitrary, but a solution is often much easier to implement. For example, in the case of an humanoid robot, the robot node would be typically the robot chest, because the robot symmetry facilitates the computation of the Servos translation and rotation.

In our case, the body box is obviously the better choice. The figure 7.15 depicts the solid nodes hierarchy of the robot.

Add a Robot node having four Servo nodes as children at the end of the scene tree according to figure 7.15.
Add a Shape node containing a Box geometry to the Robot node. Set the color of the Shape to red. Use the Shape to define also the boundingObject field of the Robot node. The dimension of the box is (0.1, 0.05, 0.2). Add a Physics node to the Robot. The figure 7.16 represents all the nodes defining the robot. So far only the direct children nodes of the root Robot node are implemented.
tutorial_4_wheels_highlevel

Figure 7.15: High level representation of the 4 wheels robot

tutorial_4_wheels_lowlevel

Figure 7.16: Low level representation of the 4 wheels robot

7.7.3 Rotational Servos

A Servo node is by default rotational (defined by its type field). This means that the controller will be able to rotate the Servo. The rotation is computed by using the Euler axis and angle representation of the Servo node (its rotation field). Indeed, the euler angle can be modified by the controller. So the Servo rotation axis is the Euler axis given by the rotation field.

In our case, the rotation axis of the wheels will be along the x-axis. So the rotation field of each Servo node is (1, 0, 0, 0) and the translation field corresponds to the position of the wheels relatively to the robot origin. For example WHEEL1 is located at (0.06, 0, 0.05).

Set the translation and the rotation fields of each Servo as described above.

We want now to implement the cylinder shape of the wheels. As the Cylinder node is defined along the y-axis, a Transform node should encapsulate the Shape to rotate the Cylinder along the along the x-axis.

Complete the missing nodes to get the same structure as the one depicted in figure 7.16. Don't forget the Physics nodes. Rotate the Transform node by an Euler axis and angle of (0, 0, 1, Pi/2) in order to inverse the x-axis and the y-axis. The Cylinder should have a radius of 0.04 and a height of 0.02. Set the color of the wheels to green.
Set the name field of each Servo node from "wheel1" to "wheel4" according to the figure 7.14. These labels will be used to reference the wheels from the controller.

7.7.4 Sensors

The last part of the robot modeling is to add the two distance sensors to the robot. This can be done by adding two DistanceSensor nodes as direct children of the Robot node. Note that the distance sensor acquires its data along the +x-axis. So rotating the distance sensors in order to point their x-axis outside the robot is necessary (see the figure 7.14).

Add the two distance sensors as explained above. The distance sensors are at an angle to 0.3 [rad] with the robot front vector. Set their type field to "sonar". Set their graphical and physical shape to a cube (not transformed) having a edge of 0.01 [m]. Set their color to blue. Set their name field according to the labels of figure 7.14.

7.7.5 Controller

In the previous tutorials, you learnt how to setup a feedback loop and how to read the distance sensor values. However actuating the Servo nodes is new. The following note explain how to proceed.

To program the servos, the first step is to include the API module corresponding to the Servo node:

#include <webots/servo.h>

Then to get the references of the Servo nodes:

// initialize servos
WbDeviceTag wheels[4];
char wheels_names[4][8] = {
  "wheel1", "wheel2", "wheel3", "wheel4"
};
for (i=0; i<4 ; i++)
  wheels[i] = wb_robot_get_device(wheels_names[i]);

A servo can be actuated by setting its position, its velocity or its force (cf. Reference Manual). Here we are interested in setting its velocity. This can be achieve by setting its position at infinity, and by bounding its velocity:

double speed = -1.5; // [rad/s]
wb_servo_set_position(wheels[0], INFINITY);
wb_servo_set_velocity(wheels[0], speed);

Implement a controller called 4_wheels_collision_avoidance moving the robot and avoiding obstacles by detecting them by the distance sensors. Note that the lookupTable field of the DistanceSensor nodes indicates which values are returned by the sensor (cf. Reference Manual). Don't forget to set the controller field of the Robot node to indicate your new controller. As usual a possible solution of this exercise is located in the tutorials directory.

7.7.6 Conclusion

You are now able to design simple robot models, to implement them and to create their controllers.

More specifically you learnt the different kind of nodes involved in the building of the robot models, the way to translate and rotate a solid relatively to another, the way that a rotational servo is actuated by the controller.

release 7.0.2
Copyright © 2012 Cyberbotics Ltd. All right reserved.