Cyberbotics' Robot Curriculum/Intermediate programming Exercises

From Wikibooks, open books for an open world
Jump to: navigation, search

In the previous chapter, you learned to manipulate the e-puck devices in detail by using the C programming. You have now the technical background to start this new chapter about the robotic behavior. Different techniques will be used to program the e-puck behavior. Notably, you will see that your robot has a memory.

Program an Automaton [Intermediate][edit]

During this exercise, you will convert an FSM of the chapter Beginner programming Exercises in the C programming. First, a simple example will be given, a new version of the exercise Simple Behavior: Finite State Machine. Then, you will create your own FSM. It will be a new version of the exercise Better Collision avoidance Algorithm.

Open the World File[edit]

Open the following world file:


You should observe the same world as in the section Simple Behavior: Finite State Machine.

An Example of FSM[edit]

According to the figure Sensors_to_actuators_loop.png, the main loop of your program should always execute its instructions in the following order:

  1. Obtain the sensor values
  2. Treat these values according to the expected behavior
  3. Sends commands to the actuators

In our case, the behavioral part of the robot is modeled using an FSM.

Question.svg [Q.1] Locate in the given C programming code where are these 3 points. Explain what operations are performed in each of these points.

Question.svg [Q.2] Describe how the FSM is implemented, i.e., how the current state is modeled, which control structure is used, what kind of instructions are performed in the states, what are the conditions to switch from a state to another, etc.

Create your own FSM[edit]

Auto Racing Chequered.svg [P.1] By using an FSM, implement a wall following algorithm. (Hint: start to design the structure of the automaton and then find how the transitions are fired and finally set up parameters empirically.)

*Lawn mower* [Intermediate][edit]

In this optional exercise, you will discover another topic of the robotic: the exhaustive research, i.e., your e-puck will move on a surface having an unknown shape, and will have to pass by every place. A cleaning robot or an automatic lawn mower is a typical application of this kind of movement. There are different ways to treat this topic. This exercise presents two of them: the random walk and the walk ”by scanning”.

The random Walking[edit]

Open the following world file:


You should see a grassy board with a white hedge. For the moment, the robot controller is the same as this of the previous exercise, i.e., a simple FSM which lets return your e-puck when it meets a wall. In this subsection, you will create a random walk.

When your e-puck meets a wall, it must spin on itself and go in another direction as depicted in figure below. The next figure depict a possible automaton for a random walk.

For generating a random integer between 0 and X, import the standard library (#include <stdlib.h>) and the time library (#include