Created
October 16, 2014 20:22
-
-
Save jeffschulthies/2256c5ef20265a6ebcc8 to your computer and use it in GitHub Desktop.
Ultrasonic Avoidance
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
//General Avoidance | |
import lejos.nxt.*; | |
import lejos.robotics.navigation.*; | |
public class Ultra { | |
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(320); | |
/* 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