Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • Servo Position Control with Python and micro:bit

Servo Position Control with Python and micro:bit

Angle and Angular Velocity


Did You Know? Angular Velocity

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.

Control Angular Velocity with the Script

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.  

Angle vs. Angular Velocity

Angles can be measured in degrees.  The symbol for angle is the Greek letter theta Θ .  Angles can be expressed in degrees like this: Θ = 30°.  

  • Quantity name: Angle
  • Quantity symbol: Θ
  • Unit name: Degree
  • Unit symbol: °
  • Description: A degree 1/360 of a full circle’s worth of deviation

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.    

  • Quantity name: Angular velocity
  • Quantity symbol: ω
  • Unit name: degree per second
  • Unit symbol: °/s
  • Description: Change in angle over time.  A degree per second is 1/360th of a full circle of rotation per second.

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


Your Turn: Change Angular Velocity

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°.   

  • In the micro:bit Python Editor, click Open, and reopen servo_buttons_control.hex.
  • Set the project name field to servo_buttons_control_faster_ccw.
  • In the if state9 is 1 block, change the value = value + 1 statement to value = value + 3.
  • Click Save, then click Send to micro:bit.

Tests

  • Add batteries to the battery pack connected to the Edge I/O Adapter.
  • Press and hold the P6 pushbutton until the servo reaches its 0° limit
  • Press and hold the P9 pushbutton to make the servo turn to its 180° limit, and observe the rate the horn turns.
  • Observe the rate the horn turns as you press and hold the P6 pushbutton to make the servo turn to its 0° limit.  Did it turn from 0 to 180° in about ⅓ the time it turned from 180° to 0°?  That means it’s turning 3 times as fast.
  • Remove the batteries from the battery pack.

 


Printer-friendly version
How it Works
Prev
Review and Practice
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn • Built with GeneratePress