Lego NXT Robot communication with PC

NXT-RobotGeneration Robots markets programmable autonomous robots, i.e. it is possible to program the robot’s behavior based on data it receives from its environment but also the code of conduct is on the robot, is the meaning of self. There are commercially available robots are not autonomous but which are controllable, e.g. via radio-control or other means of connection.

This paper presents a simple autonomous robot that communicates some of the data it collects to a PC, so it is possible to realize an interface on the PC that displays the steps of the robot in real time.

The article presented here leverages IP robot Lego Mind storms NXT and a code on the PC made using Microsoft Visual Programming Language, programming interface included in robotic visual Microsoft Robotics Developer Studio.

The objective of this simple example is to show how a robot using its own development language can be autonomous (Here, move in the environment, measurements of contact and distance using an ultrasonic sensor), and interact via a connection Bluetooth with a PC.

This article uses two graphics programming environments, so it is not necessary to know the programming of a robot. If you want to go further, it is possible to generate C # code in Visual Programming Language, robotics programming environment used for running the program on the PC.

Dialogue with an autonomous robot

Before we begin, I assume that the main principles of NXT-The graphical development environment provided by Lego as Microsoft Robotics Developer Studio known. For more information, see website Generation Robots featuring articles presenting these programming environments.

The robot used

A very simple robot was created using Lego Mind storms NXT Kit. It consists of two servo-motors connected to the inputs A and C of the intelligent brick, each managing a wheel (the principle of Differential Drive) a third servo motor for rotating a horizontal ultrasonic sensor (input B). This sensor ultrasonic connected to port 1 of the intelligent brick performs distance measurements (in centimeters). A contact sensor is located under the robot, connected to port 2.
Respect for the exact shape of the robot is not essential; it is simple enough for a multitude of different robots can be used.

NXT-G code

Let’s start with the NXT-G code; this is code that will run on the robot. The diagram below shows the code produced.

The code presented above has two branches that run in parallel so the robot. The upper branch manages the robot’s behavior. The first block controls the two motors used for the movement of the robot and indicates to turn the same speed, the robot then straight ahead. Then, two conditions (IF) are triggered if the contact sensor is activated (first test) or if the distance ultrasonic sensor detects an obstacle within 20 centimeters. Everything is in an infinite loop so that the robot continues to move indefinitely.

When a sensor is activated in the IF switches, it uses a custom block called “diversion”. Indeed, we have chosen to outsource this code in block personnel to modularize the code. The following figure shows the code for the NXT-G block staff.

The principle of this block is relatively simple. He must stop the robot, turn the distance ultrasonic sensor first right and if the sensor does not detect obstacle to the right, then it goes to the right, if it rotates the ultrasound transducer on the left and headed toward the left. This algorithm is an algorithm exploration of space is optimized and very efficient, but that is not the point. During each step of this code, a specific text is displayed on the screen Lego NXT robot Midterms.

Sending messages to the computer via Bluetooth robot
Returning to the first code (see the first diagram above). The second part of this program is responsible for generating every two seconds, a message Bluetooth containing the current measurement of ultrasonic sensor centimeters. Bluetooth messages generated by a Lego Mind storms NXT are stored on the robot in a mailbox (sort of queue), the Visual Programming Language and after that we will see him running on the PC, will be charged to go retrieve the contents of this message. Note that the measured distance is converted to text before being Bluetooth included in the message. We’ve found VPL code that did not interpret the information when it was passed to the digital format in the NXT-G block

Code named “avoid obstacles. Rabbit” is compiled and downloaded from the programming interface to the NXT-G Robot (See the operation of NXT-G). Block personal “Deroutage.rbt” is automatically compiled and transferred with the previous code.

Code VPL
The code VPL (Visual Programming Language) is running on the PC and communicates with the robot through a connection Bluetooth. An upcoming article will detail the Bluetooth connection with the programmable robots. The paradigm of VPL based on the concept of a service running in node DSS (Decentralized Software Services) based on the library itself CCR (Concurrency and Coordination Runtime). Both libraries responsible for implementing asynchronous and parallel robotics programs have been created by Microsoft and included in Microsoft Robotics Developer Studio. To learn more about the bricks Microsoft Robotics Developer Studio, see the article on the site Generation Robots.

Comma we said, the VPL concept leverages IP services. In the code presented above, we use two specific services to Lego Mind storms NXT. The first, named LegoNXTBrickV2 (V2 because it is the second version of NXT services occurred with the previous version of Microsoft Robotics Developer Studio). This service provides the connection to the robot via Bluetooth. A parameter important service is the COM port for Bluetooth communication must be well positioned (if you configure a connection Bluetooth, it settled on a COM port it is necessary to defer the service settings).

The second service NXT LegoBrickIOv2 which allows queries on the intelligent brick, particularly to exchange messages Bluetooth.

The principle of the program is relatively simple. Every two seconds, the program will check if messages Bluetooth is available on the mailbox # 1 Robot and if so, displays its contents in a dialog on the PC. A simple error handling can continue the program when no message is found.

The heart of what we wanted to present is therefore LegoBrickIOv2 service that allows real-time, while the robot executes an independent program for travel, and retrieve information (here distance measured in centimeters from the sensor ultrasound). Certainly, the use made of the value here is limited to a single display but we could well imagine a more relevant in a more advanced version of the program.

For that it works, you should activate the code “avoid obstacle” on the robot and then manually start the VPL code execution on the computer.
To further

The principles here are simple and aim only to present the principles of communication between two devices (a PC and a robot) and especially to explain how the program works on what. In version most advanced program, we could:

  • Create on the PC GUI using data received from the robot such as radar
  • Better calibrate the motors to rotate the head and possibly generate a representation of the environment
  • Manage exceptions if the program NXT-G does not turn on the robot
  • Propose a more efficient code for the “diversion”
  • Etc…

In conclusion, we say that the use of graphic environments particularly helpful development in robotics for several reasons. First order not to lose in different languages and their interconnection developments, it is Indeed noted that robotics is not (yet) as unified in terms of environment or operating system that is the computer world. Then development environments offered perfectly abstract from the difficulty of the asynchronous and parallel programming, typical of development in robotics. Finally, the proposed library allows to quickly prototype a program and focus on the general algorithm without being blocked by technical issues such as connection Bluetooth, managing queues or parallel programming.

Leave a Reply

Your email address will not be published.