With these 3 methods:
controlMotor(power, mode);
resetTachoCount();
getTachoCount();
This code moves a motor connected to the B port with 90 degrees, then it stops the motor.
- Code: Select all
MotorPort.B.controlMotor(70, 1);
while(MotorPort.B.getTachoCount() < 90)
{
}
MotorPort.B.controlMotor(70, 3);
After I run the previous code, if I try to find out MotorPort.B.getTachoCount() I get different values. Theoretically it should be 90.
How did I test it?
With this code:
- Code: Select all
import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.MotorPort;
public class Test_motors
{
public static void main(String[] args) throws Exception
{
int x = 10;
MotorPort.B.controlMotor(70, 1);
while(MotorPort.B.getTachoCount() < 90)
{
}
MotorPort.B.controlMotor(70, 3);
LCD.drawString("V: " + MotorPort.B.getTachoCount(), 0, 5);
Thread.sleep(x);
LCD.drawString("V2: " + MotorPort.B.getTachoCount(), 0, 6);
while(!Button.ENTER.isPressed())
{
}
Button.ENTER.waitForPressAndRelease();
}
}
"V: " displays the value on the LCD immediately after the motor was stopped.
"V2: " displays the value on the LCD after a set time.
Look what happens for some values for x :
x = 10 -----------MotorPort.B.getTachoCount() = 93
x = 20 -----------MotorPort.B.getTachoCount() = 96
x = 30 -----------MotorPort.B.getTachoCount() = 99
x = 40 -----------MotorPort.B.getTachoCount() = 101
x = 50 -----------MotorPort.B.getTachoCount() = 102
x = 60 -----------MotorPort.B.getTachoCount() = 103
x = 70 -----------MotorPort.B.getTachoCount() = 104
x = 80 -----------MotorPort.B.getTachoCount() = 105
x = 90 -----------MotorPort.B.getTachoCount() = 105
x = 100 ----------MotorPort.B.getTachoCount() = 106
x = 150 ----------MotorPort.B.getTachoCount() = 106
x = 500 ----------MotorPort.B.getTachoCount() = 106
x = 2000 ---------MotorPort.B.getTachoCount() = 106
x = 10000 --------MotorPort.B.getTachoCount() = 106
Conclusion
My conclusion is that after the motor stops (meaning after the command MotorPort.B.controlMotor(70,3) )...it continues to move with approximately 16 degrees. Why is this happening?
It's very frustratring when I'm trying to switch between 3 recipients, and I'm always checking the getTachoCount() to know at which recipient I am right know. Everytime I lose 16 degrees.
Why why why? Please, help.
NOTE: No external force is messing with the motor. I'm not touching it.
