Package lejos.nxt

Examples of lejos.nxt.Motor


   * @throws InterruptedException
   *
   */
  public void steer(int turnRate, int angle) throws InterruptedException
  {
    Motor inside;
    Motor outside;
    int rate = turnRate;
    if(rate <- 200)rate = -200;
    if(rate > 200)rate = 200;
    if(rate==0){
      if(angle<0)
        backward();
      else
        forward();
      return;
    }
    if (turnRate<0)    {
      inside = _right;
      outside = _left;
      rate = -rate;
    } else {
      inside = _left;
      outside = _right;
    }
    outside.setSpeed(_speed);
    float steerRatio = 1 - rate/100.0f;
    inside.setSpeed((int)(_speed*steerRatio));
    if(angle == Integer.MAX_VALUE) {//no limit angle for turn
      if(_parity == 1) outside.forward();
      else outside.backward();
      if( _parity*steerRatio > 0) inside.forward();
      else inside.backward();
      return;
    }
    float rotAngle  = angle*_trackWidth*2/(_wheelDiameter*(1-steerRatio));
    inside.rotate(_parity*(int)(rotAngle*steerRatio),true);
    outside.rotate(_parity*(int)rotAngle,true);

    busyWait();
    inside.setSpeed(outside.getSpeed());
  }
 
View Full Code Here


   * @param immediateReturn iff true, method returns immedediately.
   *
   */
  public void steer(int turnRate, int angle, boolean immediateReturn)
  {
    Motor inside;
    Motor outside;
    int rate = turnRate;
    if(rate <- 200)rate = -200;
    if(rate > 200)rate = 200;
    if(rate==0)
    {
      if(angle<0)backward();
      else forward();
      return;
    }
    if (turnRate<0)
    {
      inside = _right;
      outside = _left;
      rate = -rate;
    }
    else
    {
      inside = _left;
      outside = _right;
    }
    outside.setSpeed(_speed);
    float steerRatio = 1 - rate/100.0f;
    inside.setSpeed((int)(_speed*steerRatio));
    if(angle == Integer.MAX_VALUE) //no limit angle for turn
    {
      if(_parity == 1) outside.forward();
      else outside.backward();
      if( _parity*steerRatio > 0) inside.forward();
      else inside.backward();
      return;
    }
    float rotAngle  = angle*_trackWidth*2/(_wheelDiameter*(1-steerRatio));
    inside.rotate(_parity*(int)(rotAngle*steerRatio),true);
    outside.rotate(_parity*(int)rotAngle,true);
    if(immediateReturn)return;
    while (isMoving())Thread.yield();
    inside.setSpeed(outside.getSpeed());
  }
View Full Code Here

   * @param angle The angle through which the robot will rotate. If negative, robot traces the turning circle backwards.
   * @param immediateReturn If true this method returns immediately.
   */
  public void steer(final int turnRate, final int angle, final boolean immediateReturn) {
    // TODO: make this work with wheels of different size
    Motor inside;
    Motor outside;
    int rate = turnRate;
    if (rate < -200) {
      rate = -200;
    }
    if (rate > 200) {
      rate = 200;
    }
    if (rate == 0) {
      if (angle < 0) {
        backward();
      }
      else {
        forward();
      }
      return;
    }
    if (turnRate < 0) {
      inside = _right;
      outside = _left;
      rate = -rate;
    }
    else {
      inside = _left;
      outside = _right;
    }
    outside.setSpeed(_motorSpeed);
    float steerRatio = 1 - rate / 100.0f;
    inside.setSpeed((int) (_motorSpeed * steerRatio));
    if (angle == Integer.MAX_VALUE) // no limit angle for turn
    {
      if (_parity == 1) {
        outside.forward();
      }
      else {
        outside.backward();
      }
      if (_parity * steerRatio > 0) {
        inside.forward();
      }
      else {
        inside.backward();
      }
      return;
    }
    float rotAngle = angle * _trackWidth * 2 / (_leftWheelDiameter * (1 - steerRatio));
    inside.rotate(_parity * (int) (rotAngle * steerRatio), true);
    outside.rotate(_parity * (int) rotAngle, immediateReturn);
    if (immediateReturn) {
      return;
    }
    while (inside.isRotating() || outside.isRotating())
      Thread.yield();
    inside.setSpeed(outside.getSpeed());
  }
View Full Code Here

TOP

Related Classes of lejos.nxt.Motor

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.