0% found this document useful (0 votes)
60 views

Artificial Life - Robotics Tutorials

This document provides an overview of tutorials for programming robots and simulating artificial life using the Webots simulation software. It covers getting started with Webots, programming robots using sensors and actuators, building new worlds and robots, and programming more advanced robots like the e-Puck to demonstrate behaviors like obstacle avoidance and following objects of a certain color. Exercises are provided throughout to reinforce skills like reading sensor values, driving actuators to move robots, and developing behaviors using techniques like Braitenburg vehicles and behavior arbitration.

Uploaded by

ronoroa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Artificial Life - Robotics Tutorials

This document provides an overview of tutorials for programming robots and simulating artificial life using the Webots simulation software. It covers getting started with Webots, programming robots using sensors and actuators, building new worlds and robots, and programming more advanced robots like the e-Puck to demonstrate behaviors like obstacle avoidance and following objects of a certain color. Exercises are provided throughout to reinforce skills like reading sensor values, driving actuators to move robots, and developing behaviors using techniques like Braitenburg vehicles and behavior arbitration.

Uploaded by

ronoroa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Artificial Life – Robotics Tutorials

Artificial Life – Robotics Tutorials

1.  Getting Started


2.  Programming in Webots
3.  Building new worlds and new robots
4.  More Programming – Sensors and Actuators
5.  Programming the simpleBot for a simple following behaviour
6.  Adding a more sophisticated sensor
7.  Using the ePuck
8.  Programming the ePuck for simple obstacle avoidance
9.  Programming the ePuck for simple ‘Taxis’
10.  Using arbitration to choose behaviours

11.  Programming the ePuck for obstacle avoidance using potential fields
12.  Adding ‘colour’taxis using potential fields
13.  Combining potential fields

14.  Transfer and testing on the Real EPuck


15.  Fixing problems with the real EPuck
16.  Proportional control, thrashing, PID, hysteresis, dead zones

17.  The Trashcan Competition


Artificial Life – Robotics Tutorials

Getting Started – Objective: Familarity with Webots (User Guide Chapters 1-4½)‫‏‬

1.  Click on the Webots icon!


2.  Close all windows except main display window
3.  Click on main display window
4.  Click the ‘open file’ icon

5.  Navigate to:

D:/ProgramFiles/Webots

1.  Navigate to:


/projects
1.  Navigate to:
/samples
1.  Navigate to:
/mybot
Artificial Life – Robotics Tutorials

Getting Started – continued….

Webots has two concepts:

The World - simulates the world and the robot


The Controller - code for controlling the robot

To simulate a robot in Webots load its world model.

1.  Navigate to:


/worlds

1.  Click on:


mybot.wbt
Artificial Life – Robotics Tutorials

Getting Started – continued….

4 windows appear:

Console - logs important information


Code Editor - code editor for creating and compiling controllers
Scene Tree Editor - Editor for creating the world
Webots Simulator - Simulator itself

1.  Close all windows except the Webots Simulator


2.  Play around with the mouse controls to manipulate the viewing position
of the world
3.  Shift-Click on the mouse to manipulate and move objects around

1.  Click on the run button


Notice the timing display in the bottom right hand corner – shows how fast the simulator is
running compared to real time
Artificial Life – Robotics Tutorials

Getting Started – continued….

1.  Click on the stop button


2.  Click on the ‘Simulation’ menu item

This duplicates the icon controls

1.  Click on ‘fast’ and watch the timing control


2.  Click on stop
3.  Click on the robot
4.  Click on the ‘view’ menu item
5.  Explore the different view options

1.  Shift click on the robot and select ‘follow object’


Camera now follows the robot
Artificial Life – Robotics Tutorials

Getting Started – continued….

1.  Click on the ‘tools’ menu item


2.  Click on the ‘Preferences’
•  Click on ‘general’ tab
•  Always choose ‘startup mode’ as ‘stop’ and click ‘ok’

