Changes
Page history
ode added to ex3(gyro).
authored
Mar 27, 2015
by
Lasse Brøsted Pedersen
Show whitespace changes
Inline
Side-by-side
Lesson-5.markdown
View page @
cb18671e
...
...
@@ -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:::
...
...
...
...