Skip to content

Instantly share code, notes, and snippets.

@jeffschulthies
Created October 16, 2014 20:22
Show Gist options
  • Save jeffschulthies/8880d24e6687750ca0bd to your computer and use it in GitHub Desktop.
Save jeffschulthies/8880d24e6687750ca0bd to your computer and use it in GitHub Desktop.
Ultrasonic Avoidance(Go Around)
import lejos.nxt.*;
import lejos.robotics.navigation.*;
public class UltraObstacle {
public static void main(String[] args) throws Exception {
UltrasonicSensor sonic = new UltrasonicSensor(SensorPort.S1);
DifferentialPilot pilot = new DifferentialPilot(2.1f, 4.4f, Motor.A, Motor.B);
while(!Button.ESCAPE.isPressed()) {
if(sonic.getDistance() < 10) {
pilot.setTravelSpeed(8);
//pilot.steer(-90, 90);
pilot.travel(5);
//pilot.steer(-90,90);
pilot.rotate(310);
pilot.travel(-16);
pilot.rotate(-310);
/* if(sonic.getDistance() < 10) {
continue;
}
else{
pilot.travel(-12);
pilot.steer(90,-90);
pilot.travel(3);
pilot.steer(90,-90);
} */
}
else {
pilot.setTravelSpeed(-5);
pilot.backward();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment