You are on page 1of 6

Constanta Maritime University Annals

Year X, Vol.12

BLUETOOTH BI-DIRECTIONAL COMMUNICATION BETWEEN AN NXT ROBOT AND A PC


Sanda Paturca*, Mariana Ilas**, Constantin Ilas*
*) - Politehnica University of Bucharest, Dept. of Electrical Engineering **) - Politehnica University of Bucharest, Dept. of Electroncs, Telecommunication and Information Technology

ABSTRACT

In this paper we describe the implementation of a bi-directional communication between an NXT robot and a PC, using the Bluetooth protocol. We analyse and compare two approaches: a communication that is controlled by PC, using direct commands that the robot interprets and executes and a communication that is controlled by the robot, which sends data or requests to the PC. The comparison between these two approaches is done with respect to flexibility, simplicity and accuracy. With such a communication the NXT robot becomes a very powerful kit for advanced education platforms and research activities. Thus it can be used for monitoring the functionality of any robot, its accuracy in following a motion trajectory or in performing a certain action as well as for sending commands to the robot. Particularly, it is a powerful tool for mobile robots that may receive a command for a new trajectory or may interact with the PC for getting a map or updating the map on the PC when their sensors determine differences between the physical space and the map. ____________________________________________________________________________________ Keywords: Mobile Robot, Bluetooth Communication, Data Logging, Object Recognition. ____________________________________________________________________________________ 1. INTRODUCTION

Lego Mindstorms NXT robots have become a popluar platform used for implementing and testing various robot control algorithms for education and research. Its main benefits include versatility, the fact that it can be programmed through numerous tools and in several languages as well as affordability. In this paper we describe the implementation of a bi-directional communication between an NXT robot and a PC, using the Bluetooth protocol. This communication is extreamely usefull for supervising mobile robots as well as for monitoring the functionality of any robot. Thus, it can be used to send on-line and store on PC data arrays with information on the robot most important parameters (such as actual speed, obstacle position as detected by various sensors, etc). We analyse and compare two approaches for achieving this functionality. The first consists in implementing a program on the PC which sends direct commands to the robot. These commands are executed by the robot and can either perform an action (move the robot, pick an object, etc) or can read data from the sensors and send them back to the PC. The communication is controlled by the PC in this case. The second approach consists in implementing two programs, one running on the robot and the other on the PC. In this approach the communication is controlled by the program running on the robot. 2. ROBOT BLUETOOTH INTERFACE DETAILS

A Lego Mindstorms NXT robotics kit contains a programmable Lego unit, called the NXT, which includes two microcontrollers [1]. The master microcontroller is connected to a Bluetooth wireless communication interface (Bluetooth Class II V2.0 compliant). [2] Bluetooth communication can be achieved among a maximum 8 platforms, such as robots, PCs or other Bluetooth enabled systems. One unit is the master and sets up the wireless network to the slave units between the radio frequencies 2.40GHz to 2.48GHz. The robot Bluetooth interface uses a weak signal and has a range of 10 meters. [2] The Bluetooth interface on the NXT robot supports serial port profile, which means data is transferred like through a wireless serial port. Port A is used when the Bluecore is the initiator and used to send data and Port B is used when the interface receives data. One limitation is that the same robot can not be simultaneously a slave and master.[2] The communications between an NXT and other Bluetooth devices is done through one of a total of four channels.

Bluetooth Bi-directional Communication Between an NXT Robot and a PC

When interfacing the robot with a PC, the Bluetooth communication can be initiated either by the PC or the robot. Programming support for Bluetooth control is provided by most programming tools running on PC and robot. In our implemention we used C# and Microsoft.Net Framework for PC and NXC (Not Exactly C) for the NXT robot. Both contain routines for initiating the communication, as well as sending and receiving a character string.

3.

BI-DIRECTIONAL COMMUNICATION UNDER PC CONTROL