•  Click on the ‘save’ button


EXERCISE 1:
Open up and play with some of the other worlds in the
Webots Projects directory and the
Webots samples directory.
Artificial Life – Robotics Tutorials

Programming In Webots - C code version

Create a local directory to hold your own worlds and controllers

•  Click on the ‘Wizard’ menu item


•  Click on the ‘New Project Directory’

1.  Create a controller program template in C


2.  On ‘Wizard’ click ‘new Robot controller
3.  Build the controller

•  Copy the myBot world from webots to your world directory and rename it
(including the ‘textures’ directory).
•  Edit the new world and change the controller entry to your controller.
•  Open your world in Webots and make sure that your controller is active.
Artificial Life – Robotics Tutorials

Programming In Webots – continued…..

EXERCISE 2:
Edit the program and type in some ‘printf’ messages at key points in the execution.
Compile, link and execute the code and check the results in the DOS console.
Example printf: printf(“In reset function….\n”);

Note: you may need to add an include statement


#include <stdio.h>
Artificial Life – Robotics Tutorials

Robot Controllers and Supervisor Controllers

A robot controller – can use C,C++,Python or Java -> controls one robot

A supervisor controller – can use C or C++ –> controls the world and one or more robots
Artificial Life – Robotics Tutorials

New Worlds and New Robots

Click on ‘Scene Tree’ in the ‘Tools’ menu


Examine:
WorldInfo
Viewpoint
Transform
Walls
Solids

And finally

Differential Wheels

Use the menu options to get documentation.


Artificial Life – Robotics Tutorials

Programming In Webots – continued…..


How to Get information from the sensors
Add the ‘include’ file for the particular sensor
e.g.
#include <webots/distance_sensor.h>

Add some device ‘handles’ or pointers globally:


e.g. in the ‘main’ function

wb_robot_init(); /* necessary to initialize webots stuff */

/* Get and enable the distance sensors. */


WbDeviceTag ir0 = wb_robot_get_device("ir0");
WbDeviceTag ir1 = wb_robot_get_device("ir1");

Now enable the sensors:


e.g. add:

wb_distance_sensor_enable(ir0, TIME_STEP);
wb_distance_sensor_enable(ir1, TIME_STEP);
Artificial Life – Robotics Tutorials

Programming In Webots – continued…..


How to Get information from the sensors – continued…..

/* Get distance sensor values */

double ir0_value = wb_distance_sensor_get_value(ir0);


double ir1_value = wb_distance_sensor_get_value(ir1);

Now print the values to the console: Now compile code,


Fix errors,
e.g. In the run function add: Revert,
And run
printf("ir0: %f ir1: %f \n",ir0_value, ir1_value);
Move an obstacle in
front of the robot to test
Artificial Life – Robotics Tutorials

Programming In Webots – continued…..


How to Drive the Actuators (wheels in this case)‫‏‬
Add the ‘include’ file for the particular actuator
e.g.
#include <webots/differential_wheels.h>

Define a default speed:

#define DEFAULT_SPEED 60;


In the ‘main’ function create some wheel speed variables
e.g. Now compile code,
double left_speed, right_speed; Fix errors,
Revert,
Give them some default values: And run
left_speed = DEFAULT_SPEED;
right_speed= -DEFAULT_SPEED ; // make the robot spin

In the ‘run’ function set the wheel speed


e.g.
wb_differential_wheels_set_speed(left_speed, right_speed);
Artificial Life – Robotics Tutorials

Programming In Webots – continued…..

EXERCISE 4:
•  Modify the sensor reading/actuator setting code to create a robot which avoids
obstacles.

•  Take some inspiration from your previous lectures/tutorials on Braitenburg


vehicles.
Artificial Life – Robotics Tutorials

Programming In Webots – continued…..

EXERCISE 5:
•  Modify the sensor reading/actuator setting code to create a robot which
follows obstacles but otherwise stays still.
•  Use the devC++ development system to do this

Now we will use a more sophisticated sensor – a camera

Load up camera.wbt from

c:\Program Files\Webots\projects\samples\devices\worlds

EXERCISE 6:

• Play with the simulation and study the controller code (and the webots documentation).

• Work out what you need to do to detect colour blobs

• Change the controller to allow the robot to follow a red block.


Artificial Life – Robotics Tutorials

Programming The Epuck Robot

1.  Create a controller program template in C++ from the saved controller
i.e. copy webotsTemplate.cpp to joesEpuck.cpp

•  Copy the e-puck.wbt world from webots to your


world
directory and rename it (e.g. joesEpuck.wbt) also copy the textures directory
•  Edi
t
th
e
new world and change the controller entry to your controller (i.e. joesEpuck)‫‏‬
•  Open your
world in
Webots and make sure that your controller is active (by adding some printf’s)‫‏‬
EXERCISE 7.
Artificial Life – Robotics Tutorials

Programming The Epuck Robot

EXERCISE 8.
Create an simple obstacle avoidance behaviour for the Epuck

EXERCISE 9.
Create some simple ‘taxis’ behaviour for the Epuck
e.g. this could an attraction to the red block and and repulsion from the green
block

EXERCISE 10.
Combine your behaviours using simple priority based arbitration.
Use either an ‘if –then’ construct or (more advanced) a mechanism which yields
control to the particular behaviour (hint: create each behaviour as a class
which if its ‘releasers’ are met becomes available for execution, keep the
classes in an array, highest first and loop through the array).
Artificial Life – Robotics Tutorials

Programming the ePuck for obstacle avoidance using potential fields

1.  Copy your existing EPuck controller to a new controller.


2.  Copy your existing EPuck world to a new world.
3.  Rename the world controller, compile, link, revert and test.

EXERCISE 11 – normalising the sensors


Modify your program to print the values of the (8) IR sensors.
Write some code to normalise these values (hint: put the high and low
values as #defines so that they can be altered when we use the real
EPuck).
Rename the world controller, compile, link, revert and test.
Artificial Life – Robotics Tutorials

Programming the ePuck for obstacle avoidance using potential fields

The vector library:

Supplied is a vector class library to help. Use as follows:

To create a vector: CVector newVector(100,97);

Will create a vector of magnitude 100 and angle 97 degrees.

Adding vectors:

CVector sumV;
CVector anotherVector(200,67);

sumV = newVector +anotherVector;

Get the result:

Printf”Amgle: %f Mag: %f\n”, sumV.getDirection(),sumV.getMagnitude());


Artificial Life – Robotics Tutorials

Programming the ePuck for obstacle avoidance using potential fields

1.  Measure angles of sensors on real Epuck.


2.  Set up a list of vectors (8), with these angles and values of distance sensor
3.  Compute sum of above
4.  Use the new angle/magnitude to control the actuators

70 110
140
40

0 180

Sensor
300 240
angles
// create a set of 2 element vectors

CVector lv[8];

// fill with light sensor values and physical angle of sensor on robot

lv[0].setValues(ds_value[0],110);
lv[1].setValues(ds_value[1],140);
lv[2].setValues(ds_value[2],180);
lv[3].setValues(ds_value[3],240);
lv[4].setValues(ds_value[4],300);
lv[5].setValues(ds_value[5],0);
lv[6].setValues(ds_value[6],40);
lv[7].setValues(ds_value[7],70);

// create a resultant vector

CVector res;

for (int i=0;i<8;i++)‫‏‬


{
res = res + lv[i];
}

int direction = (int) res.getDirection();


int magnitude = (int) res.getMagnitude();

printf("Direction and magnitude of object: %f %f\n",res.getDirection(),res.getMagnitude());

EXERCISE 12:
Implement and test the EpuckVector.wbt world.
Artificial Life – Robotics Tutorials

Colour Blob Tracking using the Epuck Camera

