Do you want to learn robot, but you don’t have money to buy the robot? Or you don't know where to start?
Webots simulator is the solution! You can learn with any kind of robots and environments easily. Also you can create your custom robots and environment. The most interesting is Webots is free and open source.
Here we will discuss about Webots, and create our first robot program to make it move. The robot program is implemented to e-puck robot.
I have used Webots to help my friend in her thesis to develop obstacle avoidance algorithms in Niching Particle Swarm Optimization algorithms for multi-target search multi-robot system. Robots is locate in a search area. Then the robots move to search for a targets. With Niching Particle Swarm Optimization, robots is sharing their best location related to possible target location, so robots can find the best possible target location. In this simulation, we used 40 robots, and 4 targets.
My experience in developing this project using Webots is it's very easy to learn and use, complete tools, and realistic. Also I don't need to spend any money to buy real robots 😎
I will discuss about this project soon.
Official website: https://cyberbotics.com
Webots is an open source robot simulator that provides a complete development environment to model, program and simulate robots. Thousands of institutions worldwide use it for R&D and teaching. Webots has been codeveloped by the Swiss Federal Institute of Technology in Lausanne, thoroughly tested, well documented and continuously maintained since 1996. It is the most efficient solution to quickly get professional results. [Reference]
You can write the webots robot controller using C++, Java, Python or MATLAB. Choose any kind of your favourite programming language.
Webots GUI is composed of four principal windows:
Webots has provide a great and clean user guide. Also there is a tutorial that you can learn.
Official website: https://e-puck.org
Wiki: https://www.gctronic.com/doc/index.php/e-puck2
The e-puck robot is a mini mobile robot developed by GCtronic and EPFL. The e-puck robot is designed and has been widely used in research and educational purposes and is easy to use [Reference].
e-puck has been a very successful robot since 2005. About 3000 units used both in education and research. From January 2018 version 2 is available [Reference].
The e-puck robot is a non-holonomic wheeled robot. Non-holonomic wheeled robot is a robot that depends on the path it can reach to move and cannot move in all directions [Reference], different from the holonomic wheeled robot that can move in all directions [Reference] without changing its orientation. Therefore, if the e-puck robot wants to move to a different direction, the e-puck robot must rotate its body first to face that location.
Here I create a simple tutorial to create the environment, add obstacle, add e-puck robot, and create the e-puck robot program to make the robot move forward.
Before, install Webots on your computer from this tutorial. I use Webots version 2019b.
Select the last node “RectangleArena” of the scene tree view. Click on the Add button (plus sign) at the top of the scene tree view. In the dialog box, choose “PROTO nodes (Webots) / robots / gctronic / e-puck / E-puck (Robot)”, then click “Add”. An e-puck robot should appear in the middle of the arena. Save the simulation.
3. Centering the Arena
We want to look the arena from above to make it clearly visible. You can rotate the arena in X, Y, or Z axis by “hold left click” and “move the cursor”. You can move the arena by “hold right click” and “move the cursor”. You can zoom-in or zoom-out by “scrolling your mouse up or down”.
Here I give you my setting to make the arena looked from above. Double-click on the “Viewpoint” node in the scene tree. This should open the node and display its fields. Select the “orientation” field and set its “angle” value to 1.58. Select the “position” field and set its “x” value to -0.034, “y” value to 2.2365, and “z” value to -0.023.
Below is the environment look:
4. Add Obstacles
Adding obstacles in this scenario is optional. I added the obstacles just to make the simulation look more real, and just for fun 😄
Below is the environment look:
5. Create e-puck robot controller
Below is your controller source code look:
6. Edit your controller program
You can edit the controller from webots built in text editor. Or you can edit with your favourite IDE. The controller directory is placed in “[your project directory]/controllers”. The program is placed inside this controller directory.
Here is the move forward source code, or you can view it on my from GitHub Repository. Copy and paste the source code to your controller program.
/*
* Copyright 2019 Albert Alfrianta
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* Created on: 2019-09-16, Bogor, Indonesia
*
* Contact: [email protected] or https://www.linkedin.com/in/albert-alfrianta/
*
* Description:
* Simple e-puck robot program to make the robot move forward
* Written in C programming language
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <webots/device.h>
#include <webots/distance_sensor.h>
#include <webots/led.h>
#include <webots/motor.h>
#include <webots/nodes.h>
#include <webots/robot.h>
int time_step;
/* Motor device */
static WbDeviceTag left_motor, right_motor;
/* E-puck angular speed in rad/s */
#define MAX_SPEED 6.28
/* function to get simulator time step */
static int get_time_step() {
static int time_step = -1;
if (time_step == -1)
time_step = (int)wb_robot_get_basic_time_step();
return time_step;
}
/* function to set motor velocity to move forward */
static void move_forward() {
wb_motor_set_velocity(left_motor, MAX_SPEED);
wb_motor_set_velocity(right_motor, MAX_SPEED);
}
/* function to init robot stuff */
static void init_robot() {
// get simulator time step
time_step = get_time_step();
// get a handler to the motors and set target position to infinity (speed control)
left_motor = wb_robot_get_device("left wheel motor");
right_motor = wb_robot_get_device("right wheel motor");
wb_motor_set_position(left_motor, INFINITY);
wb_motor_set_position(right_motor, INFINITY);
wb_motor_set_velocity(left_motor, 0.0);
wb_motor_set_velocity(right_motor, 0.0);
}
/* main function */
int main(int argc, char **argv) {
/* necessary to initialize webots stuff */
wb_robot_init();
init_robot();
/* main loop
* Perform simulation steps of TIME_STEP milliseconds
* and leave the loop when the simulation is over
*/
while (wb_robot_step(time_step) != -1) {
/*
* move the robot forward
* */
move_forward();
};
/* Enter your cleanup code here */
/* This is necessary to cleanup webots resources */
wb_robot_cleanup();
return EXIT_SUCCESS;
}
Then click “Build” menu, then click “Build” submenu. Make sure that your controller program is open in webots text editor before build.
The important things about this program:
Program Flow:
7. Setting e-puck robot controller
Double-click on the “E-puck” node in the scene tree. This should open the node and display its fields. Select the “controller” field, then click select, then choose your controller name (here my controller name is “e-puck-move_forward”).
8. Play it
Above the 3D window, click play button to run the simulation in real-time). If the simulation is run, then this button is turn into pause button. Click this pause button if you want to pause the simulation.
The simulation is look like below:
9. Lastly
Don’t forget to save your world by click the save button or by menu “File -> Save World”.
When a Webots world is modified with the intention of being saved, it is fundamental that the simulation is first paused and reloaded to its initial state, i.e. the virtual time counter on the main toolbar should show 0:00:00:000. Otherwise at each save, the position of each 3D object can accumulate errors. Therefore, any modification of the world should be performed in that order: pause, reset, modify and save the simulation
You can download this project from my GitHub. Simply download it, and run it in your webots.
Please read this tutorial to advance your knowledge.
Stay tuned for more tutorial.
Give response if you like or if you have any advice.
Contact me if you have any question at my LinkedIn
Thank you!