Installing leJOS and Eclipse plugin on CrunchBang Linux in a VMWare Fusion 5 virtual machine on a MacBook Pro running OS X Mountain Lion 10.8.2

How’s that for a search engine friendly title? lol

I’m a big fan of RobotC and have used it since I started programming Lego Mindstorms, but sometimes the relatively basic IDE (with no other options) and odd little bugs that defy fixing (or maybe it is my code, either way I should really bring it up in the forum or raise a bug report but sometimes I just want to get on with coding, I’m so impatient) frustrate me. I have been looking at leJOS for a while mainly because it has support for some key robotic functions such as localisation and subsumption architecture built in, and it can be used from either the command line or also from within the brilliant Eclipse IDE via a plugin. I’m sure leJOS isn’t perfect either, but I want to give it a try to see how it compares.

leJOS and Eclipse run on the main OS’s i.e. Win, Mac and Linux and notionally I could run them on my Mac, but with all the security issues with the Java browser plugin recently (which is separate from the Java VM which is required for leJOS and Eclipse), I just don’t feel at this stage like installing any Java on my main OS, just in case. A friend had also recently recommended CrunchBang Linux which runs with the OpenBox window manager, and to be honest I am in love. CrunchBang is simple, elegant with application windows literally popping off the dark UI and it’s fast as hell. I also quite like to program in a ‘clean environment’ with no distracting notifications, emails or other gumph. Just an IDE and a web browser for documentation and problem searching is good for me.

CrunchBang Linux

CrunchBang linux is pretty, and fast!

I also think that Mac OS X is coming to the end of it’s useful life for me and has too many little irritations, so I am starting to look around for another main OS. But that is another story….

So, here is my guide to getting leJOS and Eclipse setup on CrunchBang 11 Waldorf 64bit in a virtual machine.

  • The links after each step are generally for further reference, but sometimes if the bits of a step are complicated you will have to follow the link.
  • I also mention CTRL-click, if you have a multi button mouse you can right click.
  • Anything that starts with a $ should be entered in a Terminal.

I hope it helps, someone!

Install and setup CrunchBang Linux

Install CrunchBang linux by going into VMWare Virtual Machine Library and adding the downloaded ISO. Start this up and setup as seems best.

Once setup finishes and you login for the first time a setup script will run. There are default answers to many questions, the defaults are usually good, but at one point you will be asked whether you want to update the ‘maintainers config file’ (or similar, I can’t remember), enter YES to get the most up to date linux kernel and to allow you to install the relevant kernel headers in a following step.

After this, shutdown the VM (virtual machine), VM settings>USB and change compatibility to USB 1.1 *** CRITICAL on MBP for NXT to be recognised consistently? ***

I setup VMWare System Settings Processors & Memory to give CrunchBang 4 of 8 processor cores and 8GB of 16GB  memory, this is more than VMWare recommends, but I’d rather give it a bit more for better performance. And Display setting has enabled 3D graphics.

At this point the VM will not work so well e.g. display size, mouse and cut/paste between host OS and VM. This will be sorted in a few mins when the VMWare Tools are installed.

I like to shutdown the guest OS now and either make a ‘snapshot’ of the VM file in the Virtual Machine Library, or make a copy of the VM file to keep somewhere safe. That way, if the following steps go wrong, then it is easy to go back to a clean install without re-installing the whole thing.

http://crunchbang.org/

Install relevant kernel headers (needed for VMWare Tools)

$ sudo apt-get install linux-headers-$(uname -r)

http://askubuntu.com/questions/40979/what-is-the-path-to-the-kernel-headers-so-i-can-install-vmware

Install VMWare Tools

Virtual Machine on top menu>Install VMWare Tools. After a short wait the File Manager should pop up with the VMWare Tools files auto mounted, follow instructions linked below.

Whilst the script is running it is important to pay attention to the questions asked. Often the defaults are OK, but e.g. I don’t like guest OS’s sharing my host OS folders so I set this option to NO rather than the default YES.

https://pubs.vmware.com/server1/vm/wwhelp/wwhimpl/common/html/wwhelp.htm?context=vm&file=tools_server.4.12.html

https://help.ubuntu.com/community/VMware/Tools

Install Dropbox from Dropbox site

I installed 64 bit CrunchBang, if you selected 32bit, then visit the Dropbox site for a relevant version, else:

$ cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -

Edit ~/.config/openbox/autostart and add

~/.dropbox-dist/dropboxd &

The easiest way is to CTRL click on desktop>Settings>OpenBox>Edit autostart. The ampersand (&) is necessary at the end of each line in autostart, if your system starts acting oddly after adding a line in here, it might be you forgot the ampersand like I did!

http://crunchbang.org/forums/viewtopic.php?id=21171

CrunchBang tweaks, personal preference

Install Google Chrome

  • There are plenty good browsers for Linux, but I do like Google Chrome the best for security, the great extensions and seamless sync across accounts and devices.
  • Can be installed by CTRL clicking, Browsers>Install Google Chrome.

Set display resolution (possibly not needed after VMWare Tools installed)

