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();
   }
 }
 @Override
 public void stop(boolean immediateReturn) throws RemoteException {
   motor.stop(immediateReturn);
 }
Esempio n. 3
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);
  }