Sie sind auf Seite 1von 62

The Islamia University of Bahawalpur

Department of Computer Systems Engineering

Introduction to Robotics
Lab Manual

Submitted To:

Dr. Nadia Rasheed Rao

Submitted By:

Fawad Hassan Jaskani (13CS34)

1
LAB 1
Introduction to Webots
Webots is a professional mobile robot simulation software package. It offers a rapid prototyping
environment that allows the user to create 3D virtual worlds with physics properties such as mass,
joints, friction coefficients, etc. The user can add simple passive objects or active objects called
mobile robots. These robots can have different locomotion schemes (wheeled robots, legged
robots, or flying robots). Moreover, they may be equipped with a number of sensor and actuator
devices, such as distance sensors, drive wheels, cameras, motors, touch sensors, emitters,
receivers, etc. Finally, the user can program each robot individually to exhibit the desired behavior.
Webots contains a large number of robot models and controller program examples to help users
get started.
Webots also contains a number of interfaces to real mobile robots, so that once your simulated
robot behaves as expected, you can transfer its control program to a real robot like e-puck,
DARwIn-OP, Nao, etc. Adding new interfaces is possible through the related system.

Webots Application:

Webots is well suited for research and educational projects related to mobile robotics. Many mobile
robotics projects have relied on Webots for years in the following areas:

2
 Mobile robot prototyping (academic research, the automotive industry, aeronautics, the
vacuum cleaner industry, the toy industry, hobbyists, etc.)
 Robot locomotion research (legged, humanoids etc.)
 Multi-agent research (swarm intelligence, collaborative mobile robots groups, etc.)
 Adaptive behavior research (genetic algorithm, neural networks, AI, etc.).
 Teaching robotics (robotics lectures, C/C++/Java/Python programming lectures, etc.)
 Robot contests (e.g. www.robotstadium.org or www.ratslife.org)

To use Webots:
You will need a minimal amount of technical knowledge to develop your own simulations:

 A basic knowledge of the C, C++, Java, Python or MATLAB programming language is


necessary to program your own robot controllers. However, even if you don't know these
languages, you can still program the e-puck and Hemisson robots using a simple graphical
programming language called BotStudio.
 If you don't want to use existing robot models provided within Webots and would like to
create your own robot models, or add special objects in the simulated environments, you will
need a basic knowledge of 3D computer graphics and VRML97 description language. That
will allow you to create 3D models in Webots or import them from 3D modelling software.

Webots simulation:
A Webots simulation is composed of following items:

1. A Webots world file (.wbt) that defines one or several robots and their environment. The
.wbt file does sometimes depend on external PROTO files (.proto) and textures.
2. One or several controller programs for the above robots (in C/C++/Java/Python/MATLAB).
3. An optional physics plugin that can be used to modify Webots regular physics behavior (in
C/C++).

World:
A world, in Webots, is a 3D description of the properties of robots and of their environment. It
contains a description of every object: position, orientation, geometry, appearance (like color or
brightness), physical properties, type of object, etc. Worlds are organized as hierarchical structures
where objects can contain other objects (like in VRML97). For example, a robot can contain two
wheels, a distance sensor and a joint which itself contains a camera, etc. A world file doesn't
contain the controller code of the robots; it only specifies the name of the controller that is required
for each robot. Worlds are saved in ".wbt" files. The ".wbt" files are stored in the "worlds"
subdirectory of each Webots project.

Controller:

3
A controller is a computer program that controls a robot specified in a world file. Controllers can
be written in any of the programming languages supported by Webots: C, C++, Java, Python or
MATLAB. When a simulation starts, Webots launches the specified controllers, each as a separate
process, and it associates the controller processes with the simulated robots. Note that several
robots can use the same controller code, however a distinct process will be launched for each
robot.
Some programming languages need to be compiled (C and C++) other languages need to be
interpreted (Python and MATLAB) and some need to be both compiled and interpreted (Java). For
example, C and C++ controllers are compiled to platform-dependent binary executables (for
example ".exe" under Windows). Python and MATLAB controllers are interpreted by the
corresponding run-time systems (which must be installed). Java controller need to be compiled to
byte code (".class" files or ".jar") and then interpreted by a Java Virtual Machine.
The source files and binary files of each controller are stored together in a controller directory. A
controller directory is placed in the "controllers" subdirectory of each Webots project.

Supervisor:
The Supervisor is a privileged type of Robot that can execute operations that can normally only be
carried out by a human operator and not by a real robot. The Supervisor is normally associated
with a controller program that can also be written in any of the above mentioned programming
languages. However, in contrast with a regular Robot controller, the Supervisor controller will have
access to privileged operations. The privileged operations include simulation control, for example,
moving the robots to a random position, making a video capture of the simulation, etc.

4
5
6
Successfully Installed Pro-Version

Teacher’s Signature:_________________
Remarks: ________________________
7
LAB 2
Webots Installation

Installation procedure
Usually, you will need to have system administrator rights to install Webots. Once installed, Webots
can be used by a regular, unprivileged user. To install Webots, please follow this procedure:

1. Uninstall completely any old version of Webots that may have been installed on your
computer previously.
2. Install Webots for your operating system as explained below.

Note: After installation, the most important Webots features will be available, but some third
party tools (such as Java, Python or MATLAB) may be necessary to run or compile specific
projects.

Installation on linux
Webots will run on most recent Linux distributions running glibc2.11.1 or earlier. This includes fairly
recent Ubuntu, Debian, Fedora, SuSE, RedHat, etc. Webots comes in two different package
types: .deb and .tar.bz2 (tarball). The .deb package is aimed at the latest LTS Ubuntu Linux
distribution whereas the tarball package includes many dependency libraries and it is therefore
best suited for installation on other Linux distributions. These packages can be downloaded
from website.
Note: Some of the following commands requires the root privileges. You can get these
privileges by preceding all the commands by the sudo command.

Note: Webots will run much faster if you install an accelerated OpenGL drivers. If you have a
NVIDIA or AMD graphics card, it is highly recommended that you install the Linux graphics
drivers from these manufacturers to take the full advantage of the OpenGL hardware
acceleration with Webots.

Note: Webots needs the avconv program to create MPEG-4 movies, that can be installed
with libav-tools, libavcodec-extra-54, and libfdk-aac0 packages.

Using Advanced Packaging Tool (APT)


The advantage of this solution is that Webots will be updated with the system updates. This
installation requires the root privileges.

8
First of all, you may want to configure your APT package manager by adding the Cyberbotics
repository. Simply execute the following lines:

apt-add-repository 'deb http://www.cyberbotics.com/debian/ binary-


amd64/'apt-get update

As an alternative, you can easily add the Cyberbotics repository from the Software and
Updates application. In the Other Software tab, click on the Add... button and copy the following
line:

deb http://www.cyberbotics.com/debian/ binary-amd64/

When you will close the window, the APT packages list should be automatically updated. Otherwise
you can manually execute the following command:

apt-get update

Optionally, Webots can be autentified thanks to the Cyberbotics.asc signature file which can be
downloaded here, using this command:

apt-key add /path/to/Cyberbotics.asc

Then proceed to the installation of Webots using:

apt-get install webots

Note: This procedure can also be done using any APT front-end tools such as the Synaptic
Package Manager. But only a command line procedure is documented here.

From the tarball package


This section explains how to install Webots from the tarball package (having
the .tar.bz2 extension). This package can be installed without the rootprivileges. It can be
uncompressed anywhere using the tar xjf command line. Once uncompressed, it is
recommended to set the WEBOTS_HOME environment variable to point to the webots directory
obtained from the uncompression of the tarball:

tar xjf webots-8.5.3-x86-64.tar.bz2

and

9
export WEBOTS_HOME=/home/username/webots

The export line should however be included in a configuration script like "/etc/profile", so that it is
set properly for every session.
Some additional libraries are needed in order to properly run Webots. In particular libjpeg62, libav-
tools, libpci3 and libavcodec-ffmpeg-extra56 have to be installed on the system.
Note: On old versions of Ubuntu (before 16.04) libpci3 should be replaced
by libpci and libavcodec-ffmpeg-extra56 by libavcodec-extra-54.

From the DEB package


This procedure explains how to install Webots from the DEB package (having the .deb extension).
On Ubuntu, double-click on the DEB package file to open it with the Ubuntu Software App on
Ubuntu 16.04 or Software Center on earlier versions and click on the Install button. If a previous
version of Webots is already installed, then the text on the button could be different,
like Upgrade or Reinstall. Note that GNOME Software App distributed in the first release of
Ubuntu 16.04 contains a bug preventing the installation of third-party packages.
Alternatively, the DEB package can also be installed using apt or gdebi with the root privileges:

apt install ./webots_8.5.3_amd64.deb

or

gdebi webots_8.5.3_amd64.deb

Installation on Windows

1. Download the "webots-8.5.3_setup.exe" installation file from website.


2. Double click on this file.
3. Follow the installation instructions.

It is possible to install Webots silently from an administrator DOS console, by typing "webots-
8.5.3_setup.exe /SILENT" or "webots-8.5.3_setup.exe /VERYSILENT"
If you observe 3D rendering anomalies or if Webots crashes, it is strongly recommend to upgrade
your graphics driver.

Installation on Mac OS X

1. Download the "webots-8.5.3.dmg" installation file from https://www.cyberbotics.com.

10
2. Double click on this file. This will mount on the desktop a volume named "Webots"
containing the "Webots" folder.
3. Move this folder to your "/Applications" folder or wherever you would like to install Webots.
4. It is recommended to increase the size of the system shared memory in order to run
simulations with more than 8 camera or display devices (such as the PR2 robot). In order to
proceed, edit the following file from the Terminal application as administrator: sudo pico
/etc/sysctl.conf. It is likely this file doesn't exist on your system, in which case an empty
file will be created. Edit this file so that it contains the lines:

kern.sysv.shmmax=16777216

kern.sysv.shmmin=1

kern.sysv.shmmni=128

kern.sysv.shmseg=32

kern.sysv.shmall=4096

These settings increase the amount of shared memory to four times the usual default. The current
values are provided by the following command line: sysctl -A | grep sysv.shm. Please refer to
the Mac OS X documentation to understand the exact meaning of each value. You will have to
reboot your computer so that these changes are taken into account.

Mac OS X security
During the first Webots launch, Mac OS X may complain about opening Webots because it is from
an unidentified developer (see figure).

11
In this case, Ctrl + click (or right-click) on the Webots icon, and select the Open menu
item. Mac OS X should propose to open the application anyway.

Tasks:
 Install Webots on windows system.
 Capture Webots installation dialogue box and first screen.

Teacher’s Signature:_________________
Remarks: ________________________

12
LAB 3
Simulation with E-Puck Mobile Robot

Controller Code:

/*

* File: my_controller.c

* Date:

* Description:

* Author:

13
* Modifications:

*/

/*

* You may need to add include files like <webots/distance_sensor.h> or

* <webots/differential_wheels.h>, etc.

*/

#include <webots/robot.h>

#include<webots/differential_wheels.h>

#define TIME_STEP 64

/*

* This is the main program.

* The arguments of the main function can be specified by the

* "controllerArgs" field of the Robot node

*/

int main(int argc, char **argv)

/* necessary to initialize webots stuff */

wb_robot_init();

wb_differential_wheels_set_speed(100,100);

while (wb_robot_step(TIME_STEP) != -1) {

/*

* Read the sensors :

14
* Enter here functions to read sensor data, like:

* double val = wb_distance_sensor_get_value(my_sensor);

*/

/* Process sensor data here */

/*

* Enter here functions to send actuator commands, like:

* wb_differential_wheels_set_speed(100.0,100.0);

*/

};

/* Enter your cleanup code here */

/* This is necessary to cleanup webots resources */

wb_robot_cleanup(); return 0;}

Simulation with Elisa Robot

15
16
17
LAB 4
Scaling of Robot
The objective of this lab is to do add scale filed in existing solid node (e.g robot). The simulation
will contain a same environment that was built in previous lab (a light and an arena with floor and
walls, a predefined robot ), but size of robot will be configured as shown in figure given below.

Hands-on Steps:

 copy $WEBOTS_HOME/projects/robots/e-puck/protos/E-puck.proto to
yourProject/protos/E-puckWithScale.proto (putting it in the protos directory and renaming it are
important)
 Edit the yourProject/protos/E-puckWithScale.proto file:
 Rename "PROTO E-puck [" to "PROTO E-puckWithScale [" => the name of the PROTO should
match with the PROTO file name.
 Add a new field "field SFVec3f scale 1 1 1"
 Modify the DifferentialWheels node to set its scale field according to the new E-
puckWithScale.scale field: (Simply add "scale IS scale")
 Add the new PROTO in your .wbt file:
18
# ...
E-puckWithScale {
scale 2 2 2
}

#VRML_SIM V8.5 utf8


# EPFL educational and research mini mobile robot.
# The e-puck is powered by a dsPIC processor and features a very large
number of sensors in its basic configuration.
# More info here: http://www.e-puck.org.