This approach is based on the NXT robot capability of interpreting and executing sequentially certain commands. Therefore we implemented a program on the PC which sends such direct commands to the robot. These commands are then executed by the robot which performs an action (moves, picks an object, etc) or reads data from the sensors and sends them back to the PC. The robot is therefore polled by the PC and executes the PC requests. In response, the robot acknowledges the execution (if an action is performed) or sends the requested data. The PC fully controls the communication. A complete cycle for sending and executing a PC command and receiving the robot response is presented in Fig. 3.1. The PC commands that the NXT robot understands include: - controlling a servomotor (speed, direction), thus determining the movement of a robot on one or more axis; - starting the execution of an NXT program; - reading data from a sensor and sending it back to the PC. An important aspect for this approach refers to correlating the data with the acquisiotion moment. Since the robot merely performs a sensor reading based on executing a command from the PC, it cannot measure the exact time for the data reading. Therefore, we can use a timer only on the PC, which will capture the moment when data is received by the PC (not the exact acquision moment). Because the duration for sending a character string over Bluetooth is not fixed, this method may introduce certain errors when a data record is performed. However, if the readings are done at intervals of a few milliseconds or more, these errors are not important.

PC operations
Sets the command Sends the command via Bluetooth

Robot operations

Decodes the command Executes the command Sets the reply Sends the reply via Bluetooth Decodes and processes the reply

DATA?

Determines time for receiving Stores data and time Fig. 3.1 The complete cycle for executing and replying to a PC command

Bluetooth Bi-directional Communication Between an NXT Robot and a PC

4.

BI-DIRECTIONAL COMMUNICATION UNDER ROBOT CONTROL

In this approach the program that runs on the robot controls the communication and sends messages to the PC. These messages are either a set of data (e.g. read from sensors) or a request for certain information. We implemented two programs, one running on the robot and the other on the PC. The PC program creates a log with all data received from the robot, which may be then processed on-line or off-line, thus being very usefull in monitoring the robot operations. The PC program may also responds to robot requests for certain information, such as a new set of coordinates for the next movement. As opposed to the previous method, this one allows determining the exact moment when a sensor is read (by using an internal timer) and therefore for each measurement a pair of the read value and time will be generated, which is very usefull for data processing. Furthermore, it can only save data at preset time moments. This method can either send the measured value and the measurement time immediately or it can save them locally and then send a buffer. Consequently it is both suitable for an on-line or off-line data processing at the PC side.

PC operations

Robot operations
Reads data Determines measurement time Sets the message Sends the message via Bluetooth

Decodes and processes the message

DATA?
Yes No

Stores data and time

Answer the request Sends the answer via Bluetooth Fig. 4.1 The complete cycle for sending data or requests to PC

5.

EXPERIMENTAL TESTS

We implemented and tested both methods described above. The robot used for experiments is presented in Fig. 5.1. For simplicity it has one servomotor and no steering possibility, so it can move only forward and backward. It also has an ultrasonic sensor, used for determining obstacles. For both methods the robot moves forward towards an obstacle that is at 40 cm. When it gets to 24cm to the obstacle, the robot stops for 3 s, then moves back with a higher speed.

Bluetooth Bi-directional Communication Between an NXT Robot and a PC

We saved the actual position as read from the servomotor encoder and the distance to the obstacle, as read from the ultrasonic sensor. The results are presented in Fig. 5.2.

Fig. 5.1 NXT robot used for testing the two communication methods

a)

b) Fig. 5.2 Actual robot position read from encoder a) and distance to the obstacle b) versus time

Bluetooth Bi-directional Communication Between an NXT Robot and a PC

6.

COMPARISON OF THE TWO APPROACHES

An important usage of the bi-directional communication is for monitoring the robot execution as well as for creating data logs. For such an application, the advantages and disadvantages of the two approaches introduced in sections 3 and 4 above are presented in Tab. 6.1.
Table 6.1 Main advantages and disadvantages of the two approaches

