Writing your first controller
In this section, we will write our first controller for the mobile robot. We have seen how the controllers handle the motion of the robot and its reaction to the sensors. Let's change the controller of the E-puck
robot to move some fixed directions. We can choose different programming languages for our controller; however, we will use C++. The goal of the new controller is to command the velocity of the wheels of the robot to show the typical structure of a Webots controller.
The first thing to do is to change the controller associated with our mobile robot. Note that each robot can use only one controller at once. Conversely, we can associate the same controller with different robots. To write our new controller, we must follow these steps:
- Create a new controller file.
- Write a new controller.
- Compile the new controller.
- Change the default controller of the robot with the new one in the robot properties panel.
As already...