I'm using leJOS with an NXT robot. I want to scan the distances of objects from my robot. While rotating the Ultrasonic sensor from right to left, I would like to find out which object is closest to me.
Motor.A.isRotating()
seemed to me as a good idea, but later I found out that leJOS hasn't implemented it yet. They are suggesting using isMoving()
instead. So I tried this:
while(!Button.ESCAPE.isDown())
{
Motor.A.rotateTo( 40);
while(Motor.A.isMoving())
{
value = sonic.getDistance();
LCD.clear();
LCD.drawString("Distance: ", 0, 2);
LCD.drawInt(value, 0, 3);
LCD.refresh();
Thread.sleep(100);
}
Thread.sleep(100);
Motor.A.rotateTo( -40);
while(Motor.A.isMoving())
{
value = sonic.getDistance();
LCD.clear();
LCD.drawString("Distance: ", 0, 2);
LCD.drawInt(value, 0, 3);
LCD.refresh();
Thread.sleep(100);
}
Thread.sleep(100);
}
I'm open to suggestions and tips! Thank you!