Shop OBEX P1 Docs P2 Docs Learn Events
Division by non-integers — Parallax Forums

Division by non-integers

jaybee11jaybee11 Posts: 3
edited 2010-01-15 01:39 in BASIC Stamp
I am using the operators "**" and "*/" to enable me to multiply by numbers with decimal points. Can't find anything that will let me divide by numbers with decimal points. My Boe-Bot pivots·right 90 degrees fith the following subroutine:

·· PivotRight:··· 'pivot Boe-Bot 90 degrees to the right
· FOR counter = 1 TO 13
··· PULSOUT 13, 850
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· PAUSE 200
· RETURN

Doing the math that means I get 6.92 degrees of rotation for each pulse. I want to replace the 13 in the FOR statement with a variable who's value can be set prior to calling the subroutine so I can get other than just 90 degrees of rotation. Would someone please help me with this task? I am using a BS2 processor and PBASIC 2.5. Thanks you.

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-01-13 20:08
    There is a lot of good information here www.emesystems.com/BS2index.htm#math
    But you will find that hobby servos will not give you the precision you seem to be expecting. I would recommend you investigate encoders if you need to stay with servos or perhaps stepper motors.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-01-13 22:22
    Division can be inverted to become multiplication, so x / 6.92 = x * 0.145.

    Say you want to move 47 degrees. Then the variable would be 47 * 0.145, or on the Stamp,
    index = degrees ** 9471
    FOR counter = 1 to index
    ' ...
    


    As Stephen pointed out, the precision is not good. Maybe there is something mechanical that can make the steps smaller, say, by running the servos at 800 instead of 850.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • jaybee11jaybee11 Posts: 3
    edited 2010-01-14 21:32
    Thanks Tracy. Exactly what I needed.
  • vaclav_salvaclav_sal Posts: 451
    edited 2010-01-15 01:39
    The end value can be a variable

    See Help for "FOR"

    FOR Counter = StartValue TO EndValue {STEP StepValue} ... NEXT


    EndValue is a variable/constant/expression* (0 - 65535) that specifies the end value of the variable (Counter). When the value of Counter is outside of the range StartValue to EndValue, the FOR...NEXT loop stops executing and the program goes on to the .....

    ·
Sign In or Register to comment.