PDA

View Full Version : Code & Math Help



MichelB
11-02-2009, 09:11 PM
Hi all (Parallax staff included), I've transposed on a Board of Education the StampWorks Experiment #26: Hobby Servo Control.
Page 149 it's written: "The value for constant Scale is determined empirically. After constructing the circuit, insert appropriate DEBUG statements to display the raw potentiometer readings from both sides..., etc.".
This exists in the program (#DEFINE _Testing = 1) and gives what it follows:
Pot. pos.ииии CWииии CCWииии Center
CW (raw)иии 302ииииии 1иииииииии 132
CCW (raw)ии 1ииииии 302ииииииии 132
CWииииииииииии250иииии 0ииииииииии 109
CCWиииииииииии 0иииии 250ииииииии 109
Posииииииииии -250иии 250ииииииииии 0
Pulseиииииии 1250иии1750иииииии 1500
Note that Pulse must be divided by 2 in order to create the correct pulse output for the servo, therefore correct pulses are CW 625, CCW 875 and Center 750 giving a range of about +30░ to -30░ from the center.
It's also written: "Take the lower of two values and divide that into 500 (desired output)."
What "lower" of what "two values"?
Why the desired output is 500?
What I need in my project is a range of +90░ to -90░ from the center obtained the following pulses:
+90░ -> 310, 0░ -> 750 and -90░ -> 1190.
Page 149 yet we can see in the example:
Raw RCTIME value: 645 Question? In my case (see above) 302? or 2 x 302 = 604?
It seems that the number 645 contradicts the lower of two values 7 lines above.
In short:
i) What value must I consider for raw RCTIME 302 or 604?
ii) What value must I take for the desired output? (instead of 500)
iii) What's about (in this case) MAX 500 ' scale RCTIME to 0-500 in the attached code?
P.S.: There is a little typing error in the example: 250 / 645 = 0.775 must be 500 / 645 = 0.775
Thank you in advance.