Example of NXJ Chart Logging

Post your NXJ projects, project ideas, etc here!

Moderators: roger, 99jonathan, imaqine

Example of NXJ Chart Logging

Postby Walt White » Wed Feb 29, 2012 2:03 am

The new NXJ Chart Logging utility is pretty nifty. Thanks to Kirk for providing this useful tool.

I'm having a problem using it within my PID program so I decided to create a very simple Chart Logging program to assist with my troubleshooting. Having gotten the simple program to work I thought I would share it in case other novice programmers are temporarily baffled by some of the configuration and setup steps.

When you run the program it displays a message telling you to launch the NXJChartLogging program on the PC and click the Connect button. Details in the comments. After connected, you press the ENTER button on the NXT to start the logging. This example uses real time logging. Enjoy.

Code: Select all
import java.io.IOException;
import lejos.nxt.*;
import lejos.nxt.comm.Bluetooth;
import lejos.nxt.comm.NXTConnection;
import lejos.util.Delay;
import lejos.util.LogColumn;
import lejos.util.NXTDataLogger;

public class Demo {

   static NXTDataLogger logger = new NXTDataLogger();
   static LogColumn someNumber = new LogColumn("Some Number", LogColumn.DT_INTEGER);
   static LogColumn[] columnDefs = new LogColumn[] { someNumber };
   
   public static void main(String[] args) throws InterruptedException, IOException {
      LCD.drawString("Waiting for ", 0, 2);
      LCD.drawString("bluetooth con to", 0, 3);
      LCD.drawString("PC to log data.", 0, 4);
      LCD.drawString("Launch NXT Chart", 0, 5);
      LCD.drawString("Logger & click", 0, 6);
      LCD.drawString("the Connect btn.", 0, 7);
      
      // From a command line:
      // [leJOS Install Location]\bin\nxjchartinglogger.bat
      // Enter the NXT's name or address.  Be sure you have write permission
      // to the folder chosen by the utility.  If not, change the folder.
      // Click the Connect button

      NXTConnection connection = Bluetooth.waitForConnection();
      logger.startRealtimeLog(connection);
      logger.setColumns(columnDefs);  // must be after startRealtimeLog()
      
      LCD.clear();
      Sound.beep();
      LCD.drawString("Press orange btn", 0, 4);
      LCD.drawString("to start.", 0, 5);
      Button.ENTER.waitForPressAndRelease();
      LCD.clear();
      
      LCD.drawString("Press and hold", 0, 5);
      LCD.drawString("dark gray ESCAPE", 0, 6);
      LCD.drawString("button to stop.", 0, 7);
      
      int startCount = 42;
      
      while (!Button.ESCAPE.isDown()) {
          logger.writeLog(startCount);
               logger.finishLine();
               startCount++;
               Delay.msDelay(500);
      }
      
                logger.stopLogging();
   }
}


The display on the PC updates in real time:

Image

Thanks, again, to Kirk!

Walt
Walt White
Novice
 
Posts: 43
Joined: Sun Aug 06, 2006 11:57 pm
Location: California Central Valley

Re: Example of NXJ Chart Logging

Postby kirkpthompson » Thu Mar 01, 2012 2:46 pm

Hi Walt.

You're welcome and thanks for the kind words.

There is also a sample showing the usage at http://lejos.svn.sourceforge.net/viewvc/lejos/trunk/samples/src/org/lejos/sample/testlogger/TestLogger.java?revision=6347&view=markup.

If you have documentation suggestions, etc., please don't hesitate to post them.

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

Re: Example of NXJ Chart Logging

Postby kirkpthompson » Thu Mar 01, 2012 8:05 pm

Hi Again.

I noticed your reference to PID and would like to point out that the lejos.util.PIDController class has a method for registering a NXTDataLogger instance (implements lejos.util.Logger) which provides integrated data logging for the [major] PID algorithm terms. Code at http://lejos.svn.sourceforge.net/viewvc/lejos/trunk/classes/src/lejos/util/PIDController.java?revision=6419&view=markup. You could try to use that or just peruse the code and see how I implemented logging.

Also, I would like to point out that Aswin has done a lot with the NXTChartingLogger in his IMU work. You can see some of it at http://nxttime.wordpress.com/2011/08/25/the-imu-sensor-filter-part-ii/.

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

Re: Example of NXJ Chart Logging

Postby Walt White » Fri Mar 02, 2012 7:53 pm

Hi Kirk,

Thanks for the link: http://lejos.svn.sourceforge.net/viewvc ... iew=markup

Reading that made the registerDataLogger() method much clearer. There is a lot less coding I have to do, and much less chance of conflicts by letting registerDataLogger() do all the work of defining and then setting the columns. And it's obvious to call registerDataLogger() AFTER connecting to the PC. I also don't have to call writeLog() in my code since that happens automatically in the doPID() method. Launch the Chart Logging utility on the PC and all the PID values just start logging away!

Now I just have to figure out how to use this data to tune my PID edge following robot for the Pursuit contest at Bricks By the Bay in two weeks in Santa Clara, Calif.

Walt
Walt White
Novice
 
Posts: 43
Joined: Sun Aug 06, 2006 11:57 pm
Location: California Central Valley

Re: Example of NXJ Chart Logging

Postby Aswin » Sat Mar 03, 2012 12:57 am

Tuning a PID controller can be difficult. To my experience it is best to start with P and let the others be zero. One you find a good value for P you can introduce a value for D. While tuning D you can also increase P. if you find a satisfactory combination you just use tha and stop tuning.
The I value must be ignored when possible. The I control is troublesome as it can build up to lage values that gives violent output. If you have to use it then you should decrease the P value in the mean time.
One last tip. Write down good combinations of PID values. You'll experiment a lot and will forget about succesful combinations.
My NXT blog: http://nxttime.wordpress.com/
Aswin
Active User
 
Posts: 122
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: Example of NXJ Chart Logging

Postby kirkpthompson » Sat Mar 03, 2012 3:50 pm

I found this works for me: Tune the Kp term to where your process becomes unstable (oscillates, etc.) and then back off the value until it stabilizes again, then add very small amounts of Ki (i.e. 0.00001) to where the the process reaches the setpoint as quickly as possible without instability. The problem with Ki that Aswin mentions can be solved by using the integral windup limiting functionality:
Code: Select all
travelPID.setPIDParam(PIDController.PID_I_LIMITHIGH, 1000);
travelPID.setPIDParam(PIDController.PID_I_LIMITLOW, -1000);
You will have to play with these numbers to tune to your process (of course).

My understanding:
Kp governs the proportional response to the error
Ki governs how fast an error correction is made when setpoint is not reached (error) and when overshooting
Kd governs the magnitude of reduction for the overshoot produced by the Ki term. Note the D term in the controller is highly sensitive to noise in the error, and can cause a process to become unstable if the noise and the derivative gain (Kd) are sufficiently large.

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

Re: Example of NXJ Chart Logging

Postby kirkpthompson » Tue May 15, 2012 1:36 pm

Hi.

There is now PID Tuning functionality for the NXT Charting Logger in the SVN snapshot if anyone feels brave enough to test it. This post http://lejos.sourceforge.net/forum/viewtopic.php?f=7&t=2550&start=15#p16297 has more details.

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


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 0 guests

more stuff