Shop OBEX P1 Docs P2 Docs Learn Events
Calculating Angular position into servo values (with the Parallax Servo Control — Parallax Forums

Calculating Angular position into servo values (with the Parallax Servo Control

jfalconjfalcon Posts: 2
edited 2008-03-10 19:05 in General Discussion
I'm writing a program that will interface the servo controller into a program that feeds angular position.

Essentially, if I have an object that is directly ahead of my robot the pan and tilt values are 1500 and 1500 respectively for 0 degrees pan and 0 degrees of tilt.· A object directly behind and up 45 degrees would be 1610 and 1050.

Now, how do I mathmatically calculate an angle (in degrees) into values that can be fed into the servo controller?

servo pulse = deg * ??? [noparse]:)[/noparse]

Thanks!
·

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,572
    edited 2008-03-10 19:05
    jfalcon,

    Assuming that the servo movement is linear in relation to the pulse width, you basically have two linear functions that just need to be scaled to one another.
    One is the Deg range... typically this is 180 Deg, but can vary.· A calibration might be necessary for MIN Deg and MAX Deg.· The other is a pulse width that has
    a range of 1ms, with a MIN pulse width of 1ms and a MAX pulse width of 2ms ... <-- typical, again depending on the servo this can vary.


    Ok, so Assuming that the servo movement range is 180 Deg and the pulse range is 1ms....


    {Servo Pulse} = {Minimum Servo Pulse} + (( {Desired Deg Position} * {Servo Pulse Range} ) / {MAXimum movement range})

    or

    {Servo Pulse} = 1000us + (( {Desired Deg Position} * 1000us ) / 180)




    Going the other way....


    {Deg Position} = (( {Desired Servo Pulse} - {Minimum Servo Pulse}) * {MAXimum movement range} ) / {Servo Pulse Range}

    or

    {Deg Position} = (( {Desired Servo Pulse} - 1000us) * 180 ) / 1000us


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
Sign In or Register to comment.