I've been working on a tool that makes it possible for my leJOS programs to report sensor readings and other values back to a computer in real time.
The system is based on the notion of channels, which you create a number of as your nxt program starts up. A channel allows you to sample specific type of values (or value tupples) and send them to the corresponding channel on the pc side. When you create the channel you can specify name, type, and other meta-data, which is then sent once an for all to the pc. After all channels have been created you leave "initialization mode", and you can now start to report data. The program on the pc side get access to all the meta-data, and can then auto-configure itself to do something intelligent with the data.
The test program below demonstrates a simple usage of the tool. Credit for the original version of the program goes to Ole Caprani, at the department of computer science, århus, denmark. Two channels are created, one that samples from a ultrasonic sensor, and one that reads values from the Battery class. The program also demonstrates a print feature included in the tool, which allows you to print values to a "console" on the pc.
- Code: Select all
public class SonicSensorTest {
public static void main(String [] args) throws Exception {
//Set up engines and sensors
UltrasonicSensor us = new UltrasonicSensor(SensorPort.S1);
//Establish remote log connection
RemoteLog log = RemoteLog.waitForConnection(2);
//And setup the logging channels
log.createChannel(us, SensorPort.S1, "My ultrasonic sensor");
log.createBatteryChannel();
log.endInitialization();
//Example of using print
log.print("Hello World!");
log.print(true);
log.print(42);
LCD.clear();
LCD.drawString("Distance: ", 0, 0);
while (! Button.ESCAPE.isPressed()){
LCD.drawInt(us.getDistance(),4,10,0);
LCD.refresh();
log.autoSample();
log.sendSamples();
Thread.sleep(300);
}
LCD.clear();
LCD.drawString("Program stopped", 0, 0);
LCD.refresh();
}
}
The screenshot below here shows the result of opening my demo live-view program, starting the program on the nxt, and then hitting the start button in the gui.
No code on the pc-side have been custom tailored to handle this specific nxt-side program. The program have instead auto-configured based on the meta-data from the nxt, which makes it very easy to setup logging. The pc-side program does not have to be restarted after each session, which allows you to study the output, change and redeploy the program, and then simply start up a new session from the gui.
My plan is to make the tool as and the underlying comm utilities available as source code once Ive gotten some more features implemented and Ive tested it for actual use. Theres still some work to be done on the charting code (its using Jfreechart btw), and I have some restructuring to do in the nxt-side classes. Its currently organised as a Channel interface and a RemoteLog class that acts as a facade, but Ive hit the nxt's constant pool limit, and therefore have to move the inner classes out of the RemoteLog class. Some planned features to come are:
- * Define (range) areas from the nxt, that a chart tool can then use to background color that range. Can be used to show how sensor readings are placed compared to thresholds and areas from the logic of the code
* Have the stop button send a shutdown command to the nxt, which sets a flag that can then be checked by a program. Purpose would be to make the debug-reploy cycle even easier.
* Perhaps add the means for the pc-side program to push new values to the nxt. Could be used to change threshold values and such on the run. This will probabbly not be implemented for some time.
* Some means of saving the data after a session has ended. JFreeChart has the posibility of exporting to svg and pdf files, so such exports as well as possibly some cvs export might be on the table.
Anyhow just thought I would share my progress so far, more updates will follow as I get the last things fixed.

