Package de.nordakademie.nxtsimulation.gui.representation

Examples of de.nordakademie.nxtsimulation.gui.representation.Obstacle


    sensorStub.setPosX(50);
    sensorStub.setPosY(50);
    sensorStub.setHeading(0);

    // Hindernis direkt vor dem Sensor:
    obstacles.add(new Obstacle(50, 50));
    sensorStub.setObstacles(obstacles);
    ret = sensorStub.i2cComplete(buffer, numBytes);
    assertEquals(1, ret);
    assertEquals((byte) 0, buffer[0]);
  }
View Full Code Here


    sensorStub.setPosX(0);
    sensorStub.setPosY(0);
    sensorStub.setHeading(0);

    // Hindernis vor dem Sensor in kurzer Entfernung:
    Obstacle testObstacle = new Obstacle((int) (5 * ArenaGui.FACTOR_PX_CM), 0);
    obstacles.add(testObstacle);
    sensorStub.setObstacles(obstacles);
    ret = sensorStub.i2cComplete(buffer, numBytes);
    assertEquals(1, ret);
    int halfObstWidthInCm = (int) (testObstacle.getActiveBounds().width/2 / ArenaGui.FACTOR_PX_CM);
    int erwarteterAbstandInCm = 5 - halfObstWidthInCm;
    assertEquals((byte) erwarteterAbstandInCm, buffer[0]);
  }
View Full Code Here

    sensorStub.setPosX(50);
    sensorStub.setPosY(50);
    sensorStub.setHeading(0);

    // Zerst�rtes Hindernis vor dem Sensor:
    Obstacle destroyedObst = new Obstacle(80, 50);
    destroyedObst.setDestroyed(true);
    obstacles.add(destroyedObst);
    sensorStub.setObstacles(obstacles);
    ret = sensorStub.i2cComplete(buffer, numBytes);
    assertEquals(1, ret);
    assertEquals((byte) 255, buffer[0]);
View Full Code Here

    sensorStub.setPosX(0);
    sensorStub.setPosY(0);
    sensorStub.setHeading(0);

    // Hindernis vor dem Sensor, aber zu weit entfernt:
    Obstacle tempObst = new Obstacle(0, 0);
    int halfObstWidhtInCm = (int) ((tempObst.getActiveBounds().width/2) / ArenaGui.FACTOR_PX_CM);
    int obsPosInPx = (int) ((255 + halfObstWidhtInCm) * ArenaGui.FACTOR_PX_CM);
    tempObst.setPosX(obsPosInPx);
    obstacles.add(tempObst);
    sensorStub.setObstacles(obstacles);
    ret = sensorStub.i2cComplete(buffer, numBytes);
    assertEquals(1, ret);
    assertEquals((byte) 255, buffer[0]);
View Full Code Here

    sensorStub.setPosX(0);
    sensorStub.setPosY(0);
    sensorStub.setHeading(0);

    // Hindernis nicht in Sensor-Richtung:
    obstacles.add(new Obstacle(0, 100));
    sensorStub.setObstacles(obstacles);
    ret = sensorStub.i2cComplete(buffer, numBytes);
    assertEquals(1, ret);
    assertEquals((byte) 255, buffer[0]);
  }
View Full Code Here

    sensorStub.setPosX(0);
    sensorStub.setPosY(0);
    sensorStub.setHeading(0);

    // Hindernis mit Winkel-Abweichung von der Sensor-Richtung:
    Obstacle tempObst = new Obstacle(0, 0);
    int halfObstWidhtInCm = (int) ((tempObst.getActiveBounds().width/2) / ArenaGui.FACTOR_PX_CM);
    int halfObstHeightInCm = (int) ((tempObst.getActiveBounds().height/2) / ArenaGui.FACTOR_PX_CM);
    tempObst.setPosX((int) ((8.5 + halfObstWidhtInCm) * ArenaGui.FACTOR_PX_CM));
    tempObst.setPosY((int) ((1.5 + halfObstHeightInCm) * ArenaGui.FACTOR_PX_CM));
    obstacles.add(tempObst);
    sensorStub.setObstacles(obstacles);
    ret = sensorStub.i2cComplete(buffer, numBytes);
    assertEquals(1, ret);
    assertEquals((byte) 9, buffer[0]);
View Full Code Here

   * @return Liste mit generierten Obstacles.
   */
  private List<Obstacle> generateRandomObstacles(int obsCount) {

    List<Obstacle> randObsList = new ArrayList<Obstacle>();
    Obstacle tempObs = new Obstacle(0, 0);

    int obsWidth = tempObs.getActiveBounds().width;
    int obsHeight = tempObs.getActiveBounds().height;
    int posXmax = arenaGui.getCanArena().getBounds().width - obsWidth;
    int posYmax = arenaGui.getCanArena().getBounds().height - obsHeight;
    int randPosX;
    int randPosY;

    Random rand = new Random();
    boolean collisionDetected = false;
    Obstacle newRandObs;

    long startTime = System.currentTimeMillis();
    // maximale Laufzeit f�r die Generierung, falls durch
    // die Zufallspositionen zu viele Kollisionen zwischen den Obstacles
    // auftreten oder die Fl�che vollst�ndig belegt ist mit Obstacles.
    long maxTime = 100;
    long timeDiff = 0;
    int obsNr = 1;

    while (obsNr <= obsCount && timeDiff < maxTime) {
      randPosX = (int) (rand.nextInt(posXmax) + ((double) obsWidth / 2));
      randPosY = (int) (rand.nextInt(posYmax) + ((double) obsHeight / 2));

      newRandObs = new Obstacle(randPosX, randPosY);
      collisionDetected = false;
      for (Obstacle randObs : randObsList) {
        if (randObs.getActiveBounds().intersects(
            newRandObs.getActiveBounds())) {
          collisionDetected = true;
        }
      }
      if (!collisionDetected) {
        randObsList.add(newRandObs);
View Full Code Here

    // 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());

View Full Code Here

TOP

Related Classes of de.nordakademie.nxtsimulation.gui.representation.Obstacle

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.