Created
August 30, 2012 08:22
-
-
Save voidw0rd/3524130 to your computer and use it in GitHub Desktop.
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.util.*; | |
import lejos.robotics.navigation.DifferentialPilot; | |
import lejos.robotics.objectdetection.*; | |
import lejos.robotics.*; | |
public class robo implements FeatureListener { | |
DifferentialPilot nerdling; | |
int DISTAMCE = 50; | |
int SCAN = 500; // in milliseconds ... | |
UltrasonicSensor us = new UltrasonicSensor(SensorPort.S4); | |
FeatureDetector fd = new RangeFeatureDetector(us, DISTAMCE, SCAN); | |
// | |
TouchSensor bump = new TouchSensor(SensorPort.S1); | |
FeatureDetector bf = new TouchFeatureDetector(bump, 10, 5); | |
FusorDetector fusion = new FusorDetector(); | |
fusion.addDetector(fd); | |
fusion.addDetector(bf); | |
ObjectDetect listener = new ObjectDetect(); | |
fusion.addListener(listener); | |
public void go() { | |
nerdling.travel(20, true); // void travel(double distance, boolean immediateReturn) | |
while(nerdling.isMoving()) { | |
if(bump.isPressed()) { | |
nerdling.stop(); | |
nerdling.steer(20, 180); // turnRate, angle | |
nerdling.travel(20, true); | |
} | |
} | |
System.out.println("> " + nerdling.getMovement().getDistanceTraveled()); | |
Button.waitForAnyPress(); | |
} | |
public void featureDetected(Feature feature, FeatureDetector detector) { | |
int range = (int)feature.getRangeReading().getRange(); | |
//Sound.playTone(1200 - (range * 10), 100); | |
//nerdling.stop(); | |
nerdling.steer(20, 90); | |
//nerdling.travel(20, true); | |
System.out.println("Range:" + range); | |
} | |
public static void main(String[] args) { | |
LCD.drawString("Testing ..."); | |
robo traveler = new robo(); | |
traveler.pilot = new DifferentialPilot(2.25f, 5.5f, Motor.A, Motor.B); | |
traveler.go(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment