Shop OBEX P1 Docs P2 Docs Learn Events
Stamp Math Help — Parallax Forums

Stamp Math Help

Kevin SkyMoCoKevin SkyMoCo Posts: 23
edited 2005-01-28 22:11 in BASIC Stamp
My servo's have a range of 300 to 1200, but I want to receive positions
in one byte (actually in the range 50-250). So I need to do some math
where if I receive a 50, send a position of 300, 51 move to 305, 52 move
to 310.

Since I have range of 200 inputs, a lookup table is too big, and since I cannot
use floating point, I am at a loss.

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-28 20:44
    This is no problem for the BASIC Stamp:

    newPos = (oldPos - 50) */ $0480 + 300
    

    You should write a little demo with the formula above to prove that it works.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2005-01-28 21:13
    How about...

    Servo = ((N*45)+3000)/10

    Expanded:
    Servo = N * 45
    Servo = Servo + 3000
    Servo = Servo / 10

    or

    N = (((Servo*10)-3000)/45)+50

    Expanded:
    N = Servo * 10
    N = N -3000
    N = N / 45
    N = N + 50

    ....Where:

    Servo = the Servo position (300 to 1200)
    N = the byte value of (50 to 200)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe - Mask Designer III

    National Semiconductor Corporation
    (Communication Interface Division)
    500 Pinnacle Court, Suite 525
    Mail Stop GA1
    Norcross,GA 30071
  • Kevin SkyMoCoKevin SkyMoCo Posts: 23
    edited 2005-01-28 21:44
    Couple questions:

    newPos = (oldPos - 50) */ $0480 + 300

    What does the $ operator do? I cannot find it in the help. And, my 50-250 value
    is an absolute position to move the servo to.


    And when I try Beua's formula with a N of 50 I get 525, not the 300 I was hoping for..
    Servo = ((N*45)+3000)/10

    Maybe more example might help.
    Send Stamp Move To
    50 300
    100 525
    150 750
    250 1200
  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2005-01-28 21:50
    OOps...

    try subtracting 50 off of N before applying the formula so that it becomes...

    Servo = (((N-50)*45)+3000)/10

    Expanded:
    Servo = N - 50
    Servo = Servo * 45
    Servo = Servo + 3000
    Servo = Servo / 10

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe - Mask Designer III

    National Semiconductor Corporation
    (Communication Interface Division)
    500 Pinnacle Court, Suite 525
    Mail Stop GA1
    Norcross,GA 30071
  • Kevin SkyMoCoKevin SkyMoCo Posts: 23
    edited 2005-01-28 22:05
    Perfect!

    My only excuse is that Calculus was 20 years ago my kids are still doing counting on
    their fingers.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-01-28 22:11
    The $ is not an operator. It just shows that the number is written in HEX format. It could just as well be written 1152 in decimal. Inside the stamp it is the same binary number in the circuits of the stamp. The

    The */ is an operator. In Jon's formula it effectively multiplies times 4.5 to achieve the scaling you need. (1152/256 = 4.5 The stamp does it internally as a multiply followed by an implicit divide by 256)


    position = (serialbyte - 50) */ $0480 + 300

    Here is another way...

    position = serialbyte */ 1152 + 75

    >Send Stamp Move To
    >50 300
    >100 525
    >150 750
    >250 1200

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.