• 沒有找到結果。

Webots User Guide

N/A
N/A
Protected

Academic year: 2022

Share "Webots User Guide"

Copied!
140
0
0

加載中.... (立即查看全文)

全文

(1)

Webots User Guide

release 4.0.27

copyright c 2002 Cyberbotics Ltd. All rights reserved.

www.cyberbotics.com

December 3, 2004

(2)

2

copyright c 2002 Cyberbotics Ltd. All rights reserved.

All rights reserved

Permission to use, copy and distribute this documentation for any purpose and without fee is hereby granted in perpetuity, provided that no modifications are performed on this documenta- tion.

The copyright holder makes no warranty or condition, either expressed or implied, including but not limited to any implied warranties of merchantability and fitness for a particular purpose, regarding this manual and the associated software. This manual is provided on an as-is basis.

Neither the copyright holder nor any applicable licensor will be liable for any incidental or con- sequential damages.

This software was initially developed at the Laboratoire de Micro-Informatique (LAMI) of the Swiss Federal Institute of Technology, Lausanne, Switzerland (EPFL). The EPFL makes no war- ranties of any kind on this software. In no event shall the EPFL be liable for incidental or consequential damages of any kind in connection with use and exploitation of this software.

Trademark information

AiboTMis a registered trademark of SONY Corp.

GeForceTM is a registered trademark of nVidia, Corp.

JavaTMis a registered trademark of Sun MicroSystems, Inc.

KheperaTMand KoalaTM are registered trademarks of K-Team S.A.

LinuxTMis a registered trademark of Linus Torwalds.

Mac OS XTMis a registered trademark of Apple Inc.

MindstormsTMand LEGOTMare registered trademarks of the LEGO group.

PentiumTMis a registered trademark of Intel Corp.

Red HatTMis a registered trademark of Red Hat Software, Inc.

Visual C++TM, WindowsTM, Windows 95TM, Windows 98TM, Windows METM, Windows NTTM, Windows 2000TMand Windows XPTMare registered trademarks of Microsoft Corp.

UNIXTMis a registered trademark licensed exclusively by X/Open Company, Ltd.

(3)

Foreword

Webots is a three-dimensional mobile robot simulator. It was originally developed as a research tool for investigating various control algorithms in mobile robotics.

This user guide will get you started using Webots. However, the reader is expected to have a minimal knowledge in mobile robotics, in C, C++ or Java programming and in VRML97 (Virtual Reality Modeling Language).

Webots 4 includes a physics engine allowing the user to define complex mobile robots with various locomotion schemes (wheeled robots, legged robots or even flying robots). Predefined sensors and actuators (like distance sensors, cameras, servos, grippers, etc.) allow the user to model and simulate any mobile robot.

If you have already developed programs using Webots 3, please read chapter 2 to update your programs to run with the new version.

We hope that you will enjoy working with Webots 4.

3

(4)

4

(5)

Thanks

Cyberbotics is grateful to all the people who contributed to the development of Webots, Webots sample applications, the Webots User Guide, the Webots Reference Manual, and the Webots web site, including Jordi Porta, Emanuele Ornella, Yuri Lopez de Meneses, Auke-Jan Ijspeert, Alcherio Martinoli, Gerald Foliot, Allen Johnson, Michael Kertesz, Aude Billiard, and many others.

Moreover, many thanks are due to Prof. J.-D. Nicoud (LAMI-EPFL) and Dr. F. Mondada for their valuable support.

Finally, thanks to Skye Legon, who proof-readed this guide.

5

(6)

6

(7)

Contents

1 Installing Webots 13

1.1 Hardware requirements . . . 13

1.2 Installation procedure . . . 13

1.2.1 RedHat Linux i386 . . . 13

1.2.2 Windows 95, 98, ME, NT, 2000 and XP . . . 14

1.2.3 Mac OS X, version 10.2.8 . . . 14

1.3 Registration Procedure . . . 15

1.3.1 Webots license . . . 15

1.3.2 Registering . . . 16

2 Upgrading from Webots 3 19 2.1 Controller . . . 19

2.1.1 Controller includes . . . 19

2.1.2 Controller library . . . 19

2.1.3 Basic data type . . . 19

2.1.4 Khepera . . . 20

2.1.5 GTK+ GUI . . . 20

2.2 World . . . 20

3 Getting Started with Webots 23 3.1 Introduction to Webots . . . 23

3.1.1 What is Webots ? . . . 23

3.1.2 What can I do with Webots ? . . . 23

3.1.3 What do I need to use Webots ? . . . 24 7

(8)

8 CONTENTS

3.1.4 What is a world ? . . . 25

3.1.5 What is a controller ? . . . 25

3.2 Launching Webots . . . 25

3.2.1 On Linux . . . 25

3.2.2 On Mac OS X . . . 26

3.2.3 On Windows . . . 26

3.3 Main Window: Menus and buttons . . . 26

3.3.1 Filemenu and shortcuts . . . 26

3.3.2 Editmenu . . . 28

3.3.3 Simulationmenu and the simulation buttons . . . 29

3.3.4 Wizardmenu . . . 30

3.3.5 Helpmenu . . . 31

3.3.6 Navigation in the scene . . . 31

3.3.7 Moving a solid object . . . 32

3.3.8 Selecting a solid object . . . 32

3.4 Scene Tree Window . . . 32

3.4.1 Buttons of the Scene Tree Window . . . 33

3.4.2 VRML97 nodes . . . 34

3.4.3 Webots specific nodes . . . 36

3.4.4 Principle of the collision detection . . . 36

3.4.5 Writing a Webots file in a text editor . . . 36

3.5 Citing Webots . . . 37

3.5.1 Citing Cyberbotics’ web site . . . 38

3.5.2 Citing a reference journal paper about Webots . . . 38

4 Tutorial: Modeling and simulating your robot 39 4.1 My first world: kiki.wbt . . . 39

4.1.1 Setup . . . 39

4.1.2 Environment . . . 40

4.1.3 Robot . . . 44

4.1.4 A simple controller . . . 54

(9)

CONTENTS 9

4.2 Adding a camera to the kiki robot . . . 55

4.3 Adding physics to the kiki simulation . . . 55

4.3.1 Overview . . . 55

4.3.2 Preparing the floor for a physics simulation . . . 57

4.3.3 Adding physics to the kiki robot . . . 57

4.3.4 Adding a ball in the kiki world . . . 57

4.4 Modelling an existing robot: pioneer2.wbt . . . 58

4.4.1 Environment . . . 58

4.4.2 Robot with 16 sonars . . . 58

4.4.3 Controller . . . 65

4.5 Transfer to your own robot . . . 65

4.5.1 Remote control . . . 66

4.5.2 Cross-compilation . . . 68

4.5.3 Interpreted language . . . 68

4.6 Adding custom ODE physics . . . 69

4.6.1 Introduction . . . 69

4.6.2 Files . . . 69

4.6.3 Implementation . . . 69

4.6.4 Compiling the shared library . . . 71

4.6.5 Example . . . 71

5 Robot and Supervisor Controllers 73 5.1 Overview . . . 73

5.2 Setting Up a Development Environment . . . 73

5.2.1 Under Windows . . . 73

5.2.2 Under Linux . . . 75

5.2.3 Under Mac OS X . . . 75

5.3 Setting Up a New Controller . . . 75

5.4 Webots Execution Scheme . . . 76

5.4.1 From the controller’s point of view . . . 76

5.4.2 From the point of view of Webots . . . 76

(10)

10 CONTENTS

5.4.3 Synchronous versus Asynchronous controllers . . . 77

5.5 Reading Sensor Information . . . 77

5.6 Controlling Actuators . . . 78

5.7 Going further with the Supervisor Controller . . . 78

5.8 Interfacing Webots to third party software . . . 79

5.8.1 Overview . . . 79

5.8.2 Main advantages . . . 79

5.8.3 Limitations . . . 80

5.8.4 MatLabTMTCP/IP utility . . . 80

6 Tutorial: Using the KheperaTMrobot 81 6.1 Hardware configuration . . . 81

6.2 Running the simulation . . . 82

6.3 Understanding the model . . . 84

6.3.1 The 3D scene . . . 84

6.3.2 The Khepera model . . . 85

6.4 Programming the Khepera robot . . . 86

6.4.1 The controller program . . . 86

6.4.2 Looking at the source code . . . 86

6.4.3 Compiling the controller . . . 89

6.5 Transferring to the real robot . . . 89

6.5.1 Remote control . . . 89

6.5.2 Cross-compilation and upload . . . 90

6.6 Working extension turrets . . . 91

6.6.1 The K213 linear vision turret . . . 91

6.6.2 The Gripper turret . . . 91

6.6.3 Custom turrets and Khepera protocol . . . 92

6.7 Support for other K-Team robots . . . 93

6.7.1 KoalaTM . . . 93

6.7.2 AliceTM . . . 95

(11)

CONTENTS 11

7 Tutorial: Using the LEGO MindstormsTM robots 97

7.1 Building up the Rover robot . . . 97

7.2 Webots model of the Rover robot . . . 119

7.3 Transfering to the real Rover robot . . . 120

7.3.1 leJOS . . . 120

7.3.2 Installation . . . 120

7.3.3 Cross-compilation and upload . . . 121

7.3.4 How does it work ? . . . 121

8 ALife Contest 123 8.1 Previous Editions . . . 123

8.2 Rules . . . 123

8.2.1 Subject . . . 123

8.2.2 Robot Capabilities . . . 124

8.2.3 Programming Language . . . 125

8.2.4 Scoring Rule . . . 125

8.2.5 Participation . . . 126

8.2.6 Schedule . . . 126

8.2.7 Prize . . . 126

8.3 Web Site . . . 126

8.4 How to Enter the Contest . . . 127

8.4.1 Obtaining the software . . . 127

8.4.2 Running the software . . . 128

8.4.3 Creating your own robot controller . . . 128

8.4.4 Submitting your controller to the ALife contest . . . 129

8.4.5 Analysing the performance and improving your competing controller . . 130

8.5 Developers’ Tips and Tricks . . . 132

8.5.1 Practical issues . . . 132

8.5.2 Java Security Manager . . . 132

8.5.3 Levels of Intelligence . . . 133

(12)

12 CONTENTS

9 Practical Work: Robot Soccer 135

9.1 Setup . . . 135

9.2 Rules . . . 136

9.3 Programming . . . 136

9.4 Extensions . . . 136

9.4.1 Modifiying the soccer field . . . 137

9.4.2 Modifying the robots . . . 137

9.4.3 Modifying the match supervisor . . . 137

(13)

Chapter 1

Installing Webots

1.1 Hardware requirements

Webots is available for RedHat Linux i386, Mac OS X, Windows 95, Windows 98, Windows ME, Windows NT, Windows 200 and Windows XP. Other versions of Webots for other UNIX systems (Debian Linux i386, Solaris, Linux PPC, Irix) may be available upon request.

OpenGL hardware acceleration is supported on Windows, Mac OS X and in some Linux config- urations. It may also be available on other UNIX systems.

1.2 Installation procedure

To install Webots, you must follow the instructions corresponding to your computer / operating system listed below:

1.2.1 RedHat Linux i386

Webots will run on RedHat Linux distributions, starting from RedHat 7.2. Webots may run on other Linux distributions. For example, it can be easily installed on Debian Linux, using the aliencommand to translate therpmpackage into adeb package before installation. If you do use Red Hat Linux, please refer to your Linux distribution documentation to get the Webotsrpm package installed.

1. Log on asroot

2. Insert the Webots CD-ROM, mount it (this might be automatic) and install the following packages

13

(14)

14 CHAPTER 1. INSTALLING WEBOTS mount /mnt/cdrom

cd /mnt/cdrom/linux

rpm -Uvh lib/mjpegtools-1.6.2-1.i386.rpm

# mjpegtools is useful to create MPEG movies from simulations rpm -Uvh webots/webots-4.0.27-1.i386.rpm

rpm -Uvh webots/webots-kros-1.1.0-1.i386.rpm

# webots-kros is useful only if you want to cross-compile

# controllers for the Khepera robot

You may need to use the--nodepsor the--forceifrpmfails to install the packages.

1.2.2 Windows 95, 98, ME, NT, 2000 and XP

1. Uninstall any previous release of Webots or Webots-kros, if any, from the Start menu,

Control Panel, Add / Remove Programs. or from the Start menu, Cyberbotics, Uninstall WebotsorUninstall Webots-kros.

2. Insert the Webots CD-ROM and open it.

3. Go to thewindows\webotsdirectory on the CD-ROM.

4. Double click on thewebots-4.0.27 setup.exefile.

5. Follow the installation instructions.

6. Optionally, double click on thewebots-kros-1.1.0 setup.exefile to install the cross- compiler for the Khepera robots.

In order to be able to compile controllers, you will need to install a C/C++ development envi- ronment. We recommend to use Dev-C++ which is provided on the Webots CD-ROM (in the windows/utilsdirectory) as well as from the Bloodshed.net1 web site. Dev-C++ is an inte- grated development environment (IDE) for C/C++ with syntax highlighting running on Windows.

It includes the MinGW distribution with the GNU GCC compiler and utilities. This software is distributed under the terms of the GNU public license and hence is free of charge.

You may also choose to use Microsoft Visual C++TMif you own a license of this software.

1.2.3 Mac OS X, version 10.2.8

1. Insert the Webots CD-ROM and open it.

2. Go to themac:webotsdirectory on the CD-ROM.

1http://www.bloodshed.net

(15)

1.3. REGISTRATION PROCEDURE 15 3. Double click on thewebots-4.0.27.dmgfile.

4. This will mount on the desktop a volume namedWebots containing the Webotsfolder.

Move this folder to your applications directory or wherever you would like to install We- bots.

In order to be able to compile controllers, you will need to install the Apple Mac OS X De- veloper tools, included in the Mac OS X installation CD-ROMs. File editing and compilation using Webots Makefiles can be achieved through these Apple tools. You will probably use the Project Builder application to edit the source codes of the Webots controllers and the Terminal application for invoking make from the directory in which your controller gets compiled.

If you would like to be able to create MPEG movies from your Webots simulations, you will have to install the mjpegtools package. This package is located in thelinux:lib directory of the CD-ROM. Install it from thejpegtools-1.6.2.tar.gz tar ball. After installation, you should be able to callmpeg2encfrom the command line.

The CodeWarriorTM development environment is not supported for the development of con- trollers (although it may also work).

1.3 Registration Procedure

1.3.1 Webots license

Starting with Webots 4, a new license system has been introduced to facilitate the use of Webots.

