* @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());
}