The Epuck camera takes picture images.

These are returned as arrays of pixels – the array size depends on how the
camera is configured.

For a 10 (width) * 6 (height) camera – 600 pixels will be returned.

You can get the width and height using the following webots functions:

width = camera_get_width(camera);
height = camera_get_height(camera);

To obtain the image:

image = camera_get_image(camera);

(See EpuckBlob.wbt)‫‏‬
Artificial Life – Robotics Tutorials

Colour Blob Tracking using the Epuck Camera

Each pixel is returned as a three element code (3 integers).

The code is called RGB meaning red/green/blue.

Each integer can have a value between 0 and 255.

For more ‘redness’ the first integer would have a higher value.
For more ‘blueness’ the second integer would have a higher value.
For more ‘greenness’ the third integer would have a higher value.
Black is 255,255,255 and white is 0,0,0
To get the RGB values do the following:

for (int x = 0; x < width; x++) {


for (int y = 0; y < height; y++) {
red = camera_image_get_red(image, width, x, y);
green = camera_image_get_green(image, width, x, y);
blue = camera_image_get_blue(image, width, x, y);
}}
Artificial Life – Robotics Tutorials

Colour Blob Tracking using the Epuck Camera

To check for a red blob simply count the number of pixels in the
image that have more redness and compare that to the number of
pixels that have greeness or blueness.

If there is more redness then the camera can probably see something
red.

EXERCISE 13:

Implement and review the EpuckBlob.wbt world and try to understand how
the RGB system works.
Artificial Life – Robotics Tutorials

Using the Real Epuck

1.  Turn on the EPuck


2.  Find the rotation switch and switch to position 0.

On/Off

Reset
Position 0

Switch

EXERCISE 14:
Check out the other rotation positions for each internal program
Artificial Life – Robotics Tutorials

Using the Real Epuck – Connecting via Bluetooth

1.  Find the rotation switch and switch to position 0.


2.  Click on “My Bluetooth Places” and “View devices in Range” - see if the
robot appears
3.  Connect to the robot by entering the pin code on the front of the robot.
4.  Check that the Epuck is working by running the EPuck monitor program.

EXERCISE 15:
Play with the EPuck functions and camera options using the EPuck
monitor
Artificial Life – Robotics Tutorials

Using the Real Epuck – Connecting via Webots

1.  Find the rotation switch and switch to position 0.


2.  Start up Webots and load the Epuck.wbt world
3.  Double click on the simulated Epuck.
4.  Choose remote control.
5.  Run the control program on Webots

EXERCISE 16:
Experiment with the real Epuck to see why it doesn’t work exactly as the
simulated version.

EXERCISE 17:
Implement a proportional controller on the simulated Epuck e.g. the nearer
the obstacle the faster the Epuck rotates. Transfer to the real Epuck and
see if you experience thrashing, hysterisis and dead zones. Code to
‘solve’ these issues.
Artificial Life – Robotics Tutorials
EXERCISE 18: TRASHCAN COMPETITION

• You should now have enought code samples and Webots experience to attempt a
competition.
• The competition is based on the subsumption architecture outlined in Robin Murphy's
book (Introduction to AI robotics) for the Trashcan competition.
• Here we will use the following: A world containing 1 red block, 1 green block and 2 yellow
blocks (as myEpuckBlob.wbt).

Rules
• Epuck starts at green block.
• Epuck searches for yellow blocks. When very close to a yellow block all led's are set on
(indicating that a yellow block has been found).
• Epuck searches for red block. When very near the red block all leds turned off (indicating
that trashcan has been found). <Yellow block removed manually>
• Repeat above for second yellow block.
• When finished return to green block.

Approach
• Ideally some for of arbitration architecture between behaviours should be implemented.
However, this could be simply a set of if-then statements.
• You can work individually or in groups.
• The potential fields approach and the blob tracking code samples may be useful,
pick and choose (or use a simpler solution) as you wish.

You might also like