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; };
@Override public void resetTachoCount() throws RemoteException { motor.resetTachoCount(); }
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); }