Created
October 16, 2014 20:22
-
-
Save jeffschulthies/8880d24e6687750ca0bd to your computer and use it in GitHub Desktop.
Ultrasonic Avoidance(Go Around)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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