Webots User Guide

previous page go up next page

Foreword

Thanks

1. Installing Webots

2. Getting Started with Webots

3. Sample Webots Applications

4. Tutorial: Modeling and simulating your robot

5. Programming Controllers and Plugins

6. Using the e-puck robot

     

5.2 Setting Up a Development Environment

5.2.1 Under Windows

Using the built-in text editor

It is recommended to use the built-in editor for developing controller code on the Windows platform. The built-in text editor provides Make... and Make Clean... buttons that make the compilation straightforward. On the Windows platform, Webots internally invokes the MinGW environment for compiling. MinGW is a gcc compatible open source development environment for Windows.

Using your own source code editor

It is possible, however less recommended, to use your own source code editor instead of Webots built-in editor. If you choose this option, you will need to install MSYS for compiling the controllers. MSYS is a UNIX-like terminal that can be used to invoke MinGW commands. When building controllers with MSYS, it is necessary that the WEBOTS_HOME environment variable is defined and points to the Webots installation directory. This variable is used by the project's Makefiles to inform the compiler of the location of Webots' libraries and header files. You will also need to add the bin directory of MinGW to your PATH environment variable. MinGW is located in the mingw subdirectory of Webots distribution. When set correctly, the environment variable should be like this:

WEBOTS_HOME = C:\Program Files\Webots
PATH = C:\program Files\Webots\mingw\bin;C:\...

Once MSYS is installed and the environment variables are defined, you should be able to compile controllers by invoking make (or mingw32-make) in the MSYS terminal. Similarly, it is possible to clean up a directory by invoking make clean (or mingw32-make clean).

Using Visual C++

Visual C++ is an integrated development environment for C and C++ provided by Microsoft. It includes a C and C++ compiler and a source code editor. Visual C++ project examples are provided in the controllers/braiten, controllers/khepera and controllers/tcpip controller directories. Typically, a new Visual C++ project for Webots should define a correct include path to the Webots include directory and should link the executable file with the Controller.lib file included in the Webots lib directory. Take care to produce an executable file in the specific controller directory, and not in a Debug or Release subdirectory as produced by default by Visual C++. For example, the khepera.exe program should be created in the khepera directory of your controllers directory. Please note that the resulting executable files cannot be executed from Visual C++, as they must be launched by Webots and referenced in the world file.

Here is the complete procedure to set up a new Webots controller project under Visual C++ 6.0:

  1. Launch Visual C++ and go to the File -> New... menu item.

  2. Create a "Win32 Console Application" project (or "Win32 Application" if you don't need a console for debugging). Set the Project name: to controllers and set the Location: to your local Webots controllers directory. Choose to create an empty project (or a typical "Hello World" Win32 Application).

  3. If you choose to create an empty project, go to the Files -> New... menu item to create a new C++ Source File named my_controller.c in your my_controller directory.

  4. Go to the Projects -> Settings menu item and select the C/C++ tab. Select the Preprocessor category and type C:\Program Files\Webots\include in the Additional include directories entry. Then, go to the Link tab, General category and replace the Output file name: Release/my_controller.exe with my_controller.exe. Then, prepend Controller.lib in the list of Object/library modules. Finally, in the Input category, type C:\Program Files\Webots\lib as an Additional library path.

  5. Now, type your Webots controller source code in the my_controller.c file (you can use the mybot_simple.c controller, provided in the sample controllers directory of Webots, C:\Program Files\Webots\projects\sample\mybot\, as an example.

  6. Now build your application from the Build -> Build my_controller.exe menu item (or F7 key). It should create a my_controller.exe file in your my_controller directory. However, this binary file cannot be launched directly or from Visual C++. It has to be launched by a Webots world refering to that file.

    If you created a Win32 Application from the "Hello World" template, you will probably want to replace the GetMessage() function call with PeekMessage(), in order to call the wb_robot_step() function while no GUI messages are coming.

  7. If you want to debug your controller program using the Visual C++ debugger, you should compile it in "Debug" mode and write the following line of code in your controller program to set a hard breakpoint:


    __asm int 3;
          

    At runtime, this will allow you to enter the Visual C++ debugger at this point and have an opportunity to place more breakpoints, track the contents of variables, etc.

5.2.2 Under Linux

On Linux, usually you do not need to install development tools because they are often prepackaged in the distribution. Webots will need to invoke the gcc C/C++ compiler and the make utility. If these tools are not installed on you system, please refer to your Linux documentation to install them. We recommend using the Webots built-in source code editor to edit and compile your C, C++, Java or Python source code.

5.2.3 Under Mac OS X

On Mac OS X, you will, just need to install the Developer Tools provided with Mac OS X, in order to to program your controllers in C, C++, Java and Python. The Apple Developer Tools for Mac OS X include the gcc C/C++ compiler, the make command, the javac Java compiler and the python command. We recommend using the Webots built-in source code editor to edit and compile your C, C++, Java and Python source code.

previous page go up next page
^ page top ^

  E-mail to webmaster Last updated: Copyright © 2008 Cyberbotics Ltd.