NXC  Version 1.2.1 r5
 All Data Structures Files Functions Variables Groups Pages
ex_NXTLineLeader.nxc

This is an example of how to use the NXTLineLeaderSteering, NXTLineLeaderAverage, NXTLineLeaderResult, NXTLineLeaderPowerDown, NXTLineLeaderPowerUp, NXTLineLeaderInvert, NXTLineLeaderReset, NXTLineLeaderSnapshot, NXTLineLeaderCalibrateWhite, NXTLineLeaderCalibrateBlack, SetNXTLineLeaderSetpoint, SetNXTLineLeaderKpValue, SetNXTLineLeaderKiValue, SetNXTLineLeaderKpValue, SetNXTLineLeaderKpFactor, SetNXTLineLeaderKiFactor, SetNXTLineLeaderKdFactor, SetSensorLowspeed, NumOut, and Wait functions.

task main()
{
SetSensorLowspeed(S1); // NXTLineLeader is an i2c device
char val;
// position sensor over white surface for 1 second
// position sensor over black surface for 1 second
// position sensor over line
byte steering, average, result;
NumOut(0, LCD_LINE1, steering);
NumOut(0, LCD_LINE2, average);
NumOut(0, LCD_LINE3, result);
// put the device to sleep
// wake up the device
// invert colors (white line on black surface)
// reset back to default colors
// take a snapshot of the surface below the device
// set sensor configuration values to non-defaults
val = SetNXTLineLeaderSetpoint(S1, MS_ADDR_LINELDR, 10); // default is 45
// set PID values
val = SetNXTLineLeaderKpValue(S1, MS_ADDR_LINELDR, 100); // default is 25
val = SetNXTLineLeaderKiValue(S1, MS_ADDR_LINELDR, 10); // default is 0
val = SetNXTLineLeaderKdValue(S1, MS_ADDR_LINELDR, 50); // default is 8
// set PID factors
val = SetNXTLineLeaderKpFactor(S1, MS_ADDR_LINELDR, 40); // default is 32
val = SetNXTLineLeaderKiFactor(S1, MS_ADDR_LINELDR, 40); // default is 32
val = SetNXTLineLeaderKdFactor(S1, MS_ADDR_LINELDR, 40); // default is 32
}