When installing Webots, you will get a license file, calledwebots.key, containing your name, address, serial number and computer ID. This encrypted file will enable you to use Webots ac- cording to the license you purchased. This file is strictly personal: you are not allowed to provide copies of it to any third party in any way, including publishing that file on any Internet server (web, ftp, or any other server). Any copy of your license file is under your responsibility. If a copy of your license file is used by an unauthorized third party to run Webots, then Cyberbotics may engage legal procedures against you. Webots licenses are (1) non-transferable and (2) non- exclusive. This means that (1) you cannot sell or give your Webots license to any third party, and (2) Cyberbotics and its official Webots resellers may sell or give Webots licenses to third parties.

If you need further information about license issues, please send an e-mail to:

<license@cyberbotics.com>

Please read your license agreement carefully before registering. This license is provided within the software package. By using the software and documentation, you agree to abide by all the provisions of this license.

(16)

16 CHAPTER 1. INSTALLING WEBOTS

1.3.2 Registering

After installing Webots, you will need to register your copy of Webots to get a license file called webots.key allowing you to use all the features of Webots corresponding to the license you purchased.

Regularwebots.key license files are tied to a specific computer, making it impossible to use Webots on another computer. However, if for some reason, you would like to move your Webots license from a computer to another, just send us an e-mail at<license@cyberbotics.com>

to explain the problem. If you plan to use several Webots licenses over a large number of com- puters, you should probably ask us to use the floating license server (see below for details).

Otherwise, you can jump to the simple registration subsection.

Floating license server: lserv

If you don’t want your Webots license file to be tied to specific computers, you have the option to install a license server for Webots. This software, calledlserv, allows you to run Webots con- currently on several machines defined by their IP addresses (or their names). Hence Webots is not tied to a predefined number of machines but can be run on an unlimited number of computers.

However, the license server takes care that the number of computers running Webots simultane- ously doesn’t exceed the maximum allowed by the license file. lserv should be installed on a server machine, i.e., a computer that is on when users are supposed to run Webots.

Currently, lserv only runs on the Linux operating system. However, it allows Webots exe- cution on Linux, Windows and Mac OS X machines. You need to provide Cyberbotics with the MAC address of the eth0 network card of the Linux server running lservso that a spe- cial webots.key license file can be created and will be sent to you. To know this MAC ad- dress, simply issue ifconfig eth0 as root and read the HWaddr parameter. It looks like:

00:50:04:1E:0E:38. Then, you will need to configure the server and clients to setup the floating license server for your local network.

lservis freely available from Cyberbotics at no extra cost upon simple request at:

<license@cyberbotics.com>

Please follow the simple registration procedure to provide Cyberbotics with all the information necessary to create thewebots.keylicense file forlserv. The computer ID provided should be the MAC address of your Linux server on whichlservwill be running.

Simple registration

In order to proceed, launch Webots on the computer on which you would like to install the license file. Go theRegistermenu item of theHelp menu of Webots and follow the instructions. If this computer is connected to the Internet, everything will run smoothly, fill in the requested form and you will shortly receive thewebots.keylicense file via e-mail. Otherwise, you will have

(17)

1.3. REGISTRATION PROCEDURE 17 to fill in a form2on the website of Cyberbotics (see figure 1.1). You will then receive an e-mail containing thewebots.keyfile corresponding to your license.

Figure 1.1: Webots registration page

Please take care to properly fill in each field of this form. The Serial Number is the serial number of your Webots package which is printed the CD-ROM under the heading S/N:. The computer ID is given by Webots in theRegistermenu item of theHelpmenu.

After completing this form, click on the Submitbutton. You will receive shortly thereafter an e-mail containing your personal license filewebots.keywhich is needed to install a registered copy of Webots as described below.

2http://www.cyberbotics.com/registration/webots4.html

(18)

18 CHAPTER 1. INSTALLING WEBOTS Registering several computers

If you need to register several computers, it may be convenient to register all the computers in the samewebots.keylicense file. Hence this unique license file could be copied across all the computers needing a Webots license.

In order to proceed, just enter several computer IDs on the web form, corresponding to all the computers you want to register. The computer IDs have to be seperated by a simple space char- acter.

Copying the license file

Once you received it by e-mail, just copy the webots.key license file into the resources directory of your Webots installation.

Under Linux, copy your personalwebots.keyfile into the/usr/local/webots/resources directory where Webots was just installed.

Under Mac OS X, copy your personalwebots.keyfile into theWebots:resourcesdirectory where Webots was just installed.

Under Windows, copy your personalwebots.keyfile into the directory where Webots was just installed, which is usuallyC:\Program Files\Webots\resources.

(19)

Chapter 2

Upgrading from Webots 3

If you have already worked with Webots 3, your existing programs may need to be modified for use with Webots 4.

2.1 Controller

2.1.1 Controller includes

The include path of the device files is the same as in Webots 3.2, i.e.:

#include <device/robot.h>

#include <device/differential_wheels.h>

#include <device/distance_sensor.h>

2.1.2 Controller library

The name of the controller library to which you will link your executable files changed to ”Con- troller.dll” on Windows and ”libController.so” on Linux. It is not any more ”GtkController.dll”

or ”libGtkController.so”. Please update your project files or make files appropriately.

2.1.3 Basic data type

Since GTK+ and glib are not used any more, the data type coming from the glib are not recog- nized any more. Webots 4 uses the more standard C data types. Moreover, a couple of other Webots specific data type have slightly changed to become more consistant with the rest of the API. Please replace the following data types in your programs:

19

(20)

20 CHAPTER 2. UPGRADING FROM WEBOTS 3 Webots 3 Webots 4

gchar char

guchar unsigned char guint8 unsigned char

gint8 char

gint int

guint unsigned int

gint32 int

guint32 unsigned int gint16 short

guint16 unsigned short gfloat float

gdouble double gpointer void * device tag DeviceTag node ref NodeRef

Table 2.1: Data types changes between Webots 3 and Webots 4

2.1.4 Khepera

If you developed controllers specifically for the Khepera robot, the khepera live function should be replaced by robot live. Moreover, the #include <transfer/khepera.h>

should be removed. Please check also that themodelfield of theDifferentialWheelsnode corresponding to the Khepera robot is ”Khepera” or ”Khepera II”, so that it will be automatically recognized by Webots as a Khepera controller for remote control and code upload.

2.1.5 GTK+ GUI

The GTK+ graphical user interface is not any more integrated within the controller library.

Hence, you are free to use any graphical user interface library, like wxWindows, GTK+, Mo- tif, MFC, etc. To use for example GTK+, you have two options: (1) you can perform all the graphical user interface operations inside a separate thread, or (2) you can setup the GUI in the same thread and call repeatly thegtk main iteration do function inside the main loop. An example of using wxWindows as the GUI of a controller in provided in the wxgui controller sample.

2.2 World

Very few changes were introduced in the Webots worlds that breaks the compatibility. How- ever, since Webots 4 uses a different collision detection engine,boundingObject made up of

(21)

2.2. WORLD 21 Extrusion or IndexedFaceSet have to be changed to composite objects made up of Box, Sphereand / orCylinder. A composite object is aGroupnode containingTransformnodes as children. TheseTransformnodes should contain the primitive shapes previously enumerated and positioned appropriately.

(22)

22 CHAPTER 2. UPGRADING FROM WEBOTS 3

(23)

Chapter 3