Set mouse speed, the values in xset cover acceleration and threshold, the values below are close to the values in OS X.

  • Edit ~/.config/openbox/autostart and add

xset m 25 1 &

Set mouse focus in Settings>OpenBox>GUI Config Tool

Change CTRL-click menu with Settings>OpenBox>menu.xml

Setup for Apple keyboard. Apple Aluminium ISO, Apple. I can not get the ~ (tilde) symbol working, but you can also use $HOME to quickly reference your home directory.

  • $ sudo dpkg-reconfigure keyboard-configuration
  • Can also setup manually by editing /etc/default/keyboard which should contain

XKBMODEL=”applealu_iso”
XKBLAYOUT=”gb”
XKBVARIANT=”mac”
XKBOPTIONS=”"

Apple magic mouse multi-touch, looks like this is not possible as the VM does the comms. If was a hard drive install then multi-touch is possible in Ubuntu at least via a driver, I don’t know about Debian based CrunchBang.

File manager slow to start?

Correct clock and time zone if not right

Install leJOS

Install JDK (Java Development Kit)

  • $ sudo apt-get install openjdk-6-jdk

Install LibUSB

  • $ sudo apt-get install libusb-dev

Setup USB access

  • $ sudo nano /etc/udev/rules.d/70-lego.rules
  • and add (should be 4 lines, not 6 as formatted below, so cut and paste to get it right):

# Lego NXT brick in normal mode
SUBSYSTEM==”usb”, DRIVER==”usb”, ATTRS{idVendor}==”0694″, ATTRS{idProduct}==”0002″, GROUP=”lego”, MODE=”0660″
# Lego NXT brick in firmware update mode (Atmel SAM-BA mode)
SUBSYSTEM==”usb”, DRIVER==”usb”, ATTRS{idVendor}==”03eb”, ATTRS{idProduct}==”6124″, GROUP=”lego”, MODE=”0660″

Create a new group for accessing the USB ports and add yourself into it

  • $ sudo groupadd lego
  • $ sudo gpasswd -a <yourusername> lego
  • Do not forget the -a (append) flag! I did, not pretty!

Reboot the virtual machine, easy to do by CTRL clicking the desktop and selecting Exit from the menu. I love X!

Obtain LeJOS and create a leJOS folder with the files in

  • $ cd /home/<user>
  • $ wget http://sourceforge.net/projects/lejos/files/lejos-NXJ/0.9.1beta/leJOS_NXJ_0.9.1beta-3.tar.gz
  • $ sudo tar xvf leJOS_NXJ_0.9.1beta-3.tar.gz
  • $ cd /opt
  • $ sudo mv ~/leJOS_NXJ_0.9.1beta-3/ leJOS_NXJ/

Build

  • $ cd /opt/leJOS_NXJ/build
  • $ sudo ant
  • Might need to install ‘ant’ with synaptic package manager or with $ sudo apt-get install ant.

Environment variables

  • These can be set globally, but I prefer them in my home directory.
  • $ cd ~
  • $ sudo nano .profile
  • Add in at end:

NXJ_HOME=/opt/leJOS_NXJ
LEJOS_NXJ_JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64
PATH=/opt/leJOS_NXJ/bin:$PATH

Reboot the virtual machine. Or restart X.

Install leJOS firmware

  • Reset NXT using reset on back of NXT for 4seconds to get it into firmware mode, the NXT should be making a ticking sound. This step doesn’t always seem to be necessary, but using any error messages in Terminal as a guide.
  • I had a lot of problems with this working sometimes and not others with a ‘no NXT found on USB’ type error message. I fixed this by changing the VMWare USB setting from USB compatibility 2.0 to 1.1.
  • $ cd /opt/leJOS/bin
  • The above dir change is not really necessary as the files are in the PATH, but useful to explore the bin directory.
  • $ nxjflash

Try a few command line leJOS tools

  • See connected NXTs
    • $ nxjbrowse
  • Control the connected NXT and view sensor values
    • $ nxjcontrol

Good leJOS install instructions at:

—————————————————-

Other stuff!

Some other stuff that I needed to do previously when messing about, but didn’t seem necessary for the above procedure. Given here just in case.

You might need to make the leJOS programs executable

  • $ cd ~/opt/leJOS_NXJ/bin
  • $ sudo chmod +x nxj*

List USB ports and what is connected

  • $ lsusb
  • Add -v flag for a verbose list.
  • If NXT has firmware then will list as ‘Mindstorms’, if in firmware mode will list as ‘AMTEL modem’
  • You can bodge a temp USB connection to the NXT if the 70-lego.rules is causing issues, with $ sudo chmod a+w /dev/bus/usb/xxx/yyy where xxx is the Bus value and yyy is the Device value given by $ lsusb

———————————————————————————————

Install Eclipse

My thanks to all those who have taken the time to create all these awesome tools and to those who write up their experiences in Linux, leJOS and all life other fun things in the above links, you made life so much easier. If you really like CrunchBang Linux, you can donate at the CrunchBang Donation page.

Have fun!