Usage of Lego-NXT robots

Preparing the robot

For running Java programs on NXT robots, the leJOS firmware needs to be flashed to the robot brick. Conversely, with the leJOS firmware being installed, Lego Mindstorms programs cannot be executed. To flash the leJOS firmware, the robot has to be connected to the PC with a USB cable. BlueJ is being started and the robot turned on with the orange button. The flash tool is being opened from the project view via the menu item Tools → Robot → NXT flash tool. The installation procedure starts with a click on the button Flash leJOS firmware. Once completed, the robot can be managed with the leJOS menu control (see picture above).

The left and right buttons of the robot are being used to navigate through the leJOS menus. Menu items can be selected with the orange enter button. The gray rectangular button serves as escape button. To enable the Bluetooth communication with the PC, navigate to the Bluetooth icon in the leJOS menu and press enter. Press enter once again to activate the Bluetooth module (Power on). There are further menu items on this menu level to configure details of the Bluetooth communication like the PIN (default value is 1234). The Bluetooth configuration on the PC depends on the operating system and will not be described here.

Executing robot programs

To upload programs, the robot needs to be turned on and connected to the PC via USB or Bluetooth. Perform a right-click on the corresponding class icon in the BlueJ project view and select the menu item Robot → Upload (NXT) in the context menu. The class will be compiled once again and transferred to the robot. Status messages will be displayed as shown in the figure below. The termination of the upload procedure will be indicated by an acoustic signal, and the log window can be closed again.

Upload for NXT robot

To start a program on the robot, navigate to the menu item Files and press the enter button. A list of all programs stored on the robot will be displayed. Navigate to the program entry of interest and open its context menu by pressing the enter button. By pressing it once again the execution can directly be started (menu item Execute program). Alternatively, the program can be marked as the default executable by pressing the right button first (menu item Set as Default). After switching on the robot or uploading a file, the default program can be started by simply pressing the enter button (menu item Run Default). A program run can be interrupted by pressing the enter and the escape button simultaneously.

The memory capacity of NXT robots is very limited. Typically 5 robot programs based on the Jabotics libraries can be stored at the same time. When uploading a robot program there will be an error message if there is not enough memory available. While the robot is connected with the PC, it is possible to delete files from the robot with the NXT file browser which can be started from BlueJ with the menu command Tools → Robot → NXT file browser. The file browser first has to establish a connection to the robot before a list of all files will be displayed as shown below. All files that are to be deleted have to be marked in the corresponding column before clicking on the button Delete Files. The robot will give an acoustic signal for every deleted file. The browser dialog can be closed afterwards. Alternatively, the files can be deleted via the leJOS menu control on the robot. Go to the menu item Files, select a file in the files list and choose the command Delete file.

NXT-Datei-Browser

Troubleshooting

In case of a severe error during a program run or (occasionally) during a file transfer to the robot there might be a system crash. Then it won't be possible to reset the robot to normal operation by pressing either the escape button or simultaneously the escape and enter buttons. It will be necessary to shortly press the reset button of the robot brick with a very slim pen or with a wire. The reset button can be found on the back of the robot brick in the upper left hole. (Caution: If the reset button is being pressed for several seconds, the robot brick will go into the flash mode that can be recognized by regular muted clicks.)

While problems during file transfer can simply be fixed by repeating the upload, bug fixing in more complex programs can be very troublesome since debugging on the robot is not possible in the usual way. The following hints (to the advisors) might be helpful:

  • For programs based on the Jabotics libraries it should be checked if the problem can be reproduced within the simulation tool. If not, the program should be tested on a different robot to rule out hardware issues. If the problem cannot be reproduced on other robots either, the cable connections between robot brick and motors / sensors might be mixed up for the robot in question.
  • In case of uncaught exceptions, the robot will display the call stack as a list of class and method IDs. To identify the corresponding code it is necessary to look at the log messages from the program upload. Here the linker displays a list of all classes and methods with the corresponding IDs (see figure with upload log messages above). Repeat the file upload to get these IDs.
  • It is possible to send information from the robot to a connected PC during a program run and to have this information displayed in a special console window (to be opened on the PC from BlueJ with Tools → Robot → NXT console viewer). More details can be found in the documentation for the interface org.jabotics.robot.en.IPCConsole. The object factory provided by the class XRobot gives access to the corresponding control object (see documentation of XRobot and IObjectFactory).
  • Robot programs can in principle be debugged within the robot simulation. It must be kept in mind though that the robot simulation is a multithreaded application. Apart from the main thread of the robot program, there are controller threads for the motor and sensor control just as on the real robot. In addition there are threads for generating graphics and sound as well as for simulating the physical world that the robot is interacting with. More details for debugging robot programs can be found on the pages on the simulation tool.
  • Finally it cannot completely be ruled out that an issue is caused by a bug in the leJOS or Jabotics libraries.