Up to now, your scripts have controlled the servo horn’s angle. That’s the direction the horn points, measured from 0° to 180° of its range. Your scripts can also control the angular velocity. That’s how fast the horn turns when it’s moving from one position to another.
The scripts currently have the angular velocity slowed down with statements like:
value = value + 1
While pressing and holding the P9 button, the value variable increases by 1 every 50th of a second. In response, the servo horn increases its angle by about 1.75° per 50th of a second. If value = value + 1 is changed to value = value + 3, the modified script will make the horn turn 3 times as fast while the P9 button is pressed and held. This is an example of changing the horn’s angular velocity.
Think back to the first servo control script. It took the servo some time to turn to each new position. In that example, the servo turned to each new position at top speed. If your script advances the value variable faster than the servo can turn, it will catch up eventually. Just keep in mind that increasing the number in the value = value + number statement can only go so far to speed up the servo since the servo has a mechanical speed limit as well.
Angles can be measured in degrees. The symbol for angle is the Greek letter theta Θ . Angles can be expressed in degrees like this: Θ = 30°.
Angular velocity is a measure of how fast (and in which direction) something turns. Angular velocity can be measured in degrees per second. Counterclockwise rotation is considered positive, and clockwise negative. In other words, if the angle is increasing, angular velocity is positive. If angle decreases over time, angular velocity is negative. The symbol for angular velocity is the Greek letter omega, ω, and one way angular velocity is expressed is in degrees per second with this notation: °/s.
When angular velocity is constant it can be measured as the change in angle over time. Change in angle can be measured as the final angle Θf minus the initial angle Θi divided by the time t it took for the object to rotate that far.
ω = (Θf - Θi) / t
Example: If it takes 2.1 seconds for the horn to rotate from 0° to 180°, what is its angular velocity?
ω = (Θf - Θi) / t
= ( 180° - 0°) / 2.1 s
≈ 85.7° / s
Example: If it takes 1.05 seconds for the horn to rotate from 135° to 45°, what is its angular velocity?
ω = (Θf - Θi) / t
= ( 45° - 135°) / 1.05 s
≈ -85.7° / s
Let’s try increasing the counterclockwise angular velocity to 3-times the original. After this change, the servo horn should take about ⅓ of the time it originally took to turn from 0° to 180°.
Links
[1] https://python.microbit.org/v/2