This chapter is composed of a series of exercises for beginners. You don't need prior knowledge to go through these exercises. The aim is to learn the basics of mobile robotics by manipulating both your e-puck and Webots. First, you will discover some e-puck devices and their utility. Then, you will acquire the concept of a robot controller. And finally, you will program a simple robot behavior by using a Webots module: BotStudio. This module enables to program an e-puck robot using a graphical interface. You will discover how to use it and what are the notions related to it.
Discovery of the e-puck [Beginner]
As explained in the chapter E-puck and Webots, an e-puck has different devices. Through this document, you will use some of them: the stepper motors, the LEDs, the accelerometer, the infrared sensors and the camera. In this exercise, you will discover the utility of each of them. The following list gives you a quick definition of these devices. You will see in the next chapter all these devices in more details.
- Stepper motor: A stepper motor[1] is an electrical motor which breaks up a full rotation into a large number of steps. An e-puck possesses two stepper motors of 1000 steps. They can achieve a speed of about one rotation per second. The wheels of the e-puck are fixed to these motors. They are used to move the robot. They can move independently. Moreover, for knowing the position of the wheels, an incremental encoder can be used. The e-puck encoder returns the number of steps since the last reset of the encoder. For example, this ”device” can be used for turning the wheel of one turn precisely.
- LED: A LED[2] (Light-Emitting Diode) is a small device which can emit light by using few energy. An e-puck possesses several LEDs. Notably, 8 around it, 4 in the e-puck body and 1 in front of it. The front LED is more powerful than the others. The aim of these LEDs is mainly to have a feedback on the state of the robot. They can also be used for illuminating the environment.
- Accelerometer: An accelerometer[3] is a device which measures the total force applied on it as a 3D vector. An e-puck has a single accelerometer. If your e-puck is at rest, the accelerometer indicates at least the gravitational vector. The accelerometer can be used for detecting a collision with a wall or for detecting the fall of the robot.
- Infrared (IR) sensor: An e-puck possesses 8 infrared (IR) sensors. An IR sensor is a device which can produce an infrared light (a light which is out the range of the visible light) and which can measure the amount of the received light. It has two kind of use. First, only the received light is measured. In this configuration, the IR sensor measures the light of the nearby environment. The e-puck can detect for example from where a light illuminates it. Second, the IR sensor emits infrared light and measures the received light. If there is an obstacle in front of the IR sensor, the light will bounce on it. The light difference is bigger. So, the e-puck can estimate the distance between its IR sensors and an obstacle.
- Camera: In front of the e-puck, there is also a VGA camera. The e-puck uses it to discover its direct front environment. It can for example follow a line, detect a blob, recognize objects, etc.
Note that the stepper motors and the LEDs are actuators. This device have an effect on the environment. To the contrary, the IR sensors and the camera are sensors. They measure specific information of the environment. On the following page you can see photos of the mechanical design.
To successfully go through the following exercises, you have to know the existence of other devices. The e-puck is alimented with a Li-ION battery. It has a running life of about 3 hours. You can switch on or off your e-puck with the ON/OFF switch which is located near the right wheel. The robot has also a Bluetooth interface which allows a communication with your computer or with other e-pucks.
Finally, the e-puck has other devices (like the microphones and the speaker) that you will not use in this document because the current version of Webots doesn't support them yet.
Robot Controller [Beginner]
In order to understand the concept of a robot controller you will play the role of the robot controller. You will perceive the sensory information coming from the sensors of the robot and you will be able to control the actuators of the robot. In this exercise, you will not actually program the behavior of the robot, but you will nevertheless control the robot.
Open the World File
First of all, you need to open the world file of this exercise. A world file contains the entire environment of the simulation, i.e., the robot shape, the ground shape, the obstacles shape and some general information like the position of the camera and even the direction of gravitational vector. In the simulation window (window (1) in figure below), click on File | Open menu and open:
.../worlds/beginner_robot_controller.wbt
You can also open the world file by clicking on the open button on the tool box of the simulation window. The e-puck model and its environment are loaded in Webots. In the simulation window, you can see an e-puck on a green board.
The Webots Windows and the simulation Camera
Webots can display several windows. Some of them were already introduced. You will focus especially on two of them (which are depicted on a figure):
- The simulation window (1): This window is probably the most important one. It shows a 3D representation of the simulation. In our case, you can see a virtual e-puck and its virtual environment. If you want to modify the camera orientation, just click and drag with the left button of the mouse where you want in the panel. Similarly you can modify the position of the camera by using the right button (Note for the Mac OS X users : if you have a mouse with a single button, hold down the Ctrl key and click for emulating the right click.). Finally you can also set the zoom by moving the mouse wheel. There are also two important buttons in this window: the play/stop button and the revert button. With the first one, the simulation can be either played or stopped, and with the second one, the entire simulation can be reset.
- The robot window (2): This window shows a 2D representation of the e-puck. The purpose of this window is to visualize the sensor values and the actuators values in real-time during a simulation. The figure with the robot window shows the meaning of the values that can be seen. The red integers correspond to the speed of the motors. They should be initially null. The green values below correspond to the encoders. The light measured by the IR sensor is represented by the green integers. While the distance between a IR sensor and an obstacle is represented by blue integers. So, note that the green and the blue values represent the same device. The red or black rectangles correspond to the LEDs which are respectively switched on or off. Finally, the accelerometer is represented both by a 2D vector which corresponds to the inclination of the e-puck, and by a slider which represents the norm of the acceleration. This window contains also a drop-down menu to configure the Bluetooth connection.
The e-puck Movements
Check that the simulation is running by clicking on the start/stop button. Then, click on the virtual e-puck in order to select it. When your e-puck is selected, white lines appears. They represent the bounds of your object for the physical simulation. You also remark red lines. They represent the direction of the IR sensors. While the magenta lines correspond to the field of view of the camera. Moreover, you can observe the camera values into a little window in the top left part of the simulation window.
On your keyboard, press the "S" key and the "X" key for respectively increasing or decreasing the speed value of the left motor. Try to press the "D" key and on the ”C” key for modifying the speed of the right motor. Now you can move the virtual robot like a remote control toy. Note that only one key can be pressed at the same time.
Blinded Movement [Challenge]
The aim of this subsection is to play the role of the robot controller. A robot controller perceives only the values measured by the robot sensors, treats them and sends some commands to the robot actuators as depicted in the figure. Note that the sensor values are modified by the environment, and that a robot can modify the environment with its actuators.
Let's move your real Robot
You probably have a real e-puck in front of you and you would like to see it moving! Webots can communicate with an e-puck via a Bluetooth connection. It can receive some values from the e-puck sensors and send some values to command the e-puck actuators. So, Webots can play the role of the controller. This mode of operation is called a remote-control session.
In order to proceed, configure first your Bluetooth connection as explained in the section Bluetooth configuration. Stop the simulation with the start/stop button. Switch on your e-puck with the ON/OFF switch. Then, in the robot window, select your Bluetooth connection in the drop-down menu. Behind the e-puck, an orange LED should switch on. To finish press the start/stop button in order to run the program. Your e-puck should behave the same as in simulation.
Your Progression
Congratulation! You finished the first exercise and stepped into the world of robotics. You already learned a lot:
- What is a sensor, an actuator and a robot controller.
- What kind of problems a robot controller must be able to solve.
- What are the basic devices of the e-puck. In particular, the stepper motors, the LEDs, the IR sensors, the accelerometer and the camera.
- How to run your mobile robot both in simulation and in reality and what is a remote-control session.
- How to perform some basic operations with Webots.
Move your e-puck [Beginner]
You already learned what a robot controller is. In the following exercises you will create simple behaviors by using a graphical programming interface: BotStudio. This module is integrated in Webots. The aim of this exercise is to introduce BotStudio by discovering the e-puck's movement possibilities.
Open the World File
Similarly to the first exercise, open the following world file:
.../worlds/beginner_move_your_epuck.wbt
Two windows are opened. The first one is the simulation window that you know. You should observe a similar world as before except that the size of the board is twice as big. This is because an e-puck needs room for moving. The second window is the BotStudio window (see figure). If the BotStudio window does not open automatically, double-click on the robot in the simulation window to open it.
The "forward" State
A BotStudio window is composed of two main parts. The left part is a graphical representation of an automaton. You will learn to use this part and understand the automaton concept in the next exercise. The right part represents an e-puck in 2 dimensions. On this representation, you can observe the e-puck sensors values in real-time. Moreover, you can set the actuators commands. This interface has also a drop-down menu for choosing a Bluetooth connection in order to create a remote-control session. This menu is similar to the two drop-down menu of the robot window that you saw above. In top, there is a tool menu. This menu enables you to create, to load, to save or to modify an automaton. The last button (the upload button) executes your automaton on the e-puck.
In the BotStudio window, select the "forward" state (blue rectangle in the middle of the white area) just by clicking on it. A selected rectangle becomes yellow. In the right part of the BotStudio window, you can modify the actuator commands, i.e., the motors speed and the LEDs state. If you want to change the motors speed, click and drag the two yellow sliders. You can set this value between -100 and 100. 0 corresponds to a null speed, i.e., the wheel won't turn. A positive value should turn the wheel forward, and a negative one backwards. If you want to change the state of a LED, click on its corresponding gray circle (red -> on, black -> off, gray -> no modification).
Configure the "forward" state as follows: all the LEDs are alight, and the motors speeds are -30|30. Upload it on the virtual e-puck by clicking on the upload button. If the simulation is running, the virtual e-puck should change its actuators values accordingly. Note that when the simulation is launched, the right part of BotStudio displays the IR sensors.
The real e-puck's IR Sensors
The aim of this subsection is to create a remote-control session with your real e-puck. This part is similar to the subsection in previous exercise where you used the real robot. There are just two differences due to the fact that the BotStudio window is used instead of the robot window. For choosing the Bluetooth connection, there is just one drop-down menu instead of two. So, please select your Bluetooth connection instead of the simulation item on the top right part of the window. Then, you have to click on the upload button for starting the remote-control session.
Simple Behavior: Finite State Machine (FSM) [Beginner]
In the precedent exercise, you learned to configure a single state. One cannot speak about behavior yet because your robot doesn't interact with its environment, i.e., it moves but it hasn't any reaction. The goal of this exercise is to create a simple behavior. You will discover what an automaton is, how it is related to the robot controller concept and how to construct an automaton using BotStudio.
Finite State Automaton
A finite state automaton (FSM)[5] is a model of behavior. It's a possible way to program a robot controller. It's composed of a finite number of states and of some transitions between them. In our case, the states correspond to a configuration of the robot actuators (the wheels speed and the LEDs state), while the transitions correspond to a condition over the sensor values (the IR sensors and the camera), i.e., under which condition the automaton can pass from one state to another. One state is particularly important: the initial state. It's the state from where the simulation begins. During this curriculum, an automaton will have the same signification as an FSM.
BotStudio enables you to create graphically an automaton. When an automaton is created, you can test it on your virtual or real e-puck. You will observe in the following exercises that this simple way to program enables to create a large range of behaviors.
Open the World File and move Objects
Open the following world file:
.../worlds/beginner_finite_state_machine.wbt
This time, there are two obstacles. You can move an object (obstacle, e-puck or even walls) by selecting the desired object, and drag and drop it by pressing the shift key. The reverse button can be pressed when you want to reset the simulation.
Creation of a Transition
In the BotStudio window, create two states with the new state button. Name the first state ”forward” and the second one ”stop” by using the text box at right. You can change the position of a state by dragging and dropping the corresponding rectangle. Change the motors speed of these states (forward state -> motors speed: 45|45, stop state -> motors speed: 0|0). Now, you will create your first transition. Click on the new transition button. Create a link from the ”forward” state to the ”stop” state (the direction is important!). In this transition, you can specify under which condition the automaton can pass from the ”forward” state to the ”stop” state. Select this transition by clicking on its text field. It becomes yellow. Rename it to ”front obstacle”. By dragging the two highest red sliders, change the conditions values over the front IR sensors to have ”>5” for each of them. You should obtain an automaton as this which is depicted in the figure called "First automaton". Select the initial state (the ”forward” state) and test this automaton on your virtual e-puck by clicking on the upload button.
You finished your first collision avoidance algorithm, i.e., your e-puck doesn't touch any wall. This kind of algorithm is a good alternative to collision detection algorithm because a collision can engender a robot's degradation. Of course it isn't perfect, you can think about a lot of situations where your robot would still touch something.
U-turn
In this subsection, you will extend your automaton in order to perform a U-turn (a spin on itself of 180 degrees) after an obstacle's detection. Add a new state called ”U-turn” to your automaton. In this state, set the motors speed to 30|-30. Add a transition called ”timer1” from the ”stop” state to the ”U-turn” state. Select this transition. This time, don't change the conditions of the IR sensors but add a delay (1 [s]) to this condition by moving the yellow slider in the middle of the green circle. The figure called "The timer condition" depicts what you should obtain.
For performing a perfect U-turn, you still have to stop the e-puck when it turned enough. Add a new timer (”timer2”) transition from ”U-turn” state to ”forward” state (see next figure).
During this exercise you created an automaton step by step. But there are still several BotStudio tricks that are not mentioned above:
- For switching from ”bigger than” to ”smaller than” condition (or inversely) for an IR sensor, click on the gray part of an IR sensor slider.
- If you don't want to change the speed of a motor in a state, click on the yellow rectangle of the motor slider. The rectangle should disappear and the motors speed will keep its precedent value.
- If you want to remove a condition of a transition, set it to 0. The value should disappear.
- There is a slider which wasn't mentioned. This slider is related to the camera. You will learn more about this topic in exercise [sec:Line-following].
Your Progression
Thanks to the two previous exercises, you learned:
- What is an FSM and how it's related with a robot behavior
- How to use BotStudio
- How to design a simple FSM
The following exercises will train you to create an FSM by yourself.
Better Collision avoidance Algorithm [Beginner]
At this step, you know what an automaton is. Now, you will reinforce this knowledge through an exercise of parameters estimation. The structure of the automaton is given (the states and the transitions) but it doesn't contain any parameter, i.e., the actuators commands and the conditions over the sensors values aren't set. You will set these parameters empirically.
Open the World File
Open the following world file:
.../beginner_better_collision_avoidance_algorithm.wbt
You may have to increase the size of the BotStudio window to see the entire automaton.
Collision Avoidance Automaton
Note that you can store your automaton by clicking on the save as button in the BotStudio window. You can also load it by clicking on the load button.
The blinking e-puck [Beginner]
Until now, you just have modified existing automata. It is time for you to create them. In this practical exercise, you will design your own automaton by manipulating LEDs.
Open the World File
Open the following world file:
.../worlds/beginner_blinking_epuck.wbt
Maybe you should increase the size of the BotStudio window for seeing the entire automaton. In the simulation window, if you don't see all the LEDs, you can move the camera around the robot by left clicking. For this exercise, working directly on the real e-puck is more convenient.
Modify an Automaton
Create your own Automaton
A way to design an automaton is first to identify the possible actuators configurations, to create a state for each of these configurations, to set the parameters of these states, to establish the conditions to pass from a state to another, to create a transition for each of these conditions and finally to set the parameters of these conditions. Unfortunately it is not always so easy. For example, in an automaton, it's possible to have two states with identical actuators commands. Indeed, if you see somebody who is running across a street without any context, you don't know if he's running to catch a bus or if he's leaving a building in fire. He seems identical but it's internal state is different.
*E-puck Dance* [Beginner]
The goal of this exercise is to put the fire on the dance floor with your virtual e-puck by creating the e-puck dance. You can imagine dance as a succession of movements with the same rhythm. You will be able to model that easily in a finite state automaton.
Open the World File
Open the following world file:
.../worlds/beginner_epuck_dance.wbt
This opens a disco dance floor. Moreover, there is already a very little example of what you can achieve. I hope you will find a better e-puck dance than the existing one.
Imagine your Dance
Line following [Beginner]
The goal of this exercise is to explore the last device available in BotStudio: the camera. With the e-puck camera, you can obtain information about the ground in front of it. BotStudio computes ”in real time” the center of the black line in front of the e-puck. The camera is another e-puck sensor and the center of the front line is the sensor value of this camera.
A linear Camera
An e-puck has a camera in front of it. Its resolution is 480x640. For technical issues it has a width of 480 and a height of 640. The most important information for following a line is the last line of the camera (see the figure called "The field of view of the linear camera"). For this reason, only the last line of the camera is sent from the e-puck to Webots. Finally an algorithm is applied on this last line in order to find the center of the black line.
The problem is that the e-puck sees only at about 5.5 cm in front of it, and sees a line of about 4.5 cm of width. Moreover, this information is refreshed about 2 times per seconds. It is little information!
Open the World File
Open the following world file:
.../worlds/beginner_linear_camera.wbt
This opens a long world. A black line is drawn on the ground. Remark that there is a grain (Gaussian noise) on the e-puck camera values in order to be more realistic. Indeed, a real camera doesn't acquire perfect values. Some noise is always present on a real camera, it comes from several factors.
Line following Automaton
In the BotStudio interface, you will also find a condition over the camera (figure called "The linear camera condition in BotStudio") represented by a slider. The value represents the center of the black line in front of the robot. When a transition is selected, you can change the condition over the camera by dragging the slider, and you can change the direction of the test by clicking on the text field (ex: ”<5” becomes ”>5”). Remark that if there is no line in front of the robot, the center value can be wrong.
Rally [Beginner] [Challenge]
Open the following world file:
.../worlds/beginner_rally.wbt
Notes
- ↑ More information on: Stepper motor
- ↑ More information on: Led
- ↑ More information on: Accelerometer
- ↑ Noise is an unwanted perturbation. More information on : Noise
- ↑ Source and more information on : Finite state automaton