Stamp Math Help
Kevin SkyMoCo
Posts: 23
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.
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
You should write a little demo with the formula above to prove that it works.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
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
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
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
My only excuse is that Calculus was 20 years ago my kids are still doing counting on
their fingers.
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