Getting Started with Webots

To run a simulation in Webots, you need three things:

This chapter gives an overview of the basics of Webots, including the display of the world in the main window and the structure of the.wbtfile appearing in the scene tree window.

Robot and Supervisor controllers will be explained in detail in chapter 5.

3.1 Introduction to Webots

3.1.1 What is Webots ?

Webots is a professional mobile robot simulation software. It contains a rapid prototyping tool allowing the user to create 3D virtual worlds with physics properties, such as mass repartition, joints, friction coefficients, etc. The user can add simple inert objects or active objects called mobile robots. These robots can have different locomotion schemes (wheeled robots, legged robots or flying robots). Moreover, they be equipped with a number of sensor and actuator devices, like distance sensors, motor wheels, cameras, servos, touch sensors, grippers, emitters, receivers, etc. Finally the user can program each robot individually to exhibit a desired behavior.

Webots contains a large number of robot models and controller program examples that help the users get started.

Webots also contains a number of interfaces to real mobiles robots, so that once your simulated robot behaves as expected, you can transfer its control program to a real robot like Khepera, Hemisson, LEGO Mindstorms, Aibo, etc.

3.1.2 What can I do with Webots ?

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

23

(24)

24 CHAPTER 3. GETTING STARTED WITH WEBOTS

• Mobile robot prototyping (academic research, automotive industry, aeronautics, vaccum cleaner industry, toy industry, hobbyism, etc.)

• Multi-agent research (swarm intelligence, collaborative mobile robots groups, etc.)

• Adaptive behavior research (Genetic evolution, neural networks, adaptive learning, AI, etc.).

• Mobile robotics teaching (robotics lectures, C/C++/Java programming lectures, robotics contest, etc.)

3.1.3 What do I need to use Webots ?

To use Webots, you will need the following hardware:

• A fairly recent PC or Macintosh computer. We recommand at least a Pentium or PowerPC CPU cadenced at 500Mhz. Webots works fine on desktop as well as laptop computers.

• A 3D capable graphics card, with at least 16MB RAM video memory. We recommand nVidia graphics card for PC/Linux users. ATI graphics card are also well suited for Mi- crosoft Windows and Apple Mac OS operating systems.

The following operating system are supported:

• Linux. Although only RedHat Linux is officially supported, Webots is known to run on most major Linux distribution, including Mandrake, Debian, SuSE, Slackware, etc. We recommand however to use a fairly recent recent version of Linux. Webots is provided as anRPMpackage, as well as aDEBpackage.

• Windows. Although Webots runs on Windows 98, ME and NT4, we recommand to use a recent version of Windows (like Windows 2003, Windows XP or Windows 2000) to avoid minor issues.

• Mac OS X. Version 10.2 of Mac OS X or ealier is highly recommanded, as Webots hasn’t been tested on older versions of Mac OS X and may not work as expected on such old versions.

Usually, you will need to be administrator to be able to install Webots. Once installed, Webots can be used as a regular unpriviliged user.

Although no special knowledge is needed to simply view the demos of robot simulations in Webots, you will need a minimal amount of scientifical and technical knowledge to be able to develop your own simulations:

(25)

3.2. LAUNCHING WEBOTS 25

• A basic knowledge of C, C++ or Java programming languages is necessary to program your own robot controllers efficiently. However, even if you don’t know these languages, you can still program the Hemisson robot 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 some very basic knowledge of 3D computer graphics and VRML97 3D description language. That will allow you to create 3D models in Webots or import them from a 3D modelling software.

3.1.4 What is a world ?

A world in Webots is a 3D virtual environment in which you can create objects and robots. A world is saved in theworldsdirectory, in a.wbtfile which contains a description for any object:

Its position, orientation, geometry, appearance (like color, brightness), physical properties, type of object, etc. A world is a hierarchical structure where objects can contain other objects (like in VRML97). For example a robot can contain two wheels, a distance sensor and a servo which itself contains a camera, thus making the camera moveable relatively to the robot thanks to the servo. However, a world file does not contain all the information necessary to run a simulation.

The controller of each robot is specified in the world file by a reference to an executable binary file, but the world file doesn’t contain this executable binary file.

3.1.5 What is a controller ?

A controller is an executable binary file which is used to control a robot described in a world file.

Controllers are stored in subdirectories of the Webotscontrollersdirectory. Controllers may be native executables files (.exeunder Windows) or Java binary files (.class).

3.2 Launching Webots

3.2.1 On Linux

From an X terminal, type webots to launch the simulator. You should see the world window appear on the screen (see figure 3.1).

Webots can also run in batch mode, that is without displaying any window. This is useful to launch simulations from scripts to perform extensive simulations with differents sets of param- eters and save results automatically from a supervisor or robot controller process. To launch Webots in batch mode, simply typewebots --batch filename.wbtwhere filename.wbt is

(26)

26 CHAPTER 3. GETTING STARTED WITH WEBOTS the name of the world file you want to use. Webots will then be launched in batch mode: The speed of execution should correspond to the fast mode.

3.2.2 On Mac OS X

Open the directory in which you uncompressed the Webots package and double-click on the Webots icon. You should see the world window appear on the screen (see figure 3.1).

3.2.3 On Windows

From theStartmenu, go to theProgram Files — Cyberboticsmenu and click on theWebots 4.0.27

menu item. You should see the world window appear on the screen (see figure 3.1).

3.3 Main Window: Menus and buttons

The main window allows you to display your virtual worlds and robots described in the.wbt file. Four menus and a number of buttons are available.

3.3.1

File

menu and shortcuts

TheNewmenu item opens a new default world representing a chessboard of 10 x 10 plates on a surface of 1 m x 1 m. The following button can be used as a shortcut:

New

TheFilemenu will also allow you to perform the standard file operations:Open...,SaveandSave As..., respectively, to load, save and save with a new name the current world.

The following buttons can be used as shortcuts:

Open...

Save

TheRevertitem allows you to reload the most recently saved version of your.wbtfile.

The following button can be used as a shortcut:

Revert

(27)

3.3. MAIN WINDOW: MENUS AND BUTTONS 27

Figure 3.1: Webots main window

The Export VRML item allows you to save the .wbt file as a .wrl file, conforming to the VRML97 standard. Such a file can, in turn, be opened with any VRML97 viewer. This is especially useful for publishing a world created with Webots on the Web.

TheMake Animation...item allows you to create a 3D animation as a WVA file. This file format is useful to playback Webots animations in real 3D, including navigation facilities. The WVA viewer is called Webview. It is a freely available software downloadable from Cyberbotics’

Webview web site1. It can run as a plugin for Internet Explorer, Netscape or Mozilla, but also as a stand alone application. Webview works on Windows, Linux and Mac OS X. It is well suited to demonstrate Webots results, possibly on the Internet World Wide Web.

TheMake Movie...item allows you to create a MPEG-2 movie under Linux and Mac OS X or an AVI movie under Windows. As movies are created on a 25 frame per second basis, you should

1http://www.cyberbotics.com/webview

(28)

28 CHAPTER 3. GETTING STARTED WITH WEBOTS adapt the basic simulation step and the refresh display parameters in the general preferences to obtain a movie running at real time. Leaving the basic simulation step to 32 ms and setting the refresh display each 1 basic simulation step should produce movies runnig faster than real time.

If you need exact real time, set the basic simulation step to 25 ms (it might then be optimal to adapt your controllers’robot stepfunctions using a multiple value of 25, like 50, 75 or 100).

It is also possible to make accelerated movies by setting the refresh display each 2 (or more) basic simulation step while leaving the basic time step to its original value (32 or 25).

TheScreenshot...item allows you to take a screenshot of the current view in Webots. It opens a file dialog to save the current view as a PNG image.

3.3.2

Edit

menu

TheScene Tree Window menu item opens the window in which you can edit the world and the robot(s). A shortcut is available by double-clicking on a solid in the world. A solid is a physical object in the world.

TheImport VRML...menu item inserts VRML97 objects at the end of the scene tree. These objects come from a VRML97 file you will have to specify. This feature is useful to import complex shapes that were modeled in a 3D modelling software, then exported to VRML97 (or VRML 2.0), and then imported into Webots with this menu item. Most 3D modelling software, like 3D Studio Max, Maya, AutoCAD or Art Of Illusion, include the VRML97 (or VRML 2.0) export feature. Beware, Webots cannot import VRML 1.0 file format. Once imported, these objects appear as Group, Transform or Shape nodes at the bottom of the scene tree. You can then either turn these objects into Webots nodes (like Solid, DifferentialWheels, etc.) or cut and paste them into thechildrenlist of existing Webots nodes.

TheRestore Viewpointmenu item resets the camera position and orientation as it was originally when the file was open. This feature is handy when you get lost while navigating in the scene and want to return to the original camera position and orientation.

ThePreferencesitem pops up a window with the following panels:

General: TheStartup modeallows you to choose the state of the simulation when We- bots is launched (stop, run, fast; see theSimulationmenu).

TheBasic simulation stepparameter defines the duration of the simulation step ex- ecuted by Webots. It is expressed in milliseconds. Setting this value to a high value will accelerate the simulation, but will decrease the accuracy of the simulation, especially for physics simulation and collision detection This value is also used when theStepbutton is pressed.

TheRefresh display parameter is multiplicated to the basic step value to define how frequently the 3D display of the main window is refreshed in normalRunmode.

Rendering: This tab controls the 3D rendering in the simulation window.

(29)

3.3. MAIN WINDOW: MENUS AND BUTTONS 29 Checking theDisplay axescheck box displays a red, green and blue axes representing respectively the x, y and z axes of the world coordinate system.

Checking theDisplay sensor rayscheck box displays the distance sensor rays of the robot(s) as red lines.

Checking theDisplay lightscheck box displays the lights (PointLightin the world so that they can be moved more accurately).

Files and paths: The user directory and the default .wbt world which is open when launching Webots are defined here. The user directory should contain at least aworlds, controllers,physics, andobjectssubdirectories where Webots will be looking for files. A complete user directory can be created easily from theSetup user directorymenu item in theWizardmenu

3.3.3

Simulation

menu and the simulation buttons

In order to run a simulation a number of buttons are available corresponding to menu items found under theSimulationmenu:

Stop: InterruptRunorFastmodes.

Step: Execute one simulation basic step. The duration of such a step is defined in the preferences of Webots and can be adjusted to suit your needs.

Run: Execute simulation steps until theStopmode is entered. In run mode, the 3D display of the scene is refreshed every n basic step, where n is defined in the Webots preferences.

Fast: Same asRun, except that no display is performed (Webots PRO only). only.

The Fast mode performs a very fast simulation mode suited for heavy computation (genetic algorithms, vision, learning, etc.). However, as the world display is disabled during aFastsimu- lation, the scene in the world window remains blank until theFastmode is stopped. This feature is available only with Webots PRO.

TheWorld View / Robot Viewitem allows you to switch between two different points of view:

World View: This view corresponds to a fixed camera standing in the world.

Robot View: This view corresponds to a mobile camera following a robot.

The default view is the world view. If you want to switch to theRobot View, first select the robot you want to follow (click on the pointer button then on the robot), and then chooseRobot View

in theSimulationmenu. To return to theWorld Viewmode, reselect this item.

(30)

30 CHAPTER 3. GETTING STARTED WITH WEBOTS A speedometer (see figure 3.2) allows you to observe the speed of the simulation on your com- puter. It is displayed in the bottom right hand side of the main window and indicates how fast the simulation runs compared to real time. In other words, it represents the speed of the virtual time.

If the value of the speedometer is 2, it means that your computer simulation is running twice as fast as the corresponding real robots would. This information is relevant both inRunmode and

Fastmode.

Figure 3.2: Speedometer

To the left of the speedometer, the virtual time is displayed using the following format:H:MM:SS:MMM whereHis the number of hours (may lie on several digits), MMis the number of minutes, SSis the number of seconds andMMMis the number of milliseconds. (see figure 3.2). If the speedome- ter value is higher than one, the virtual time will be progressing faster than the real time. This information is relevant both inRunmode andFastmode.

The basic simulation time step can be chosen from the preferences window. It is expressed in virtual time milliseconds. The value of this time step defines the duration of the time step executed during theStepmode. This step is multiplicated by the refresh parameter to define how frequently the display is refreshed. The refresh parameter can be changed from the preferences window.

In Run mode, with a time step of 64 ms and a fairly simple world displayed with the default window size, the speedometer will typically indicate approximately 0.5 on a Pentium II / 266 Mhz without hardware acceleration and 12 on a Pentium III / 500 Mhz with an nVidia Geforce II MX graphics card.

3.3.4

Wizard

menu

TheWizardmenu is useful to facilitate the creation of a new user directory (from theSetup user directory menu item) or the creation of a new robot controller (from the New robot controller

menu item).

TheSetup user directory menu item will ask you to choose a name for your user directory. A user directory is a directory that will contain all the files you will create while using Webots, including world file, controller files, object files, physics shared libraries, etc. Once you chose a name for this user directory, you will be asked to choose a location on your hard disk where to store it. Then, Webots will create this directory at the specified location and it will create all

(31)

3.3. MAIN WINDOW: MENUS AND BUTTONS 31 the subdirectories and files needed. Finally, it will set this directory as the current user directory in the Webots preferences. From there, you will be able to save all your Webots files in the subdirectories of this user directory (world files, controllers, etc.).

TheNew robot controllermenu item allows you to create a new controller program for your robot.

You will be prompted to choose between a C, C++ or a Java controller. Then, Webots will ask you the name of your controller and it will create all the necessary files (including a template source code file) in your user directory.

3.3.5

Help

menu

In the Helpmenu, the About...item opens theAbout...window, displaying the license infor- mation.

TheIntroduction item is a short introduction to Webots (HTML file). You can access the User Guide and the Reference Manual with the User GuideandReference Manual items (PDF files).

TheWeb site of Cyberboticsitem lets you visit our Web site.

3.3.6 Navigation in the scene

The view of the scene is generated by a virtual camera set in a given position and orientation.

You can change this position and orientation to navigate in the scene using the mouse buttons.

The x, y, z axes mentioned below correspond to the coordinate system of the camera; z is the axis corresponding to the direction of the camera.

• Rotate viewpoint: To rotate the camera around the x and y axis, you have to set the mouse pointer in the 3D scene, press the left mouse button and drag the mouse:

if you clicked on a solid object, the rotation will be centered around the origin of the local coordinate system of this object.

if you clicked outside of any solid object, the rotation will be centered around the origin of the world coordinate system.

