Package lejos.nxt

Examples of lejos.nxt.UltrasonicSensor


  public void testCercaContextNoObstacle() {
    NativeSensorPortStub nativeSensorPortStub = new NativeSensorPortStub();
    nativeSensorPortStub.setISensorPort(0, sensorStub);
    NativeSensorPort nativeSensorPort = NativeSensorPort.getInstance();
    nativeSensorPort.setBehaviour(nativeSensorPortStub);
    UltrasonicSensor sensor = new UltrasonicSensor(SensorPort.S1);
    sensorStub.setPosX(0);
    sensorStub.setPosY(0);
    sensorStub.setHeading(0);

    // Continous-Modus testen (ist der default-Modus):
    sensor.continuous();
    assertEquals(255, sensor.getDistance());

    // Ping-Modus testen:
    sensor.ping();
    assertEquals(255, sensor.getDistance());
  }
View Full Code Here


  public void testCercaContextConfig() {
    NativeSensorPortStub nativeSensorPortStub = new NativeSensorPortStub();
    nativeSensorPortStub.setISensorPort(0, sensorStub);
    NativeSensorPort nativeSensorPort = NativeSensorPort.getInstance();
    nativeSensorPort.setBehaviour(nativeSensorPortStub);
    UltrasonicSensor sensor = new UltrasonicSensor(SensorPort.S1);
    sensorStub.setPosX(0);
    sensorStub.setPosY(0);
    sensorStub.setHeading(90);
   
    // �berpr�fung der Ma�einheit
    // Damit das letzte Element des Arrays leer ist:
    char [] charBuff6 = "10E-2m".toCharArray();
    char [] charBuff7 = new char[7];
    for(int i=0;i<6;i++)
      charBuff7[i] = charBuff6[i];
    assertEquals(new String(charBuff7, 0, 7), sensor.getUnits());
   
    // �berpr�fung der Modus-Setzung
    sensor.continuous();
    assertEquals((byte) 2, sensor.getMode());
    sensor.ping();
    assertEquals((byte) 1, sensor.getMode());
  }
View Full Code Here

  public void testCercaContextWithObstacles() {
    NativeSensorPortStub nativeSensorPortStub = new NativeSensorPortStub();
    nativeSensorPortStub.setISensorPort(0, sensorStub);
    NativeSensorPort nativeSensorPort = NativeSensorPort.getInstance();
    nativeSensorPort.setBehaviour(nativeSensorPortStub);
    UltrasonicSensor sensor = new UltrasonicSensor(SensorPort.S1);
    sensorStub.setPosX(0);
    sensorStub.setPosY(0);
    sensorStub.setHeading(90);

    // Continous-Modus testen (ist der default-Modus):
    assertEquals(255, sensor.getDistance());

    // Ein Obstacle, aber nicht per Sensor erreichbar:
    obstacles.add(new Obstacle(100, 20));
    sensorStub.setObstacles(obstacles);
    sleep15ms();
    assertEquals(255, sensor.getDistance());

    // Ein Obstacle vor dem Sensor:
    Obstacle tempObst = new Obstacle(0, 0);
    int halfObstHeightInCm = (int) ((tempObst.getActiveBounds().height/2) / ArenaGui.FACTOR_PX_CM);
    tempObst.setPosY((int) ((20 + halfObstHeightInCm) * ArenaGui.FACTOR_PX_CM));
    obstacles.add(tempObst);
    sensorStub.setObstacles(obstacles);
    sleep15ms();
    assertEquals(20, sensor.getDistance());

    // Ping-Modus testen:
    sensor.ping();
    int dist[] = new int[8];
    sensor.getDistances(dist);
    for (int i = 0; i < dist.length; i++) {
      assertEquals(20, dist[i]);
    }
  }
View Full Code Here

public class CheckSonicAction implements Action {
  private int distance;
 
  public void run() {
    UltrasonicSensor sensor = new UltrasonicSensor(SensorPort.S1);
    distance = sensor.getDistance();   
  }
View Full Code Here

  public static UltrasonicTester getInstance(){
    if (tester == null) {
      tester = new UltrasonicTester();
      tester.motor = new NXTRegulatedMotor(MotorPort.B);
      tester.motor.setSpeed(tester.sensorMotorSpeed);
      tester.sensor = new UltrasonicSensor(SensorPort.S4);
      tester.sensor.setMode(2);
     
      LCD.clear();
      LCD.drawString("Ultrasonic Testing", 0, 0);
      LCD.drawString("Press Escape\n to exit", 0, 1);
View Full Code Here

  private GoalFindUltrasonicSensor() {}
 
  public static GoalFindUltrasonicSensor getInstance() {
    if (goalFindUltrasonic == null) {
      goalFindUltrasonic = new GoalFindUltrasonicSensor();
      ultrasonicSensor = new UltrasonicSensor(SensorPort.S4);
      sweepMotor = new NXTRegulatedMotor(MotorPort.B);
      de = DataExchange.getInstance();
      sweepMotor.setSpeed(sweepSpeed);
    }
   
View Full Code Here

  private Ultrasonic () { }
 
  public static Ultrasonic getInstance() {
    if (ultrasonic == null) {
      ultrasonic = new Ultrasonic();
      us = new UltrasonicSensor(port);
      us.setMode(2); //set to continuous
      de = SumoDataExchange.getInstance();
    }
   
    return ultrasonic;
View Full Code Here

TOP

Related Classes of lejos.nxt.UltrasonicSensor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.