NXTLineLeader in release 0.9 problems

This is where you talk about the NXJ hardware related topics such as the brick, sensors, LEGO pieces, etc.

Moderators: imaqine, 99jonathan, roger

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

NXTLineLeader in release 0.9 problems

Postby Walt White » Wed Apr 20, 2011 6:47 pm

In a previous thread, Andy suggested:

The line leader class can be seen here:
If you want to use the new classes there really is no need to wait for 0.9 you can use the developer snapshot, not that much will change before 0.9 and any testing you do will be very useful.

So I loaded the referenced NXTLineLeader class into Eclipse and did some testing. Results are below.

Both of the constructors generated errors:

Code: Select all

public NXTLineLeader(I2CPort port, int address) {
   super(port, address, I2CPort.LEGO_MODE, TYPE_LOWSPEED_9V);


Code: Select all

public NXTLineLeader(I2CPort port) {
   this(port, DEFAULT_I2C_ADDRESS);


I followed a suggestion provided by Eclipse and used:

Code: Select all

public NXTLineLeader(I2CPort port) {

It's possible that when using a "complete" 0.9 package the problems described above may be solved, and may solve some of the things described below.

A seemingly obligatory task is to figure out how to generate the real time display of each of the eight sensors shown as a rectangle. To do that I used getCalibratedSensorReading() and noted that the documentation says it returns values in the range [0..255] while I found that the range was [0..100].

A worse problem is the methods to set many of the parameters did not work as I expected. It took awhile to discover that this was the cause of my robot's unexpected behavior. The simplest way to duplicate the problem is to just use the set methods followed by displaying the results of their respective get methods in the LCD.

I did two tests of setting values to something easy to see such as [42..48] and then [12..18] and found:

Code: Select all

parameter| default | set | get | set | get |
SetPoint |   45    |  42 |  42 |  12 |  12 |
KP       |   25    |  43 |  45 |  13 |  15 |
KPDiv    |   32    |  44 |  46 |  14 |  16 |
KI       |    0    |  45 |  0  |  15 |   0 |
KIDiv    |   32    |  46 |  32 |  16 |  32 |
KD       |   10    |  47 |  47 |  17 |  17 |
KDDiv    |   32    |  48 |  32 |  18 |  32 |

SetPoint and KD both work as expected.
KP and KPDiv both have a descrepancy of 2.
KDDiv, KI, and KIDiv always return their default values.

If anyone is interested, I can post the code the calibrating the WHITE and BLACK values and for generating the rectangles for a graphic display of each sensor. Those took a bit of experimentation and may save someone else that time.


User avatar
leJOS Team Member
Posts: 5972
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: NXTLineLeader in release 0.9 problems

Postby gloomyandy » Wed Apr 20, 2011 7:09 pm

The setKI code seems to be using the wrong constant (it uses LL_KP rather than LL_KI). No idea if this will fix that problem or not. Other than that looking at the code I don't really see anything wrong with it and would suspect that the odd values being returned are down to the sensor. You could test this by trying the same thing from NXC (or RobotC if you have it). Unfortunately as I think I mentioned in the other thread I don't think any of the dev team have this sensor so it is hard for us to help much more than that (this code was contributed by a leJOS user).

The return value comment is sort of correct, the actual method could return a value in the 0-255 range, however it may be as seems to be the case that the values returned by the sensor are limited to a range of 0-100. I assume you have access to the actual sensor documentation, does that specify what range the sensor returns?

I will fix the constant error, and also update the doc. Let us know if you find anything else of interest, and if the KI value can be set if the correct constant is used...


Return to “NXJ Hardware”

Who is online

Users browsing this forum: No registered users and 2 guests