• Translate viewpoint: To translate the camera in the x and y directions, you have to set the mouse pointer in the 3D scene, press the right mouse button and drag the mouse.

• Zoom / Tilt viewpoint: Set the mouse pointer in the 3D scene, then:

if you press both left and right mouse buttons (or the middle button) and drag the mouse vertically, the camera will zoom in or out.

if you press both left and right mouse buttons (or the middle button) and drag the mouse horizontally, the camera will rotate around its z axis (tilt movement).

if you use the wheel of the mouse, the camera will zoom in or out.

(32)

32 CHAPTER 3. GETTING STARTED WITH WEBOTS

3.3.7 Moving a solid object

In order to move an object, hold the shift key down while using the mouse.

• Translation: Pressing the left mouse button while the shift key is pressed allows you to drag solid objects on the ground (xz plan).

• Rotation: Pressing the right mouse button while the shift key is pressed rotates solid ob- jects: A first click is necessary to select a solid object, then a second shift-press-and-drag rotates the selected object around its y axis.

• Lift: Pressing both left and right mouse buttons, the middle mouse button, or rolling the mouse wheel while the shift key is pressed allows you to lift up or down the selected solid object.

3.3.8 Selecting a solid object

Simply clicking on a solid object allows you to select this object. Selecting a robot enables the choice ofRobot Viewin thesimulationmenu. Double-clicking on a solid object opens the scene tree window where the world and robots can be edited. The selected solid object appears selected in the scene tree window as well.

3.4 Scene Tree Window

As seen in the previous section, to access to the Scene Tree Window you can either chooseScene Tree Windowin theEditmenu, or click on the pointer button and double-click on a solid object.

The scene tree contains all information necessary to describe the graphic representation and sim- ulation of the 3D world. A world in Webots includes one or more robots and their environment.

The scene tree of Webots is structured like a VRML97 file. It is composed of a list of nodes, each containing fields. Fields can contain values (text string, numerical values) or nodes.

Some nodes in Webots are VRML97 nodes, partially or totally implemented, while others are specific to Webots. For instance theSolidnode inherits from theTransformnode of VRML97 and can be selected and moved with the buttons in the World Window.

This section describes the buttons of the Scene Tree Window, the VRML97 nodes, the Webots specific nodes and how to write a.wbtfile in a text editor.

(33)

3.4. SCENE TREE WINDOW 33

Figure 3.3: Scene Tree Window

3.4.1 Buttons of the Scene Tree Window

The scene tree with the list of nodes appears on the left side of the window. Clicking on the+in front of a node or double-clicking on the node displays the fields inside the node, and similarly expands the fields. The field values can be defined on the top right side of the window. Five editing buttons are available on the bottom right side of the window:

Cut

Copy

Paste after

These three buttons let you cut, copy and paste nodes and fields. However, you can’t perform these operations on the first three nodes of the tree (WorldInfo, ViewpointandBackground).

These nodes are mandatory and cannot be duplicated. Similarly, you can’t copy theSupervisor node because only one supervisor is allowed. Please note that when you cut or copy a robot node, like aDifferentialWheelsorSupervisornode, thecontrollerfield of this node is reset to"void".

(34)

34 CHAPTER 3. GETTING STARTED WITH WEBOTS

Delete: This button allows you to delete a node. It appears only if a node is selected. If a field is selected, theDefault Valuebutton appears instead.

Default Value: You can click on this button to reset a field to its default value(s). A field with values must be selected in order to perform this button. If a node is selected, the Delete

button replaces it.

Transform: This button allows you to transform a node into another one.

Insert after: With this button, you can insert a node after the one currently selected. This new node contains fields with default values, which you can of course modify to suit your needs.

This button also allows you to add a node to a childrenfield. In all cases, the software only permits you to insert a coherent node.

Insert Node: Use this to insert a node into a field whose value is a node. You can insert only a coherent node.

Export Node: Use this button to export a node into a file. Usually, nodes are saved in your objectsdirectory. Such saved nodes can then be reused in other worlds.

Import Node: Use this button to import a previously saved node into the scene tree. Usually, saved nodes are located in the Webots objectsdirectory or in your own objectsdirectory.

The Webotsobjectsdirectory already contains a few nodes that can be easily imported.

3.4.2 VRML97 nodes

A number of VRML97 nodes are partially or completely supported in Webots.

The exact features of VRML97 are the subject of a standard managed by the International Stan- dards Organization (ISO/IEC 14772-1:1997).

You can find the complete specifications of VRML97 on the official VRML97 Web site2. The following VRML97 nodes are supported in Webots:

• Appearance

• Background

2http://www.web3d.org

(35)

3.4. SCENE TREE WINDOW 35

• Box

• Color

• Cone

• Coordinate

• Cylinder

• DirectionalLight

• ElevationGrid

• Fog

• Group

• ImageTexture

• IndexedFaceSet

• IndexedLineSet

• Material

• PointLight

• Shape

• Sphere

• Switch

• TextureCoordinate

• TextureTransform

• Transform

• Viewpoint

• WorldInfo

The Webots Reference Manual gives a list of nodes supported in Webots and specify which fields are actually used. For a comprehensive description of the VRML97 nodes, please refer to the VRML97 documentation.

(36)

36 CHAPTER 3. GETTING STARTED WITH WEBOTS

3.4.3 Webots specific nodes

In order to implement powerful simulations including mobile robots with different propulsion schemes (wheeled robots, legged robots or flying robots), a number of nodes specific to Webots have been added to the VRML97 set of nodes.

VRML97 uses a hierarchical structure for nodes. For example, the Transform node inherits from the Group node, such that, like theGroup node, the Transform node has a children field, but it also adds three additional fields: translation,rotationandscale.

In the same way, Webots introduces new nodes which inherit from the VRML97 Transform node, principally the Solid node. Other Webots nodes (DifferentialWheels, Camera, TouchSensor, etc.) inherit from thisSolidnode.

The Reference Manual gives a complete description of all Webots nodes and their respective fields.

3.4.4 Principle of the collision detection

The collision detection engine is able to detect a collision between twoSolidnodes. It calculates the intersection between the bounding objects of the solids. A bounding object (described in the boundingObjectfield of theSolidnode) is a geometric shape or a group of geometric shapes which bounds the solid. If the boundingObject field is NULL, then no collision detection is performed for thisSolidnode. ASolidnode may contain other Solidnodes aschildren, each of them having its own bounding object.

The collision detection is mainly used to detect if a robot (for example aDifferentialWheels node) collides with an obstacle (Solidnode), or with another robot. TwoSolidnodes can never inter-penetrate each other; their movement is stopped just before the collision.

Example: A solid with a bounding box different from its list of children.

Let us consider the Khepera robot model. It is not exactly aSolidnode, but the principle for the boundingObjectis the same. Open thekhepera.wbtfile and look at theboundingObject field of the DifferentialWheels node. The bounding object is a cylinder which has been transformed. See figure 3.4.

3.4.5 Writing a Webots file in a text editor

It is possible to write a Webots world file (.wbt) using a text editor. A world file contains a header, nodes containing fields and values. Note that only a few VRML97 nodes are imple- mented, and that there are nodes specific to Webots. Moreover, comments can only be written in the DEF, and not like in a VRML97 file.

The Webots header is:

(37)

3.5. CITING WEBOTS 37

Figure 3.4: The bounding box of the Khepera robot

#VRML_SIM V4.0 utf8

