Getting Started on Linux
|
Getting Started on Linux
This version of the tutorial is for the 0.85 release of leJOS NXJ. PrerequisitesJava Development KitYou will also need a Java Development Kit (JDK) on your PC. Note that a Java Runtime Environment (JRE) is not sufficient as it does not allow you to compile Java programs. You can download the latest JDK from http://java.sun.com/. Follow the instructions for installing it. leJOS NXJ works has been tested with JDK versions 1.5 and 1.6, but will not work with earlier versions. JDK 1.6 is recommended as some PC samples do not work with JDK 1.5. Note that leJOS has only been tested with the official Sun JDK. You will need to add the JDK bin directory to your system or user PATH,
so that commands such as It is also a good idea to set the environment variable JAVA_HOME to the folder where you installed the JDK, as it is necessary if you use the ant build system. libusbIn order to use a USB connection to your NXT brick on Linux, you will need libusb installed on your sysyem. leJOS requires the legacy 0.1.12 release. On most Linux distributions the 0.1.12 version of the libusb package will normally be installed, but the libusb development package may not be.. You can get more information from http://libusb.sourceforge.net Package DependenciesYou will need to ensure that the packages that leJOS NXJ is dependent on are on your system. To build the jlibnxt JNI library, which is used for USB access, you need the Development files for libusb (libusb-devel). Note that leJOS NXJ uses libusb (legacy release 0.1.12), not libusb1. To build the jbluez library, you need the Development Libraries for Bluetooth applications (bluez-libs-devel). jbluez is only needed if you use the NXTCommBluez comms driver instead of the default NXTCommBluecove. If you do not need jbluez, you can remove the build of it from the build/build.xml file. Note that package names and descriptions may differ with different Linux distributions. Accessing USB devicesIf you are running leJOS NXJ from a non-root user, you will need to ensure that you have read and write access the NXT USB device in /dev/bus/usb. If you can identify the device in /dev/bus/usb, you can do this by: sudo chmod a+w /dev/bus/usb/xxx/yyy However, the yyy number will count up each time the NXT is disconnected and reconnected. A better solution is to use udev rules. How to do this may vary with different Linux systems. To use udev rules, set up a file such as /etc/udev/rules.d/70-lego.rules and populate it with the following lines:
# Lego NXT
This relies on the username you are using being in the lego group. You can modify the file to your requirements. The two vendors are LEGO and Atmel (for the samba driver used in firmware update mode). You may need to reload the rules or restart udev. On some Linux systems, the command to reload the rules is udevadm control --reload-rules. BluetoothIf you want to communicate with the NXT over Bluetooth, you will need a Linux supported Bluetooth dongle or built-in support on your PC. By default leJOS uses Bluecove with is included in the distribution, but there is an option to use the Linux BlueZ API directly. You can use leJOS NXJ without Bluetooth. Downloading the softwareYou can download the leJOS NXJ software from The leJOS NXJ download page. On Linux, leJOS is distributed as a .tar.gz file. Installing leJOSUnpacking the releaseUnpack the release a directory of your choice, e.g. /opt/lejos/ Setting up environment variablesYou need to set:
Setting JAVA_HOME is not always necessary, but is good practice. The bin directory for the JDK may already be on your PATH. With most Linux distributions, you can set these environment variables for the current user in .bash_profile or for all users in /etc/profile. If you use Eclipse and the Eclipse plugin, you will also need to add $NXJ_HOME/bin to LD_LIBRARY_PATH so that the Eclipse plugin can access the leJOS NXJ JNI libraries. This should normally be done in /etc/profile, but this may differ for different Linux distributions. Building the releaseTo build the release, change directory to lejos_nxj/build and type If you do not need jbluez, and you do not have the package dependices for it, you can remove it from the build.xml file. Flashing the FirmwareAs leJOS NXJ is a firmware replacement, you will need to flash the firmware to your NXT. Note that this will overwrite any existing firmware. If you have the standard LEGO firmware or other third-party firmware on your NXT, existing files will be lost. Note that the 0.85 release changes the amount of flash memory reserved for the firmware and the startup menu, so when you first flash the 0.85 firmware any existing files will be lost Make sure your NXT is attached to the PC by its USB cable, and switch it on by pressing the orange button. You can either use the command line nxjflash command or the nxjflashg GUI program. Using the command line: Type Using the GUI version: To run the GUI version type Testing your InstallationYou can check that you have successfully installed leJOS NXJ on your PC and your NXT by compiling and running your first program. Compiling and running your first programJava programs need to be compiled to class files before they can be run. For leJOS NXJ, all the class files that are to be run on the NXT needed to be linked to produce a binary file (with the extension .nxj) and this must then be uploaded to the NXT. To run a sample program, such as the View.java sample, follow these steps: Start a shell session, and change directory to the lejos_nxj/projects/samples/View folder:Compile the program with the nxjc command:
Then link, upload and run it with the nxj command:
You should see the menu of the View sample on your NXT. |
|