コード例 #1
0
ファイル: IBB.java プロジェクト: pfcoperez/tecnicasiarobotica
  // Distance Sensors on front of bot
  public void readProximitySensors(OutputStream out, byte[] buf, int len) {
    try {
      leftRangeFinder.ping(); // Tell the sensor to test the left range sensor
      float leftDistance =
          leftRangeFinder.getDistanceCm(); // Read the distance measured by the left range sensor
      rightRangeFinder.ping(); // Tell the sensor to test the right range sensor
      float rightDistance =
          rightRangeFinder.getDistanceCm(); // Read the distance measured by the right range sensor

      if (leftDistance < 0.0f) leftDistance = leftPreDist;
      else leftPreDist = leftDistance;

      int leftVal = (int) leftDistance;

      if (rightDistance < 0.0f) // out of range (too far or too close)
      rightDistance = rightPreDist;
      else rightPreDist = rightDistance;

      int rightVal = (int) rightDistance;

      writeCRLF(out, "n, " + rightVal + ", " + leftVal);
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }