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).
I don't have any other NXT languages available, but I did try using the LineLeader class submitted by ChrisB01 in this thread.
The results show that the ChrisB01 class can in fact accurately set the PID constants on the sensor and the release 0.9.0 class still has problems. Specifically, the release 0.9.0 class commands to set the KI Divisor and KD Divisor do not change those values from the default settings and the command to set the KP Divisor sets it to whatever value you have supplied as the KI Divisor.
The code for testing the Release 0.9.0 class:
- Code: Select all
import lejos.nxt.*;
import lejos.nxt.addon.NXTLineLeader;
public class Rel090 {
/** Uses the new NXTLineLeader class included with Release 0.9.0
*/
static NXTLineLeader liner = new NXTLineLeader(SensorPort.S4);
/** Default settings for the sensor are:
* SetPoint=45, Kp=25, KpDiv=32, Ki=0, KiDiv=32, Kd=10, KdDiv=32. **/
public static void main(String[] args) throws InterruptedException {
Rel090 display = new Rel090();
}
public Rel090() {
while (Button.ENTER.isPressed()) { }
liner.wakeUp();
LCD.drawString("Release 0.9.0", 0, 0);
LCD.drawString("Default values: ", 0, 1);
LCD.drawString("SetPoint=" + liner.getSetPoint(), 0, 2);
LCD.drawString("Kp=" + liner.getKP() + " " + "KpDiv=" + liner.getKPDivisor(), 0, 3);
LCD.drawString("Ki=" + liner.getKI() + " " + "KiDiv=" + liner.getKIDivisor(), 0, 4);
LCD.drawString("Kd=" + liner.getKD() + " " + "KdDiv=" + liner.getKDDivisor(), 0, 5);
LCD.drawString("Press orange btn", 0, 6);
Button.ENTER.waitForPressAndRelease();
LCD.clear();
int SetPoint = 12;
int KP = 13, KPDivisor = 14;
int KI = 15, KIDivisor = 16;
int KD = 17, KDDivisor = 18;
liner.setSetPoint(SetPoint);
liner.setKP(KP);
liner.setKD(KD);
liner.setKI(KI);
liner.setKPDivisor(KPDivisor);
liner.setKPDivisor(KDDivisor);
liner.setKPDivisor(KIDivisor);
LCD.drawString("Release 0.9.0", 0, 0);
LCD.drawString("My init values: ", 0, 1);
LCD.drawString("SetPoint=" + liner.getSetPoint(), 0, 2);
LCD.drawString("Kp=" + liner.getKP() + " " + "KpDiv=" + liner.getKPDivisor(), 0, 3);
LCD.drawString("Ki=" + liner.getKI() + " " + "KiDiv=" + liner.getKIDivisor(), 0, 4);
LCD.drawString("Kd=" + liner.getKD() + " " + "KdDiv=" + liner.getKDDivisor(), 0, 5);
LCD.drawString("Press orange btn", 0, 6);
Button.ENTER.waitForPressAndRelease();
}
}
The code for testing the ChrisB01 class:
- Code: Select all
import lejos.nxt.*;
public class ChrisB01 {
/** Uses the LineLeader class written by ChrisB01. That class is stored in the
* same Eclipse folder as this program.
*/
static LineLeader liner = new LineLeader(SensorPort.S4);
/** Default settings for the sensor are:
* SetPoint=45, Kp=25, KpDiv=32, Ki=0, KiDiv=32, Kd=10, KdDiv=32. **/
public static void main(String[] args) throws InterruptedException {
ChrisB01 display = new ChrisB01();
}
public ChrisB01() {
while (Button.ENTER.isPressed()) { }
liner.setSleep('P'); // wake it up; turn it on.
LCD.drawString("ChrisB01 class", 0, 0);
LCD.drawString("Default values: ", 0, 1);
LCD.drawString("SetPoint=" + liner.getSetPoint(), 0, 2);
LCD.drawString("Kp=" + liner.getKp() + " " + "KpDiv=" + liner.getKpDivisor(), 0, 3);
LCD.drawString("Ki=" + liner.getKi() + " " + "KiDiv=" + liner.getKiDivisor(), 0, 4);
LCD.drawString("Kd=" + liner.getKd() + " " + "KdDiv=" + liner.getKdDivisor(), 0, 5);
LCD.drawString("Press orange btn", 0, 6);
Button.ENTER.waitForPressAndRelease();
int SetPoint = 12;
int Kp = 13, KpDivisor = 14;
int Ki = 15, KiDivisor = 16;
int Kd = 17, KdDivisor = 18;
liner.setSetPoint(SetPoint);
liner.setKp(Kp);
liner.setKpDivisor(KpDivisor);
liner.setKi(Ki);
liner.setKiDivisor(KiDivisor);
liner.setKd(Kd);
liner.setKdDivisor(KdDivisor);
LCD.drawString("ChrisB01 class", 0, 0);
LCD.drawString("My init values: ", 0, 1);
LCD.drawString("SetPoint=" + liner.getSetPoint(), 0, 2);
LCD.drawString("Kp=" + liner.getKp() + " " + "KpDiv=" + liner.getKpDivisor(), 0, 3);
LCD.drawString("Ki=" + liner.getKi() + " " + "KiDiv=" + liner.getKiDivisor(), 0, 4);
LCD.drawString("Kd=" + liner.getKd() + " " + "KdDiv=" + liner.getKdDivisor(), 0, 5);
LCD.drawString("Press orange btn", 0, 6);
Button.ENTER.waitForPressAndRelease();
}
}
Note that for an accurate comparison you should shut off the NXT between tests. Each test should accurately show the default values before proceeding. The fact that the NXT plays its startup music after running each program does not reflect a reset of the sensor which only happens when the NXT is powered off and then on.
In all previous threads Andy explained that none of the development team members had this particular sensor so could not really do a lot of testing or debugging. Hopefully someone who does have this sensor can see something I'm missing and help. Failing that, I guess I'm elected to thank Andy for all of his work on 0.9.0 and all the help he provides in this forum by sending him one
Walt
