TrackingHardware
Software
Mega PlanEtc. |
Main /
JavaWe have available limited code for controlling both the Brainstem (over I2C or Serial) and the CMUCam2 (over Serial). This code has many bugs in it that we are still ironing out, and we're including it, like other code on this site, primarily to give you a better jumping-off point for development. In particular, we believe a conflict may arise between JamVM and I2C which causes freezing at intermittent points; we're still working on it. Virtual MachinesWe have tried three virtual machines on the Gumstix: JamVM, Wonka, and kaffe. All three VMs are simply bytecode interpreters, so don't expect astonishing speed. JamVM and Wonka have binaries for the ARM architecture; kaffe requires cross-compilation. The long and short of it: use JamVM. It's much faster, smaller, and cleaner. kaffe is the slowest, biggest, and most difficult to port. JamVM also requires the GNU Classpath class library, which has to be loaded onto the Gumstix as well per instructions on the JamVM web page. Using Kaffe (if you must)Download Kaffe as kaffe-console.tar.gz and copy it to the Gumstix. Unpack it into these directories: /mnt/mmc/usr/ /mnt/mmc/usr/lib/ /mnt/mmc/usr/lib/kaffe-console/ /mnt/mmc/usr/lib/kaffe-console/lib/ /mnt/mmc/usr/lib/kaffe-console/jre/lib/ /mnt/mmc/usr/lib/kaffe-console/jre/lib/security/ /mnt/mmc/usr/lib/kaffe-console/jre/lib/arm/ /mnt/mmc/usr/lib/kaffe-console/jre/bin/ Create a symlink back to the root filesystem by running ln -s /mnt/mmc/usr/lib/kaffe-console /usr/lib/ Then run java /usr/lib/kaffe-console/jre/bin/java -cp /mnt/mmc test to get # /usr/lib/kaffe-console/jre/bin/java -cp /mnt/mmc test Hello World! You can also add to the default path and just run 'java' # export PATH=$PATH:/usr/lib/kaffe-console/jre/bin/ # java -cp /mnt/mmc test Hello World! Notes
Where to Put Java and Jar FilesPut "permanent" robot jar files in #!/bin/sh # Set up the classpath to be: .:~/java: ... and various # jars in /usr/local/robot/jar CLASSPATH=.:${HOME}/java:$CLASSPATH for i in `ls /usr/local/robot/jar/*.jar` do CLASSPATH=${CLASSPATH}:$i done export CLASSPATH # Add additional stuff to the CLASSPATH just for JamVM CLASSPATH=${CLASSPATH}:/usr/local/share/classpath/glibj.zip CLASSPATH=${CLASSPATH}:/usr/local/share/jamvm/classes.zip # Run JamVM /usr/local/bin/jamvm -C $CLASSPATH $* BeanShellBeanShell is an enormously useful jar file to have on the Gumstix. It provides a command line for Java, allowing you to issue Java method calls by hand. The bsh-core is sufficient for most needs. Once the jar file has been installed in your CLASSPATH, you can run it with Java CompilersBoth Jikes and KJC (a free javac replacement) work on the Gumstix, part of the Kopi Project. We think that Jikes may occasionally produce incorrect bytecode -- but it's really fast. KJC
Jikes
Communicating with the Brainstem Over SerialYou can use Acroname's proprietary java code to communicate with the brainstem via the serial daemon with a few modifications. First, delete the public void nonBlockingEvent() { if (in != null) { byte readBuffer; try { while (in.available() > 0) { readBuffer = (byte)(in.read()); handleByte(readBuffer); } } catch (IOException e) { System.out.println("error handling byte"); e.printStackTrace(); } } } Next, compile following Java code and include in Acroname's jar file: NonBlockingInputStream.java You can use the code like this: Socket s = new Socket("localhost", 5002); inputStream = new NonBlockingInputStream(s.getInputStream()); ((NonBlockingInputStream)inputStream).registerNonBlockingEvent(stem); /* tell the stream where to get I/O */ stem.SetStream(inputStream, s.getOutputStream()); Communicating with the Brainstem over I2CWe have made a simple class which communicates with the Brainstem over I2C by accessing the Usage: import acroname.*; int a; Brainstem b = new Brainstem(); b.setServo(4,2,220); // set brainstem #4's second servo to 220 a = b.getA2D(4,2); // get brainstem #4's second analog (0 to 64K) a = b.getDigital(4,2); // get brainstem #4's second digital (0 or 1) a = b.getCharScratchpad(4,2); // get brainstem #4's second pad as a byte) a = b.getIntScratchpad(4,2); // get brainstem #4's second and third // scratchpads together as an int) b.setCharScratchpad(4,2,220); // set brainstem #4's second pad to // 220 as a byte) b.setIntScratchpad(4,2,1000); // get brainstem #4's second and third //scratchpads together to 1000 as an int) In all cases the functions return Communicating with the CMUCam2 over SerialThe cmucam.jar file provides some basic code for communicating with the CMUCam2 over the serial daemon on the Gumstix. Java source is included in the jar file (it's only three Java files). The following CMUCamExample.java file provides an example for using the code. The alternative is to use a JNI native interface. We have been working on one designed for use with the CMUCam. It's available as cmucamlibjava.tar.gz with source code. Usage:
Yet to do:
|