After this header, you can directly write your nodes. The three nodesWorldInfo,Viewpoint andBackgroundare mandatory.

Note: We recommend that you write your file using the tree editor. However it may be easier to make some particular modifications using a text editor (like using the search and replace feature of a text editor).

3.5 Citing Webots

When writing a scientific paper, or describing your project involving Webots on a web site, it is always appreciated to make a correct reference to Webots, mentionning Cyberbotics’ web site explicitely and a reference journal paper describing Webots. In order to help you in such a task, we provide here some citation examples, including BibTex entries that you can freely reuse in your own documents:

(38)

38 CHAPTER 3. GETTING STARTED WITH WEBOTS

3.5.1 Citing Cyberbotics’ web site

This project uses Webots3, a commercial mobile robot simulation software developed by Cyber- botics Ltd.

This project uses Webots (http://www.cyberbotics.com), a commercial mobile robot simulation software developed by Cyberbotics Ltd.

The BibTex reference entry may look odd, as it is very different from a standard paper citation and we want the specified fields to appear in the normal plain citation mode of LaTeX.

@MISC{Webots,

AUTHOR = {Webots},

TITLE = {http://www.cyberbotics.com},

NOTE = {Commercial Mobile Robot Simulation Software}, EDITOR = {Cyberbotics Ltd.},

URL = {http://www.cyberbotics.com}

}

Once compiled with LaTeX, it should display as follow:

References

[1] Webots. http://www.cyberbotics.com. Commercial Mobile Robot Simulation Software.

3.5.2 Citing a reference journal paper about Webots

A reference paper was published in the International Journal of Advanced Robotics Systems.

Here is the BibTex entry:

@ARTICLE{Webots04,

AUTHOR = {Michel, O.},

TITLE = {Webots: Professional Mobile Robot Simulation}, JOURNAL = {Journal of Advanced Robotics Systems},

YEAR = {2004}, VOLUME = {1}, NUMBER = {1}, PAGES = {39--42},

URL = {http://www.ars-journal.com/ars/SubscriberArea/Volume1/39-42.pdf}

}

3http://www.cyberbotics.com

(39)

Chapter 4

Tutorial: Modeling and simulating your robot

The aim of this chapter is to give you several examples of robots, worlds and controllers. The first world is very simple, nevertheless it introduces the construction of any basic robot, and explains how to program a controller. The second example shows you how to model and use a camera on this simple robot. The third example will add physics to the robot and world, so that the robot can play with a ball. Finally, the last example will show you how to build a virtual Pioneer 2TMrobot from ActivMedia Robotics.

4.1 My first world: kiki.wbt

As a first introduction, we are going to simulate a very simple robot made up of a box, two wheels and two infra-red sensors (see figure 4.1). The robot is controlled by a program performing obstacle avoidance inspired from Braitenberg’s algorithm. It evolves in a simple environment surrounded by a wall.

4.1.1 Setup

Before starting, please check that Webots was installed properly on your computer (refer to the installation chapter of this manuel). Then, you will have to setup a working directory that will contain the files your will create in this tutorial. To do so, create a directory calledmy webotsin your local directory. Then, create a couple of subdirectories calledworldsandcontrollers. The first one will contain the simlation worlds you will create, while the second one will contain your programs controlling the simulated robots. If you are using gcc as a compiler, you may also need to copy the Makefile.include file from the Webots controllers directory in your localcontrollers directory. To start up with this tutorial, simply copy the kiki.wbt worlds from the Webotsworlds directory to your localworldsdirectory. You will also have

39

(40)

40 CHAPTER 4. TUTORIAL: MODELING AND SIMULATING YOUR ROBOT

wheels IR sensors

Figure 4.1: The kiki robot

to copy thekikisubdirectory which contains thekiki.pngimage. Finally, copy the simple directory from the Webotscontrollersdirectory to your localcontrollersdirectory. Now you should inform Webots that your working directory is there. To do it, launch Webots and open thePreferences...from theEditmenu. Select theFiles and pathstab and select your local my webotsdirectory as theUser directory. You can also set thekiki.wbtworld as the default world. Then quit Webots, so that the preferences are saved. When you will restart it, it will run the kiki world.

4.1.2 Environment

This very first simulated world is as simple as possible. It includes a floor and a surrounding wall to avoid that the robot escapes. This wall is modelled using an Extrusion node. The coordinates of the wall are shown in figure 4.2.

First, launch Webots and stop the current running simulation by pressing the Stop button. Go to the File menu, Newitem to create a new world. This can also by achieved through the New

button, or the keyboard shortcut indicated in the Filemenu. Then open the scene tree window from theScene Tree...item in theEditmenu. This can also be achieved by double-clicking in the 3D world. Let us start by changing the lighting of the scene:

1. Select thePointLight node, and click on the + just in front of it. You can now see the different fields of thePointLightnode. SelectambientIntensityand enter 0.6 as a value, then selectintensity and enter 0.8, then selectlocationand enter 0.5 0.5 0.5 as values. Pressreturn.

2. Select thePointLight node, copy and paste it. Open this newPointLight node and type -0.5 0.5 0.5 in thelocationfield.

(41)

4.1. MY FIRST WORLD: KIKI.WBT 41

0

x

1 2

3 4

8

9 5

0 (−0.489, −0.5)

5 (−0.49, −0.5) 1 (−0.489, −0.49) 2 (0.49, −0.49) 3 (0.49, 0.49) 4 (−0.49, 0.49) 6 (−0.5, −0.5) 7 (−0.5, 0.5) 8 (0.5, 0.5) 9 (0.5, −0.5)

6

7

z

(x,z) coordinates:

Figure 4.2: The kiki world

3. Repeat this paste operation twice again with -0.5 0.5 -0.5 in the locationfield of the third PointLight node, and 0.5 0.5 -0.5 in the location field of the fourth and last PointLightnode.

4. The scene is now better lit. Open thePreferences...from theEditmenu, select theRender- ingtab and check theDisplay lightsoption. Click on theOKbutton to leave the preferences and check that the light sources are now visible in the scene. Try the different mouse buttons, including the mouse wheel if any, and drag the mouse in the scene to navigate and observe the location of the light sources. If you need more explanations with the 3D navigation in the world, go to theHelpmenu and select theHow do I navigate in 3D ?item.

Secondly, let us create the wall:

1. Select the lastTransformnode in the scene tree window (which is the floor) and click on theinsert afterbutton.

2. Choose aSolidnode.

3. Open this newly created Solid node from the + sign and type ”wall” in its name field.

4. Select thechildrenfield andInsert afteraShapenode.

(42)

42 CHAPTER 4. TUTORIAL: MODELING AND SIMULATING YOUR ROBOT 5. Open thisShape, select itsapperance field and create an Appearance node from the

New node button. Use the same technique to create aMaterialnode in thematerial field of the Appearance node. Select the diffuseColorfield of the Material node and choose a color to define the color of the wall. Let us make it dark green.

6. Now create anExtrusionnode in thegeometryfield of theShape.

7. Set theconvexfield toFALSE. Then, set the wall corner coordinates in thecrossSection field as shown in figure 4.2. You will have to re-enter the first point (0) at the last position (10) to complete the last face of the extrusion.

8. In thespinefield, write that the wall ranges between 0 and 0.1 along the Y axis (instead of the 0 and 1 default values).

9. As we want to prevent our robot to pass through the walls like a ghost, we have to define theboundingObject field of the wall. Bounding objects cannot use complex geometry objects. They are limited to box, cylinder and spheres primitives. Hence, we will have to create four boxes (representing the four walls) to define the bounding object of the surrouding wall. Select theboundingObject field of the wall and create aGroup node that will contain the four walls. In thisGroup, insert aTransformnode as achildren. Create aShape as the unique children of theTransform. Instead of creating a new Appearancefor this Shape, reuse the firstAppearance you created (for the wall). To do so, go back to the children list of the wall Solid, open the Shape, click on the Appearancenode and you will see on the right hand side of the window that you can enter a DEF name. Write WALL APPEARANCE as a DEF name and return to theShape of the bounding object. Select itsappearancefield and create aNew nodefor it. However, in theCreate a new nodedialog, you will now be able to use the WALL APPEARANCE you just defined. Select this item and clickOK. Now create aBoxas ageometryfor this Shape node. Set the size of the Box to [ 1 0.1 0.01 ], so that it matches the size of a wall. Set the translationfield of the Transform node to [ 0 0.05 0.495 ], so that it matches the position of a wall. Now, close thisTransform, copy and paste it as the second childrenof the list. Set the translation field of the new node to [ 0 0.05 -0.495 ], so that it matches the opposite wall. Repeat this operation with the two remaining walls and set their rotationfields to [ 0 1 0 1.57 ] so that they match the orientation of the corresponding walls. You also have to edit theirtranslationfield as well, so that they match the position of the corresponding walls.

10. Close the tree editor, save your file as ”my kiki.wbt” and look at the result.

The wall in the tree editor is represented in figure 4.3, while the same wall in the world editor is visible in figure 4.4

(43)

4.1. MY FIRST WORLD: KIKI.WBT 43

Figure 4.3: The wall in the tree editor

Figure 4.4: The wall in the world window

(44)

44 CHAPTER 4. TUTORIAL: MODELING AND SIMULATING YOUR ROBOT

4.1.3 Robot

This subsection describes how to model the kiki robot as a DifferentialWheelsnode con- taining several children: aTransformnode for the body, twoSolidnodes for the wheels, two DistanceSensornodes for the infra-red sensors and aShapenode with a texture.

The origin and the axis of the coordinate system of the robot and its dimensions are shown in figure 4.5.

0.08 y

LEFT SIDE VIEW

z y

0.05 0.08

0.01

0.08

Ø 0.05 0.02

x

FRONT VIEW

Figure 4.5: Coordinate system and dimensions of the kiki robot

To model the body of the robot:

1. Open the scene tree window.

2. Select the lastSolidnode.

3. Insert afteraDifferentialWheelsnode, set its name to ”kiki”.

(45)

4.1. MY FIRST WORLD: KIKI.WBT 45 4. In thechildrenfield, first introduce aTransformnode that will contain a shape with a box. In the newchildrenfield,Insert afteraShapenode. Choose a color, as described previously. In thegeometryfield,insertaBoxnode. Set the size of the box to [0.08 0.08 0.08]. Now set thetranslationvalues to [ 0 0.06 0 ] in theTransformnode (see figure 4.6)

Figure 4.6: Body of the kiki robot: a box To model the left wheel of the robot:

1. Select the Transform node corresponding to the body of the robot and Insert after a Solidnode in order to model the left wheel. Type ”left wheel” in thenamefield, so that thisSolid node is recognized as the left wheel of the robot and will rotate according to the motor command.

2. The axis of rotation of the wheel is x. The wheel will be made of a Cylinder rotated of pi/2 radians around the z axis. To obtain proper movement of the wheel, you must pay attention not to confuse these two rotations. Consequently, you must add aTransform node to thechildrenof theSolidnode.

3. After adding thisTransform node, introduce inside it a Shapewith a Cylinderin its geometryfield. Don’t forget to set an appearance as explained previously. The dimen- sions of the cylinder should be 0.01 for the heightand 0.025 for the radius. Set the rotationto [ 0 0 1 1.57 ]. Pay attention to the sign of the rotation; if it is wrong, the wheel will turn in the wrong direction.

4. In theSolidnode, set the translation to [-0.045 0.025 0] to position the left wheel, and set the rotation of the wheel around the x axis: [1 0 0 0].

(46)

46 CHAPTER 4. TUTORIAL: MODELING AND SIMULATING YOUR ROBOT 5. Give aDEF name to your Transform: WHEEL; notice that you positioned the wheel in translation at the level of theSolidnode, so that you can reuse theWHEEL Transform for the right wheel.

6. Close the tree window, look at the world and save it. Use the navigation buttons to change the point of view.

To model the right wheel of the robot:

1. Select the left wheelSolidnode andinsert afteranotherSolidnode. Type ”right wheel”

in the name field. Set the translation to [0.045 0.025 0] and the rotation to [1 0 0 0].

2. In thechildren,Insert afterUSE WHEEL. PressReturn, close the tree window and save the file. You can examine your robot in the world editor, move it and zoom in on it.

The robot and its two wheels are shown in figure 4.7 and figure 4.8.

Figure 4.7: Wheels of the kiki robot

The two infra-red sensors are defined as two cylinders on the front of the robot body. Their diameter is 0.016 m and their height is 0.004 m. You must position these sensors properly so that the sensor rays point in the right direction, toward the front of the robot.

(47)

4.1. MY FIRST WORLD: KIKI.WBT 47

Figure 4.8: Body and wheels of the kiki robot

1. In thechildren of theDifferentialWheelsnode, insert aftera DistanceSensor node.

2. Type the name ”ir0”. It will be used by the controller program.

3. Let’s attach a cylinder shape to this sensor: In thechildrenlist of theDistanceSensor node,Insert afteraTransformnode. Give aDEFname to it: INFRARED, which you will use for the second IR sensor.

4. In thechildrenof theTransformnode,insert afteraShapenode. Define an appearance andinsertaCylinderin thegeometryfield. Type 0.004 for the height and 0.008 for the radius.

5. Set the rotation for the Transform node to [0 0 1 1.57] to adjust the orientation of the cylinder.

6. In theDistanceSensornode, set the translation to position the sensor and its ray: [0.02 0.08 -0.042]. In theFilemenu,Preferences,Rendering, check theDisplay sensor raysbox.

In order to have the ray directed toward the front of the robot, you must set the rotation to [0 1 0 1.57].

參考文獻

相關文件

Once you get down to a purely business level, your influence is gone and the true light of your life isdimmed. You must work in the missionary spirit, with a breadth of charity

As the result, I found that the trail I want can be got by using a plane for cutting the quadrangular pyramid, like the way to have a conic section from a cone.. I also found

In Section 3, the shift and scale argument from [2] is applied to show how each quantitative Landis theorem follows from the corresponding order-of-vanishing estimate.. A number

You are given the wavelength and total energy of a light pulse and asked to find the number of photons it

The Seed project, REEL to REAL (R2R): Learning English and Developing 21st Century Skills through Film-making in Key Stage 2, aims to explore ways to use film-making as a means

To encourage Sharon, her mom told her “if you can get good grades, I will give you a surprise.” So, Sharon had studied math all night and she also hadn’t slept well last week..

In the simulated environment, his patients gain confidence to face the challenges in the real world.. Here is a successful story to demonstrate VR’s

You may spend more time chatting online than talking face-to-face with your friends or family.. So, are you a heavy