Approach PC-controlled application

Advantages - no need for robot programming - simple

Robot-controlled application

- can execute a much larger set of functions - can determine and store the exact measurement time - for off-line creation of data logs can create local logs and send them to PC at the end of the application

Disadvantages - cannot determine the exact acquisition time - can execute only a restricted set of commands - need two programs, one for robot and one for PC

An important aspect for data logging is the possibility of saving both the measuread value and the measurement (or acquisition) time. As summarized in Tab. 6.1 and explained in sections 3 and 4 above, this is only possible for the robot-controlled application. However, even for PC-controlled application the errors introduced by using the time when data is received on the PC instead of the actual measurement time are usually small. The errors between the two approaches are presented in Fig. 6.1. Another interesting feature for data logging is the possibility of saving locally the data and sending them to PC when the test is done. If we do not need real time, on-line measurements on the PC this feature has the advantage of decreasing the processor loading during the actual experiment. Summarizing the comparison results we may conclude that the PC-controlled approach is simpler and easier to implement for small tests, but the robot-controlled one is more advanced and offers a higher flexibility. Instruciunile de micare sunt: mers nainte cu viteza 40cm/s pe o distan de 24cm, oprire 1 secund, revenire la poziia iniial cu vitez de 3 ori mai mare.
25 Robot- controlled application 20 PC- controlled application

distance [cm]

15

10

0 0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000

time [ms]

Bluetooth Bi-directional Communication Between an NXT Robot and a PC

25 Robot-controlled application PC-controlled application 20

distance [cm]

15

10

0 7800 8000 8200 8400 8600 8800 9000 9200 9400

time [ms]

Fig. 6.1 Evolutia distantei parcurse in timp. Rezultatele comparrii celor dou metode

7.

CONCLUSIONS

We implemented, tested and compared two approaches for obtaining a bi-directional communication between a NXT robot and a PC, via Bluetooth. Such a communication is extreamely useful for monitoring the robot movement and actions or for debugging robot programs. With this the NXT robot becomes a very powerfull kit for advanced education platforms and research activities. We demonstrated that the PC-controlled approach is very easy to implement and provides satisfactory results, whereas the robot-controlled approach is more powerfull and gives a higher flexibility, including the capability of sending data either immediately after acquisition or at the end of the experiment. Also, with this approach we can save both the data and the exact acquisition time, which is very useful for a precise data analysis. 8. REFERENCES

[1] LEGO MINDSTORMS Hardware Developer Kit (HDK), http://mindstorms.lego.com, LEGO Group, 2006 [2] LEGO Mindstorms NXT Bluetooth Developer Kit, http://mindstorms.lego.com, LEGO Group, 2006 [3] LEGO Mindstorms NXT Direct commands, http://mindstorms.lego.com, LEGO Group, 2006 [4] SIEGWART, R., NOURBAKHSH, I., Introduction to Autonomous Mobile Robots, MIT Press, 2004. [5] WANG, E. L., LaCOMBE, J., and ROGERS, C., Using LEGO Bricks to Conduct Engineering Experiments, Proceedings of the ASEE Annual conference and exhibition, session 2756, 2004 [6] HOLLAND, J., Designing Autonomous Mobile Robots, Elsevier, 2004 [7] http://www.bluetooth.com/ [8] http://telecom.etc.tuiasi.ro/telecom/staff/ccomsa/Lucru/Introducere_n_Bluetooth.pdf [9] GAWTHROP J., McGOOKIN E., A LEGO-Based Control Experiment, IEEE Control Systems Magazine, v.24, October 2004 [10] Ericsson Mobile Communications AB, Users Manual Bluetooth PC Reference Stack by Ericsson, 2000 [11] HANSEN J., Not eXactly C (NXC) Programmer's Guide, 2007 [12] DUMITRIU, A., Mecatronic, volumul I, Editura Universitii Transilvania din Braov, 2006.

You might also like