PROTO E-puck [
field SFVec3f translation 0 0 0
field SFRotation rotation 0 1 0 0
field SFVec3f scale 1 1 1

field SFString controller "e-puck_avoid_obstacles"


field SFString controllerArgs ""
field SFString name "e-puck"
field SFFloat camera_fieldOfView 0.84
field SFInt32 camera_width 52
field SFInt32 camera_height 39
field SFBool camera_antiAliasing FALSE
field SFRotation camera_rotation 1 0 0 0 # linear camera mode: 1 0 0
-0.47
field SFFloat camera_noise 0.0
field SFInt32 emitter_channel 1
field SFInt32 receiver_channel 1
field MFFloat battery []
field SFString window "e-puck"
field MFNode turretSlot []
field MFNode groundSensorsSlot []
field SFBool kinematic FALSE
]
{
%{
kinematic = fields.kinematic.value
}%
DifferentialWheels {
translation IS translation
rotation IS rotation
scale IS scale

19
20
21
Teacher’s Signature:_________________
Remarks: ________________________

22
LAB 5
Work on Solid Node
The objective of this lab is to do modify the simulation environment through addition of solid node.
The simulation will contain an environment (floor, a predefined robot (e-puck) and solid node
(sphere) as shown in Figure given below

Solid Node:
A rigid body is a body in which deformation can be neglected. The distance between any two given
points of a rigid body remains constant in time regardless of external forces exerted on it. Soft bodies
and articulated objects are not rigid bodies, e.g. the following are not rigid bodies: a rope, a tyre, a
sponge and an articulated robot arm. However, an articulated entity can be broken into of several
undividable rigid bodies. For example a table, a robot finger phalanx or a wheel are undividable rigid
bodies. In Webots there is a direct match between a rigid body and a Solid node. A Solid node (or a

23
node which inherits the Solid node) will be created for each rigid body . To define a rigid body, you
will have to create a Solid node. Inside this node you will find different subnodes corresponding to the
characteristics of the rigid body.

Hands-on Steps:

Modification of Floor
 Make sure the "my_first_simulation.wbt" world file is open, and that the simulation is paused
and is at a virtual time of 0. Using the File / Save World As... menu, save the simulation as
"obstacles.wbt".

 To remove the RectangleArena, select it in the scene tree view and press the Delete button
located in the toolbar.

 In order to add a different floor PROTO, select the DirectionalLight node and click on
the Add button. In the open dialog box, and choose PROTO (Webots) / objects / floors / Floor
(Solid).

 In the scene tree view select and expand the Floor. Modify the size fields and set it to {1,
1} to resize it to 1mx1m.

Addition of Solid Node


24
 In the scene tree view, select the last node and add a Solid node using
the Add button.
 Similarly select the children field of the Solid node, and add a Shape node to it.
 In order to get a shaded object, it is necessary to specify an appearance. To do this,
select the appearance field of the Shape node and use the Add button.
 Then, you can add a default Material to the material field in a similar way.
 Add a Sphere node as the geometry field of the newly created Shape node.
 Change radius to 0.05 and subdivision field to 2 in geometry.
 Add another Sphere node to the boundingObject field of the Solid.
 Change radius to 0.05 and subdivision field to 2 in geometry.
 Finally add a Physics node to the physics field of the Solid. By modifying
the translation field of the Solid node, place the ball in front of the robot (at {0, 0.1,
-0.2} ).
 Save the simulation

Tasks
 Perform above described hands-On steps.
 Create another simulation with another other robot with scale size 2 2 2.
 Attach Snap shots of both simulations.

25
26
Teacher’s Signature:_________________
Remarks: ________________________

27
LAB 6
DEF-USE Mechanism
The objective of this lab is to work on DEF-USE mechanism in simulation. Through this mechanism
a node that has been define in previous simulation will be used in two place in screen tree with
single reference. DEF-USE mechanism allows to reduce node redundancy of the scene tree.

To define the ball, In previous simulation we have used the Sphere node in two different contexts:
for the graphical representation (children) and to define the physical bounds
(boundingObject). All Geometry node (such as the Sphere node) can be used in a graphical
context. However, only a subset of them can be used in a physical context.

DEF-USE mechanism
The DEF-USE mechanism allows to define a node in one place and to reuse that definition elsewhere
in the Scene Tree. This avoids the duplication of identical nodes and this allows to modify several
nodes at the same time. Here is how it works: first a node is labeled with a DEF string, and then
copies of this node are reused elsewhere with the USE keyword. Only the fields of the DEF node can

28
be edited, the fields of the USE nodes assume similar values. This mechanism is dependent on the
apparition order of the nodes in the world file, because the DEF node should appear first.

Hands-on Steps:

 From the results of the previous simulation, create a new simulation called "appearance1.wbt"
by using the File / Save World As... menu.
 Select the first Sphere node (the child of the Shape) in the scene tree view. The field editor of
the scene tree view allows you to enter the DEF string. Enter "BALL_GEOMETRY".
 Select the boundingObject field (containing the second Sphere node), and delete it by using
the Reset to default button in the field editor. Then, click on the Add button, and select
the USE / BALL_GEOMETRY in the dialog box.
 Now change the Change radius to 0.05 and subdivision field to 2 in DEF BALL_GEOMETRY.
 Note It will effect USE BALL_GEOMETRY

Tasks
 Perform above described hands-On steps.
 Add other another solid node and work with DEF_USE .
 Attach Snap shots of both simulations.
 Firstly we take our previous simulation

29
Then we save it as an another simulation as appearance.wbt
And

30
Teacher’s Signature:_________________
Remarks: ________________________
31
LAB 7
Work with graphical Rendering
The objective of this lab is to do hands-on practice on some nodes related to the graphical
rendering. Good looking simulations can be created very quickly when these nodes are used
adequately. A good graphics quality does not only enhance the user's experience, it is also essential
for simulations where robots perceive their environment (camera image processing, line following,
etc.) as shown in figure given below.

Lights:
The lighting of a world is determined by light nodes. There are three types of light nodes: the
DirectionalLight, the PointLight and the SpotLight. A DirectionalLight simulates a light which is infinitely
far (ex: the sun), a PointLight simulates light emitted from a single point (ex: a light bulb), and a
SpotLight simulates a conical light (ex: a flashlight). Each type of light node can cast shadows.
32
Lights are costly in term of performance. Minimizing the number of lights increases the rendering
speed. A maximum of 8 lights is allowed if the shaders are disabled in the Webots preferences. A
PointLight is more efficient than a SpotLight, but less than a DirectionalLight. Note finally that casting
shadows can reduce the simulation speed drastically.

Hands-on Steps:

 From the results of the previous simulation, create a new simulation called
"appearance.wbt" by using the File / Save World As... menu.
 Adjust your DirectionalLight node. Set its ambientIntensity field to 0.5, its castShadows field
to TRUE, and its direction field to {1, -2, 1}.
 Add an Appearance node to the ball. Add a Material node to the material field as well as an
ImageTexture node to the texture field of the Appearance node. Add an item to the
ImageTexture's url field using the Add button.
 Set the value of the newly added url item to
"WEBOTS_HOME/projects/default/worlds/textures/red_brick_wall.jpg" using the file selection
dialog
 View the simulation in wireframe mode by using the View / Wireframe Rendering menu item.
Then restore the plain rendering mode: View / Plain Rendering.

Tasks
 Perform above described hands-On steps.
 Create another simulation with box object.
 Attach Snap shots of both simulations.

33
34
Teacher’s Signature:_________________
Remarks: ________________________

35
LAB 8
Controllers Basics
The objective of this lab is to give the basics introduction of robot programming in Webots through
hands-on practice. The features that has been covered in this lab are: What is the link between
the scene tree nodes and the controller API, how the robot controller has to be initialized and
cleaned up, how to initialize the robot devices, how to get the sensor values, how to command the
actuators, and how to program a simple feedback loop.

Understand the e-puck Model


Controller programming requires some information related to the e-puck model. In order to create
the collision avoidance algorithm, we need to read the values of its 8 infra-red distance sensors
located around its turret, and we need to actuate its two wheels. The way that the distance sensors
are distributed around the turret and the e-puck direction are depicted in this figure.

The distance sensors are modeled by 8 DistanceSensor nodes in the hierarchy of the robot. These
nodes are referenced by their name fields (from "ps0" to "ps7"). We will explain later how these
nodes are defined. For now, simply note that a DistanceSensor node can be accessed through the
related module of the Webots API (through the "webots/distance_sensor.h" include file). The
values returned by the distance sensors are scaled between 0 and 4096 (piecewise linearly to the
distance). While 4096 means that a big amount of light is measured (an obstacle is close) and 0
means that no light is measured (no obstacle).

In the same way, the e-puck root node is a DifferentialWheel node and can be accessed by the
"webots/differential_wheel.h" include file. The speed is given in a number of ticks/seconds where
1000 ticks correspond to a complete rotation of the wheel. The values are clamped between -
1000 and 1000.

36
(a) E-Puck with distance sensors

(b) UML state machine of a simple feedback loop

37
Controller Programming (Hands-on practice)
 Save the previous world as "collision_avoidance.wbt".
 Create a new controller called "e-puck_avoid_collision" using the wizard. Modify the
controller field of the E-puck node in order to link it to the new controller.
 At the beginning of the controller file, add the include directives corresponding to the
Robot, the DifferentialWheels and the DistanceSensor nodes in order to be able to use the
corresponding API.
#include <webots/robot.h>
#include <webots/differential_wheels.h>
#include <webots/distance_sensor.h>

 After the include statements add a macro that defines the duration of each physics step.
This macro will be used as argument to the wb_robot_step() function, and it will also be
used to enable the devices. This duration is specified in milliseconds and it must be a
multiple of the value in the basicTimeStep field of the WorldInfo node.
#define TIME_STEP 64
 Write the prototype of the main() function as follows:
// entry point of the controller
int main(int argc, char **argv)
{
// initialize the Webots API
wb_robot_init();
// initialize devices
// feedback loop
while (1) {
// step simulation
int delay = wb_robot_step(TIME_STEP);
if (delay == -1) // exit event from Webots
break;
// read sensors outputs
// process behavior
// write actuators inputs
}
// cleanup the Webots API
wb_robot_cleanup();
return 0; //EXIT_SUCCESS
}

 Just after the comment "// initialize devices", get and enable the distance sensors as
follows:
38
// initialize devices
int i;
WbDeviceTag ps[8];
char ps_names[8][4] = {
"ps0", "ps1", "ps2", "ps3",
"ps4", "ps5", "ps6", "ps7"
};

for (i=0; i<8; i++) {


ps[i] = wb_robot_get_device(ps_names[i]);
wb_distance_sensor_enable(ps[i], TIME_STEP);
}

 In the main loop, just after the comment "// read sensors outputs", read the distance
sensor values as follows:
// read sensors outputs
double ps_values[8];
for (i=0; i<8 ; i++)
ps_values[i] = wb_distance_sensor_get_value(ps[i]);

 In the main loop, just after the comment "// process behavior", detect if a collision occurs
(i.e. the value returned by a distance sensor is bigger than a threshold) as follows:
// detect obstacles
bool right_obstacle =
ps_values[0] > 100.0 ||
ps_values[1] > 100.0 ||
ps_values[2] > 100.0;
bool left_obstacle =
ps_values[5] > 100.0 ||
ps_values[6] > 100.0 ||
ps_values[7] > 100.0;

 Finally, use the information about the obstacle to actuate the wheels as follows:
// init speeds
double left_speed = 500;
double right_speed = 500;
// modify speeds according to obstacles
if (left_obstacle) {
// turn right
left_speed += 500;
right_speed -= 500;
}
else if (right_obstacle) {
// turn left
39
left_speed -= 500;
right_speed += 500;
}
// write actuators inputs
wb_differential_wheels_set_speed(left_speed, right_speed);

 Compile code by selecting the Build / Build menu item. Compilation errors are displayed in
red in the console. If there are any, fix them and retry to compile. Revert the simulation.
The Controller Code
#include <webots/robot.h>
#include <webots/differential_wheels.h>
#include <webots/distance_sensor.h>
// time in [ms] of a simulation step
#define TIME_STEP 64

// entry point of the controller


int main(int argc, char **argv)
{
// initialize the Webots API
wb_robot_init();

// internal variables
int i;
WbDeviceTag ps[8];
char ps_names[8][4] = {
"ps0", "ps1", "ps2", "ps3",
"ps4", "ps5", "ps6", "ps7"
};

// initialize devices
for (i=0; i<8 ; i++) {
ps[i] = wb_robot_get_device(ps_names[i]);
wb_distance_sensor_enable(ps[i], TIME_STEP);
}

// feedback loop
while (1) {
// step simulation
int delay = wb_robot_step(TIME_STEP);
if (delay == -1) // exit event from Webots
break;

// read sensors outputs


double ps_values[8];
for (i=0; i<8 ; i++)
40
ps_values[i] = wb_distance_sensor_get_value(ps[i]);

// detect obstacles
bool right_obstacle =
ps_values[0] > 100.0 ||
ps_values[1] > 100.0 ||
ps_values[2] > 100.0;
bool left_obstacle =
ps_values[5] > 100.0 ||
ps_values[6] > 100.0 ||
ps_values[7] > 100.0;

// init speeds
double left_speed = 500;
double right_speed = 500;

// modify speeds according to obstacles


if (left_obstacle) {
left_speed += 500;
right_speed -= 500;
}
else if (right_obstacle) {
left_speed -= 500;
right_speed += 500;
}

// write actuators inputs


wb_differential_wheels_set_speed(left_speed, right_speed);
}

// cleanup the Webots API


wb_robot_cleanup();
return 0; //EXIT_SUCCESS
}

Controller Programming (Hands-on practice)


 Save the previous world as "collision_avoidance.wbt".
 Create a new controller called "e-puck_avoid_collision" using the wizard. Modify the
controller field of the E-puck node in order to link it to the new controller.
 At the beginning of the controller file, add the include directives corresponding to the
Robot, the DifferentialWheels and the DistanceSensor nodes in order to be able to use the
corresponding API.
#include <webots/robot.h>
#include <webots/differential_wheels.h>
#include <webots/distance_sensor.h>
41
 After the include statements add a macro that defines the duration of each physics step.
This macro will be used as argument to the wb_robot_step() function, and it will also be
used to enable the devices. This duration is specified in milliseconds and it must be a
multiple of the value in the basicTimeStep field of the WorldInfo node.
#define TIME_STEP 64
 Write the prototype of the main() function as follows:

42
#include <webots/robot.h>
#include <webots/differential_wheels.h>
#include <webots/distance_sensor.h>
// time in [ms] of a simulation step
#define TIME_STEP 64

// entry point of the controller


int main(int argc, char **argv)
{
// initialize the Webots API
wb_robot_init();

// internal variables
int i;
WbDeviceTag ps[8];
char ps_names[8][4] = {
"ps0", "ps1", "ps2", "ps3",
"ps4", "ps5", "ps6", "ps7"
};

// initialize devices
for (i=0; i<8 ; i++) {
ps[i] = wb_robot_get_device(ps_names[i]);
43
wb_distance_sensor_enable(ps[i], TIME_STEP);
}

// feedback loop
while (1) {
// step simulation
int delay = wb_robot_step(TIME_STEP);
if (delay == -1) // exit event from Webots
break;

// read sensors outputs


double ps_values[8];
for (i=0; i<8 ; i++)
ps_values[i] = wb_distance_sensor_get_value(ps[i]);

// detect obstacles
bool right_obstacle =
ps_values[0] > 100.0 ||
ps_values[1] > 100.0 ||
ps_values[2] > 100.0;
bool left_obstacle =
ps_values[5] > 100.0 ||
ps_values[6] > 100.0 ||
ps_values[7] > 100.0;

// init speeds
double left_speed = 500;
double right_speed = 500;

// modify speeds according to obstacles


if (left_obstacle) {
left_speed += 500;
right_speed -= 500;
}
else if (right_obstacle) {
left_speed -= 500;
right_speed += 500;
}

// write actuators inputs


wb_differential_wheels_set_speed(left_speed, right_speed);
}

// cleanup the Webots API


wb_robot_cleanup();
return 0; //EXIT_SUCCESS

44
}

Adding the Camera Sensor:

45
46
Teacher’s Signature:_________________
Remarks: ________________________
47
LAB 9
Homogenous transformation matrices
The objective of this lab is to give the basics introduction of homogenous transformation through
hands-on practice (in MATLAB). Robots have either translational or rotational joints. We therefore
need a unified mathematical description of translational and rotational displacements. The
translational displacement d, given by the vector

d = ai+bj+ck

can be described also by the following homogenous transformation matrix H

When using homogenous transformation matrices an arbitrary vector has the following
4×1 form

A translational displacement of vector q for a distance d is obtained by multiplying


the vector q with the matrix H

The translation, which is presented by multiplication with a homogenous matrix, is


equivalent to the sum of vectors q and d

v = q+d = (xi+yj+zk)+(ai+bj+ck) = (x+a)i+(y+b)j+(z+c)k.

In a simple example, the vector 2i+3j+2k is translationally displaced for the distance 4i−3j+7k

48
Tasks (Solve through MATLAB)

1. A point auvw [5,9,2] is attached to a rotating frame uvw, the frame rotates 60 degree
about the Z axis of the reference frame.

2. 4. A point axyz 4,6,9] is the coordinate w.r.t. the reference coordinate system xyz, find the
corresponding point auvw w.r.t. the rotated U-V-W coordinate system if it has been rotated
60 degree about OZ axis.

3.

Teacher’s Signature:_________________
Remarks: ________________________
49
LAB 10
Inverse Transformation matrix
The objective of this lab is to do hands –on practices in MATLAB for Inverse transformation matrix.

Tasks 1:

Tasks 2:

A point a=[0,2,6] is the coordinate w.r.t. the reference coordinate system X,Y,Z, find the corresponding
point w.r.t. the rotated U-V-W coordinate system if it has been rotated 60 degree about Z axis .
50
Teacher’s Signature:_________________
Remarks: ________________________

51
LAB#11
Composite Transformation matrix
The objective of this lab is to do hands –on practices in MATLAB for Composite Homogeneous
Transformation Matrix.

Tasks:

52
Figure :Robot kinematic chain

 Draw Kinematic chain for Figure given above.


 Find the Position of E in H coordinate.
 Take any value for U𝑇𝑅 R𝑇𝐻 H𝑇𝐸 U𝑇𝑃 P𝑇𝐸 matrices.

Teacher’s Signature:_________________
Remarks: ________________________

53
LAB 12

Representation of Transformations along


Reference Frame and Rotating Frame
The objective of this lab is to do hands –on practices in MATLAB for computation of transformation
rotation along reference frame and rotation frame.

Transformation relative to reference frame(x,y,z)


Right to left order –pre multiply point with transformations matric

Example

A point P(7,3,2) is attached to a frame (n,o,a) and is subjected to the transformations described next.
Find the coordinates of the point relative to the reference frame at the conclusion of transformations.
• Rotation of 90 about the z-axis
• Followed by a rotation of 90 about the y-axis
• Followed by a translation of [4,-3,7].
Solution:𝑃𝑥𝑦𝑧 = Trans(4,-3,7)Rot(y,90)Rot(z,90)P

6
=[4]
10
1

Transformation relative to rotating frame (n,o,a)


Left to right order-as written in problem

Example

A point P(7,3,2) is attached to a frame (n,o,a) and is subjected to the transformations described next.
Find the coordinates of the point relative to the reference frame at the conclusion of transformations.
• Rotation of 90 about the a-axis
• Followed by a translation of [4,-3,7] along n,o,a
• Followed by a rotation of 90 about the o-axis
54
Solution:𝑃𝑥𝑦𝑧 = Rot(a,90)Tran(4,-3,7)Rot(o,90) P
0
= [6 ]
0
1

Tasks:
1. A point P(6,2,3) is attached to a frame (n,o,a) and is subjected to the transformations
described next. Find the coordinates of the point relative to the reference frame at the
conclusion of transformations.
• Rotation of 90 about the x-axis
• Followed by a rotation of 90 about the z-axis
• Followed by a translation of [-4,-2,-7].

2. A point P(8,5,-6) is attached to a frame (n,o,a) and is subjected to the transformations


described next. Find the coordinates of the point relative to the reference frame at the
conclusion of transformations.
• Rotation of 90 about the o-axis
• Rotation of 90 about the n-axis
• Followed by a translation of [5,8,2] along n,o,a
• Followed by a rotation of 90 about the n-axis
• Followed by a translation of [-3,0,0] along n,o,a

Teacher’s Signature:__________________
Remarks: _________________________

LAB 13
55
Familiarization with Robot Arms
And Cyber Machines

Objective: Familiarization with robot arms and cyber machines in robotics lab.

Theory: Walli supports a wide variety of robotic devices. Four different conventional robots which
emulate the movement of human arm are SCARA, rectilinear robots, CNC or computer numerically
controlled machines, the Cyber mill and Lathe.

Following robot are and mills are placed in robotics lab.

1- Mentor
2- Gryphon
3- Serpant
4- Conveyor belt
5- Cyber mill
6- Cyber lathe

Mentor

56
Gryphon

Serpant

57
Cyber Mill

Cyber Lathe

Modes of Robot Programming

58
Robot arms are programmed in following modes

1- Point-to-point control
Keyboard------------ Direct entry of Axis data from keyboard
Pendant-------------- Axis data taken from robot, moved incrementally by push buttons
2- Point-to-point and Continuous Control
Simulator------------ Axis data taken from simulator positions

Tasks Evaluation

Software displays

Readings

performance

Teacher’s Signature:__________________

59
LAB 14
Working with Serpent Robot

Objective: Demonstrating simple movements and working of Serpent robot.

Theory and Procedure: This is a program to demonstrate the simplest robotic manoeuvre which
may be used in a workcell, to pick-up an object using a vertical movement and placing with the same
vertical orientation. With Serpent, it is assured since the prismatic axis at the wrist is vertical, and it
only moves between end stops. A horizontal placement is not possible.

The program may be obeyed as a single sequence, which will contain two lines with the
same code, or it may be obeyed as part of the larger program under the control of a workcell program
for the separate pickup and place sequence.

The object or part is assumed to be at a height above the workcell surface, corresponding to
that of a conveyor, the typical use of such a manoeuvre being to take parts off the conveyor and place
60
them in a component bin. In the program the conveyor pickup point is assumed to be ahead of a
robot and to the left of the Y axis, with the conveyor typically aligned and parallel to the x axis. Either
the two finger gripper or the suction gripper may be used . The height of the gripper in its lower
position will need to be physically adjusted, however, with the combination of the height of the robot
on its column and the end stops for the wrist prismatic axis, Z, otherwise the gripper may not reach
or damage could result if it can travel too far.

Robot Program:

Serpent-1~SVERTP&P.se3

61
Tasks Evaluation

Software displays

Readings

performance

Teacher’s Signature:__________________

62

Das könnte Ihnen auch gefallen