I'm very new in programmation, but I'm tying.
I have a problem, I can Start the two motors at the same time with a while. He can stop when he is 20 cm from anything, but it doesn't stop the 2 motors at the same time, I have one stop et another stop. The robot do a little rotate.
Anybody know whats the problem?
I have this class:
- Code: Select all
public class Moteur {
public Moteur() {
}
public void avancer() {
Motor.A.forward();
Motor.B.forward();
}
public void reculer() {
Motor.A.backward();
Motor.B.backward();
}
public void tournerGauche(){
Motor.A.rotate(320);
}
public void tournerDroite(){
Motor.B.rotate(320);
Motor.A.stop();
}
}
And this other:
- Code: Select all
public class HelloWorld {
private static int dist = 20;
public static void main(String[] args) {
Moteur m = new Moteur();
MotorPort a = MotorPort.A;
UltrasonicSensor u1 = new UltrasonicSensor(SensorPort.S2);
while (u1.getDistance() != dist) {
m.avancer();
}
Motor.A.stop();
Motor.B.stop();
}
}
}
Thanks very much for the help!
