コード例 #1
0
 public void checkIfSharpCorner() {
   leftMotor.stop();
   rightMotor.stop();
   isSharpCorner = false;
   int performedRotation = 0;
   DifferentialPilot pilot = new DifferentialPilot(2, 10, leftMotor, rightMotor);
   if (getRealTimeValue() >= 0.1) {
     pilot.rotate(-4);
     isSharpCorner = true;
     tellLineBehaviorIsSharpCorner();
   } else {
     for (int i = 0; i <= 40; i++) {
       pilot.rotate(1);
       performedRotation += 1;
       if (getRealTimeValue() >= 0.1) {
         isSharpCorner = true;
         tellLineBehaviorIsSharpCorner();
         break;
       }
       if (Button.readButtons() != 0) {
         this.interrupt();
       }
     }
   }
   if (!isSharpCorner) {
     align(pilot, performedRotation);
     line.setIsNoSharpCorner();
   }
 }
コード例 #2
0
  public ManageNxtSteering(DataExchange DE) {
    // initialize variables
    DEObj = DE;

    centreMotor = Motor.B;
    centreMotor.resetTachoCount();
    curPos = centreMotor.getTachoCount();
    centreMotor.setSpeed(MIN_STEER_SPD);
    // centreMotor.setAcceleration(10000);
    centreMotor.flt();

    oldDyn = 0;
    newCmd = DataExchange.NULL_CMD;
    isNxtStop = isNxtCalib = false;
  };
コード例 #3
0
 @Override
 public void waitComplete() throws RemoteException {
   motor.waitComplete();
 }
コード例 #4
0
 @Override
 public void flt(boolean immediateReturn) throws RemoteException {
   motor.flt(immediateReturn);
 }
コード例 #5
0
 @Override
 public RegulatedMotorListener removeListener() throws RemoteException {
   return motor.removeListener();
 }
コード例 #6
0
 @Override
 public int getSpeed() throws RemoteException {
   return motor.getSpeed();
 }
コード例 #7
0
 @Override
 public int getLimitAngle() throws RemoteException {
   return motor.getLimitAngle();
 }
コード例 #8
0
 @Override
 public void rotateTo(int limitAngle) throws RemoteException {
   motor.rotateTo(limitAngle);
 }
コード例 #9
0
 @Override
 public void backward() throws RemoteException {
   motor.backward();
 }
コード例 #10
0
 @Override
 public void forward() throws RemoteException {
   motor.forward();
 }
コード例 #11
0
 @Override
 public void close() throws RemoteException {
   motor.close();
 }
コード例 #12
0
 @Override
 public void setAcceleration(int acceleration) throws RemoteException {
   motor.setAcceleration(acceleration);
 }
コード例 #13
0
 @Override
 public void setStallThreshold(int error, int time) throws RemoteException {
   motor.setStallThreshold(error, time);
 }
コード例 #14
0
 @Override
 public boolean isStalled() throws RemoteException {
   return motor.isStalled();
 }
コード例 #15
0
  public void run() {

    // infinite task
    while (true) {
      // retrieve decoded opcode info
      synchronized (this) {
        newDyn = DEObj.getNxtDyn();
        newCmd = DEObj.getNxtCmd();
        newPos = DEObj.getNxtPos();
        curPos = centreMotor.getTachoCount();
        DEObj.setCurSteerPos(curPos);
      }
      ;

      // steer to newPos, if conditions apply
      if ((newCmd != DataExchange.EXIT_CMD) && (newCmd != DataExchange.NULL_CMD)) {
        if (oldDyn != newDyn) {
          oldDyn = newDyn;

          switch (newCmd) {
            case DataExchange.STOP_CMD:
              isNxtStop = true;
              centreMotor.stop();
              break;
            case DataExchange.CAL_CMD:
              centreMotor.rotate(getDeltaPos(newPos, curPos));
              LCD.clear(6);
              LCD.drawString("CMD:: CALIBRATE", 0, 6);
              break;
            case DataExchange.START_CMD:
              isNxtStop = false;
              if (isNxtCalib) {
                // calibration is done, the current TachoCount
                // position becomes the reference, i.e. "0 deg".
                isNxtCalib = false;
                centreMotor.resetTachoCount();
                curPos = centreMotor.getTachoCount();
              }
              break;
            case DataExchange.RELEASE_CMD:
              // when user releases the mouse drag, the vehicle attempts to recover a straight
              // drive.
              // It simulates what happens naturally in a real car when the driver gets his hands
              // off
              // the steering upon exiting from a curve.
              centreMotor.rotateTo(0);
              break;
            case DataExchange.FRWD_CMD:
            case DataExchange.BKWD_CMD:
              if (!isNxtStop) {
                centreMotor.rotate(getDeltaPos(newPos, curPos));
              }
              break;
            default:
              break;
          }
          ; // switch case
        } // if (old != new)
        else {
          centreMotor.flt();
        }

        try {
          // thread going to sleep
          ManageNxtSteering.sleep(50);
        } catch (InterruptedException e) {
          e.printStackTrace();
          LCD.drawString("EX-6:", 0, 5);
          LCD.refresh();
        }

      } // if (new != EXIT_CMD)
      else {
        if (newCmd == DataExchange.EXIT_CMD) {
          centreMotor.stop(); /* stop motor */
          break; /* exit while loop */
        }
      }
    } // while loop

    DEObj.setNXTdone(true);
  }
コード例 #16
0
 @Override
 public void rotate(int angle, boolean immediateReturn) throws RemoteException {
   motor.rotate(angle, immediateReturn);
 }
コード例 #17
0
 @Override
 public void rotate(int angle) throws RemoteException {
   motor.rotate(angle);
 }
コード例 #18
0
 @Override
 public void resetTachoCount() throws RemoteException {
   motor.resetTachoCount();
 }
コード例 #19
0
 @Override
 public void rotateTo(int limitAngle, boolean immediateReturn) throws RemoteException {
   motor.rotateTo(limitAngle, immediateReturn);
 }
コード例 #20
0
 @Override
 public int getTachoCount() throws RemoteException {
   return motor.getTachoCount();
 }
コード例 #21
0
 @Override
 public void setSpeed(int speed) throws RemoteException {
   motor.setSpeed(speed);
 }
コード例 #22
0
 @Override
 public boolean isMoving() throws RemoteException {
   return motor.isMoving();
 }
コード例 #23
0
 @Override
 public float getMaxSpeed() throws RemoteException {
   return motor.getMaxSpeed();
 }
コード例 #24
0
 @Override
 public void addListener(RegulatedMotorListener listener) throws RemoteException {
   motor.addListener(listener);
 }