I've just started programming the NXT using the NXC language and I've come up against a problem I'm hoping some kind soul here can help me with...
I'm trying to write a function that centres the rack-and-pinion steering on a buggy using the following logic:
1. Turn the steering (motor) until it stalls (i.e. MotorRotationCount() returns the same number either side of a Wait(100))
2. Turn the steering (motor) back a known rotation (400 degrees in this case)
3. Store the value now returned by MotorRotationCount() as the centred steering value (I've tried using ResetRotationCount() but it doesn't seem to do anything)
However, when I set the steering (motor) to the stored "centred" value, the motor stops in a different position. I've tried using MotorTachoCount() as well, and I get slightly different results (sometimes) that I can't seem to predict...
Can anybody tell me what exactly MotorRotationCount() and MotorTachoCount() do and how they differ, please? Do they return absolute (i.e. position) or some sort of relative value (e.g. degrees rotation since the motor was last turned on or something...). Also, why don't ResetRotationCount() or ResetTachoCount() seem to set their respective values to zero?
Thanks for any help with this,
monxc
p.s. Just for completeness, here's my code:
Code: Select all
sub cntrSteer()
{
bool stalled = FALSE;
int curCnt;
ResetRotationCount(OUT_C);
NumOut(0,LCD_LINE1,MotorRotationCount(OUT_C),TRUE);
OnFwd(OUT_C, 25);
while(!stalled)
{
curCnt = MotorRotationCount(OUT_C);
Wait(100);
if(curCnt == MotorRotationCount(OUT_C))
{
stalled = TRUE;
}
}
taskBeep();
NumOut(0,LCD_LINE2,MotorRotationCount(OUT_C),DRAW_OPT_LOGICAL_OR);
RotateMotor(OUT_C, 60, -440);
//ResetRotationCount(OUT_C);
Wait(500);
CNTR = MotorRotationCount(OUT_C);
NumOut(0,LCD_LINE3,MotorRotationCount(OUT_C),DRAW_OPT_LOGICAL_OR);
taskBeep();
}
Code: Select all
sub truckCntr()
{
while(MotorRotationCount(OUT_C) != CNTR)
{
if(turnAngle < 0)
{
OnFwd(OUT_C,60);
}
if(turnAngle > 0)
{
OnRev(OUT_C,60);
}
}
Off(OUT_C);
NumOut(0,LCD_LINE4,MotorRotationCount(OUT_C),DRAW_OPT_LOGICAL_OR);
}