ode added to ex3(gyro). authored by Lasse Brøsted Pedersen's avatar Lasse Brøsted Pedersen
......@@ -197,7 +197,28 @@ private void calcMotorValues(float interval)
}
```
The control loop calculates the average period for the controlloop, then gyro and motor values. It then calculates the output ..
The control loop calculates the average period for the controlloop, then gyro and motor values. It then calculates and applies the control output:
```java
while(running)
{
interval = calcInterval(i, startTime);
calcGyroValues(interval);
calcMotorValues(interval);
float fpower = (KGYROSPEED * gyroSpeed +
KGYROANGLE * gyroAngle) / WHEELRATIO +
KPOS * motorPosition +
KSPEED * motorSpeed;
int power = Math.min(100, Math.abs((int)fpower));
int direction = fpower < 0 ? MotorPort.FORWARD : MotorPort.BACKWARD;
leftMotor.controlMotor(power, direction);
rightMotor.controlMotor(power, direction);
i++;
}
```
// STIKORD:::
......
......