Bluetooth data logging and debug on the nxt

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Bluetooth data logging and debug on the nxt

Postby Jannick » Wed Sep 19, 2007 12:19 am

Hi

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.

Image

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.
Last edited by Jannick on Mon Sep 24, 2007 12:36 pm, edited 2 times in total.
Jannick
New User
 
Posts: 10
Joined: Sun Sep 16, 2007 3:56 pm

Postby Jannick » Thu Sep 20, 2007 1:14 am

A quick update. I've restructured the code on the nxt-side to get around the constant pool limit, and ive implemented the ability for the client side code to signal additional meta-data about each channel. The initialization code




Code: Select all
      //Establish remote log connection
      RemoteLog log = RemoteLog.waitForConnection(2);
      
      //And setup the logging channels
      log.createChannel(us, SensorPort.S1).defineMarker(75).defineMarker(100).defineRange(10, 30);   
      log.createBatteryChannel();          
      log.endInitialization();   


Now produces a chart with ranges and markers:

Image

Theres obviously still some work to do on getting the colors, opacity and layout correct, but all the meta-data transfer and recording mechanisms have been created. Task for tommorow is named ranges and markers, chart size prioterization and chart colors and layout.
Jannick
New User
 
Posts: 10
Joined: Sun Sep 16, 2007 3:56 pm

Postby Jannick » Mon Sep 24, 2007 12:03 am

A quick progress update. I'm pretty close to being finished with the feature set I plan for my own use. Left to do is the posibility of scrolling in the data after logging have ended, some sort of export, as well as changing to use circular buffers, so that the program doesnt slow down when you run for a long time with a really high sample rate. I expect to be done at about thursday this week, so if theres any interest Ill polish off the apidocs and make it available after then.

The screenshot shows some of the work that has been done. The different type of channels can now be shown in a size relative to their importance. You can add multiple areas and markers to a channel, in order for you to visualize the meaning/interpretation of the values. The battery channel shows the new step rendering option (there is also a point renderer available). At the top of the interface there is now the option to select how many seconds of the data you want displayed.

Image

The meta-data is setup like this in your nxt-side code.

Code: Select all
distanceChannel.defineMarker(125, "Target distance");
distanceChannel.defineRange(50F, 100F);
distanceChannel.defineRange(100F, 125F);
distanceChannel.defineRange(125F, 150F);
distanceChannel.defineRange(150F, 200F);
      
...
batteryChannel.defineRange(0f, 7f, "Battery low");


The meta-data methods all return the object that is acted on, making it possible to chain them:

Code: Select all
distanceChannel.defineMarker(125, "Target distance").defineRange(50F, 100F).defineRange(100F, 125F).defineRange(125F, 150F).defineRange(150F, 200F);
Jannick
New User
 
Posts: 10
Joined: Sun Sep 16, 2007 3:56 pm

Postby Jannick » Mon Sep 24, 2007 7:35 pm

Another quick update. The tool is basicly done at this point, and I expect to toss the source online on thursday. Another member of my study group have the NXT at the moment, and I just want to perform a quick check for stupid bugs before releasing it.

It is now possible to zoom around in the captured data (custom range on both axis) by dragging boxes with the mouse, as well as changing between preset display time ranges, both while capturing and afterwards. If you have found an interesting graph/subgraph, it can then be exported as a png by right clicking on the chart.

The only remaining issue is that the BtOutputStream from the leJOS classes currently sends a bluetooth packet per byte. I intend to perform some test to see if this really is an issue, because otherwise I prefer to wait until a fix becomes part of the platform.
Jannick
New User
 
Posts: 10
Joined: Sun Sep 16, 2007 3:56 pm

When do think to launch your tool?

Postby esmetaman » Mon Sep 24, 2007 7:47 pm

Hi, when do you think to launch your tool?

Thanks.
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
https://github.com/jabrena/livingrobots
http://www.iloveneutrinos.com/
User avatar
esmetaman
Advanced Member
 
Posts: 311
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Postby Jannick » Mon Oct 01, 2007 9:24 pm

Hi. Im getting my hands on the nxt after the comming thursday. Theres a single issue I need to fix, but I didnt get the chance at our last exercise session. So this comming weekend at the latest.
Jannick
New User
 
Posts: 10
Joined: Sun Sep 16, 2007 3:56 pm

Postby Jannick » Sat Oct 06, 2007 2:08 pm

Hi

Been really busy at work, so havnt had much time to work on the tool. Ive slammed together a very alpha release in case anyone want to take a look. I t can be found at http://rapidshare.com/files/60672364/remotelog_0_1_alpha.rar.html

The file contains a very simple readme file detailing the dependencies you will need to run the gui graph app.

Note: I havnt tested that all needed files are in the release, and the tool has never been tested on linux. Let me know if you run into any issues.
Jannick
New User
 
Posts: 10
Joined: Sun Sep 16, 2007 3:56 pm

New Download link?

Postby Jeev » Thu Nov 01, 2007 2:30 am

Hi,

Is there any chance that we could get this file hosted anywhere else?

The RapidShare link is dead.

Thanks
Jeev
New User
 
Posts: 3
Joined: Thu Jun 28, 2007 10:53 pm

Postby MadGinga » Tue Nov 13, 2007 3:07 pm

Hi there,

I agree with Jeev, is there any chance we could get this file rehosted? As I would really interested in this.

Cheers

Martin
MadGinga
New User
 
Posts: 7
Joined: Mon Nov 05, 2007 4:12 pm
Location: UK

Postby PatrickLismore » Fri Nov 16, 2007 8:43 pm

Your project is really interesting i'd like to chat about the bluetooth,

im using bluetooth in my project to connect two robots and send data across.

-------------

If anyone needs files hosted somewhere I have a small hosting company, im sure i could make room for a few files,

dont think its appropiate to post the url here if you need to make use of it pm me.
User avatar
PatrickLismore
Active User
 
Posts: 81
Joined: Tue Oct 16, 2007 7:28 pm
Location: Prague

Re: Bluetooth data logging and debug on the nxt

Postby kirkpthompson » Tue Aug 16, 2011 6:40 pm

Greetings All.

There has been an effort underway to provide a data logging and charting capability in LeJOS. It is planned to be in the next release.

There are two pieces to this:
    The lejos.util.NXTDataLogger class which provides datalogging services on the NXT. This class interacts with the...
    [LeJOS Install location]\bin\nxjchartinglogger.bat (launches lejos.pc.tools.NXJChartingLogger) which provides a Charting and logging GUI on the PC. It supports Bluetooth and USB and provides a dynamic chart of the data [sent from the NXT] which can be manipulated to "explore" your data graphically.
The NXJChartingLogger project is in the SVN repos at http://lejos.svn.sourceforge.net/viewvc/lejos/trunk/org.lejos.charting/ if you want to see what it's about.

A demo of the early prototype of the NXJChartingLogger GUI can be viewed at http://www.youtube.com/watch?v=m2H9mlcd4xk. This demo video was a POC of some screen capture s/w and the quality is not real good. The sound is weak and you will have to turn up your volume.

As always, comments, suggestions, criticisms, etc. always encouraged.

Best
-K
Leg Godt!
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Re: Bluetooth data logging and debug on the nxt

Postby Aswin » Wed Aug 24, 2011 6:35 am

Kirk,

Your data logger seems really nice. I have some questions about it.

Can It handle data from different sources (gyro + accelerometer + tacho's) at the same time? I suppose it does because there is the notion of columns in the code. How are the different columns displayed in the viewer? Is there one chart with multiple lines, is there one chart for each column? Can it save he graph to an image file?
If I want to use it right now (I need to tune some PID controllers), is it sufficient to install the latest build?
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 207
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: Bluetooth data logging and debug on the nxt

Postby kirkpthompson » Wed Aug 24, 2011 1:39 pm

Hi Aswin. Posting this from my phone. Pls. Excuse brevity. ANSWERS:
Yes.
As a series on same chart.
Yes.
Can be if you hide other series and spawn chart in new window.
Yes.
Yes. Also, the lejos.util.PIDController class has support built in

Best,
-K
Leg Godt!
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Re: Bluetooth data logging and debug on the nxt

Postby Aswin » Thu Aug 25, 2011 12:46 pm

Hi,

I can't get it to work, the NXJChartingLogger won't start. What have I done wrong?

I installed the latest build from https://lejos.svn.sourceforge.net/svnro ... k/snapshot using TortoiseSVM. After that I set the environment variables NXJ_HOME and PATH. When I issue NXJchartinglogger on the PC the chartinglogger won't start. This is the error I get:
Code: Select all
Exception in thread "main" java.lang.NoClassDefFoundError: lejos/pc/tools/NXJChartingLogger
Caused by: java.lang.ClassNotFoundException: lejos.pc.tools.NXJChartingLogger
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: lejos.pc.tools.NXJChartingLogger.  Program will exit.


The NXJchartinglogger.bat file resolves to:
Code: Select all
"C:\Program Files\Java\jdk1.6.0_25\bin\java.exe"
-Dnxj.home="C:\Users\Aswin\snapshot"
-DCOMMAND_NAME="nxjchartinglogger"
-classpath "C:\Users\Aswin\snapshot\lib\pc\jtools.jar;C:\Users\Aswin\snapshot\lib\pc\pccharting.jar;C:\Users\Aswin\snapshot\lib\pc\pccomm.jar;C:\Users\Aswin\snapshot\lib\pc\pctools.jar;C:\Users\Aswin\snapshot\lib\pc\3rdparty\bcel.jar;C:\Users\Aswin\snapshot\lib\pc\3rdparty\bluecovegpl.jar;C:\Users\Aswin\snapshot\lib\pc\3rdparty\bluecove.jar;C:\Users\Aswin\snapshot\lib\pc\3rdparty\commonscli.jar;C:\Users\Aswin\snapshot\lib\pc\3rdparty\jcommon.jar;C:\Users\Aswin\snapshot\lib\pc\3rdparty\jfreechart.jar;C:\Users\Aswin\snapshot\lib\pc\3rdparty\stax-api-1.0.1.jar"
lejos.pc.tools.NXJChartingLogger


btw. My program compiles fine using the NXTDataLogger class.
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 207
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: Bluetooth data logging and debug on the nxt

Postby kirkpthompson » Thu Aug 25, 2011 2:07 pm

Hi Aswin. This is probably because the snapshot doesn't have the latest pccharting.jar (my fault). I fixed that. Go get \snapshot\lib\pc\pccharting.jar out of the repos and replace your version. Let me know of this doesn't work.

Best,
-K
Leg Godt!
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Next

Return to NXJ Projects

Who is online

Users browsing this forum: Yahoo [Bot] and 0 guests

cron
more stuff