Skip to content

Instantly share code, notes, and snippets.

@voidw0rd
Created August 30, 2012 08:22
Show Gist options
  • Save voidw0rd/3524130 to your computer and use it in GitHub Desktop.
Save voidw0rd/3524130 to your computer and use it in GitHub Desktop.
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