• 沒有找到結果。

Interfacing Webots to third party software

在文檔中 Webots User Guide (頁 79-82)

and save it as ajpegorPNGimage. This can be used to create a ”webcam” showing the current simulation in real-time on the Web!

5.8 Interfacing Webots to third party software

5.8.1 Overview

If you don’t want to develop your robot controllers using C, C++ or Java, it is possible to interface Webots to almost any third party software, such as MatLabTM, LispTM, LabViewTM, etc. Such an interface is implemented through a TCP/IP protocole that you can define by yourself. Webots comes with an example of interfacing a simulated Khepera robot through TCP/IP to any third party program able to read from and write to a TCP/IP connection. This example world is calledtcpip.wbtand lies in theworldsdirectory of Webots. The simulated Khepera robot is controlled by thetcpip controller which lies in the controllersdirectory of Webots. This small C controller comes with full source code intcpip.c, so that you can improve it to suit your needs. A client example is provided as a binary and C source code in client.c. Such a client should be used as a model to rewrite a similar client using the programming language of your third party software. This has already been implemented in Lisp and MatLab by some Webots customers.

5.8.2 Main advantages

There are several advantages of using such an interface. First, you can have several simulated robots in the same world using the several instances of the sametcpipcontroller, each one using a different TCP/IP port, thus allowing your third party software to control several robots through several TCP/IP connections. To allow thetcpipprocess to open a different port depending on the controlled robot, you should give a differentnameto each robot and use therobot get name in thetcpipcontroller to retrieve this name and decide to open a port specific for each robot.

The second advantage is that you can also remote control a real Khepera robot from your third party software without writting a line of code. Simply switching to the remote control mode in the Khepera window will redirect the input/output to the real robot through the serial line.

The third advantage is that you can spread your controller programs over a network of computers.

This is especially useful if the controller programs perform computer expensive algorithms such as genetic algorithms or other learning techniques.

Finally, it should be mentioned that it might be interesting to set the controlled robot in syn-chronous or asynsyn-chronous mode depending if you want the Webots simulator waits for com-mands from your controllers or not. In synchronous mode (set thesynchronization field of

80 CHAPTER 5. ROBOT AND SUPERVISOR CONTROLLERS your robots to TRUE), the simulator will wait for commands from your controllers. The con-troller step defined by the robot step parameter thetcpip controller will be respected. In asynchronous mode (set the synchronization field of your robots toFALSE), the simulator will run as fast as possible, without waiting for commands from your controllers. In the latter case, it might be interesting to check the real time option in the preferences of Webots to have a real time simulation in which robots should behave like a real robots controlled through an asynchronous connection.

5.8.3 Limitations

The main drawback of this method is that if your robot has a camera device, the protocole should send the images to the controller over TCP/IP, which might be pretty network intensive. Hence it is recommended to have a high speed network, or use small resolution camera images, or compress the image data before sending it to the controller. This overhead is negligible if you use low resolution cameras such as the Khepera K213.

5.8.4 MatLab

TM

TCP/IP utility

The standard version of MatLabTM doesn’t provide a plain TCP/IP interface. However, a free toolbox called TCP/UDP/IP Toolbox 2.0.5 developed by Mr. Peter Rydes¨ater is available. This toolbox can be found on the Webots CD-ROM (in thecommon utildirectory), as well as on the MatLab web site. It is known to run on Windows, Linux and other UNIX systems. It can be used so that your MatLab programs can connect to thetcpipWebots controllers to drive robots.

Chapter 6

Tutorial: Using the Khepera TM robot

The goal of this chapter is to explain you how to use Webots with your Khepera robot. Khepera is a mini mobile robot developed by K-Team SA, Switzerland (www.k-team.com).

Webots can use the serial port of your computer to communicate with the Khepera robot.

6.1 Hardware configuration

1. Configure your Khepera robot in mode 1, for serial communication protocol at 9600 baud as described in figure 6.1.

2. Plug the serial connection cable between your Khepera robot and the Khepera interface.

3. Plug the Khepera Interface into a serial port of your computer (either COM1 or COM2, at your convenience).

4. Check the the Khepera robot power switch is OFF and plug the power supply to the Khep-era Interface.

Note: Linux and Mac OS X users may want to redefine theCOM1,COM2,COM3 andCOM4 ports by settingWEBOTS COM1,WEBOTS COM2 WEBOTS COM3and/orWEBOTS COM4environment vari-ables to point to the appropriate/devdevice files.

On Linux, if these environment variables are not set, Webots will use respectively/dev/ttyS0, /dev/ttyS1, /dev/ttyS2 and /dev/ttyS3 for COM1, COM2 COM3 and COM4 (note the -1 difference). For example, if your laptop running Linux has no serial port, you may want to use a USB-RS232 converter, in which case it may be useful to type something like: export WEBOTS COM1 /dev/ttyUSB0to allow Webots to communicate with the Khepera through the USB port.

81

82 CHAPTER 6. TUTORIAL: USING THE KHEPERATMROBOT

0 4 2 6 8

A C E

mode selector set to 1 serial port

Top View

LEDs

Figure 6.1: Khepera II mode selection

On Mac OS X, onlyCOM1has a default value which is set to"/dev/tty.USB Serial", corre-sponding to the default USB to serial converter (like the one installed by the USB232-P9 convert-ers). Other USB to serial converters may require that you define theWEBOTS COM1environment variable to match their specific value. For example, the KeySpan USB to serial converter will need that you define WEBOTS COM1 as "/dev/tty.USA28X1213P1.1". Please consult the documentation of your USB serial adapter to know the exact file name to be defined.

That’s it. Your system is operational: you will now be able to simulate, remote control and transfer controllers to your Khepera robot.

在文檔中 Webots User Guide (頁 79-82)

相關文件