Joystick not reading Zero
bennettdan
Posts: 614
Hello,
···· I have a joystick with 5k pots when I run the RCTIME command and then debug the value I dont go to Zero because the pot does not rotate all the way CW OR CCW due to the mecanical stops on the joystick. How can I change that number to control a servo I dont really understand how to scale and offset the number..
The values are 150 left and 350 to the right..
···· I have a joystick with 5k pots when I run the RCTIME command and then debug the value I dont go to Zero because the pot does not rotate all the way CW OR CCW due to the mecanical stops on the joystick. How can I change that number to control a servo I dont really understand how to scale and offset the number..
The values are 150 left and 350 to the right..
Comments
·· Assuming the lowest value is where you want 0 to be, you can simply subtract the lowest value from your readings.· For example, if your range is 150 - 350 and you subtract 150 from all readings, then your range will be 0 - 200 afterward.· I hope this helps.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Look at your extremes...· what is the difference between 500 and 1000?· 500 right?· (1000-500 = 500)
And the answer to your previous question gave you a range of 0 to 200 right?
So how do you make 200 "fit" into 500?
200 * x = 500·· ... solve for x
x = 500 / 200·· ... you can use these values or you can simplify....
x = 5 / 2
So·take your previous answer that ranges from 0 to 200·(Lets call it 'Result_One')....
Result_Two = (Result_One * 5) / 2
or you could write...
Result_Two = (Result_One * 5) >> 1
...Now what 'Result_Two' will look like is a number ranging from 0 to 500.· This is still not what we want,
so you need to add back in your original offset of 500.
Final_Result = (Result_One * 5) >> 1 + 500
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Can you post your code?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Hey here is my code it is pretty smooth now that I have played with the pause statements but the timetwo axis when the joystick is all the way left it goes from 1000and jump to 500 and spins the servo in the wrong direction. I tried to put in limits but it made the jerking worse...thanks for any help...
'Servo Control with Joystick
' {$STAMP BS2}
' {$PBASIC 2.5}
time···· VAR Word
timetwo· VAR Word
DO
HIGH 7
PAUSE 3
RCTIME 7, 1, time
time = time - 200
time = (time*500)/120 + 480
HIGH 8
PAUSE 5
RCTIME 8, 1, timetwo
timetwo = timetwo - 212
timetwo = (timetwo*500)/140 + 500
PULSOUT 1, time
PULSOUT 0, timetwo
'DEBUG HOME, "time = ", DEC5 time
'DEBUG HOME, "timetwo = ", DEC5 timetwo
LOOP
Post Edited (bennettdan) : 8/3/2006 1:03:00 AM GMT
a little binary math doesn't hurt try this:
'assuming your input range is 150 to 350
timetwo=timetwo-150 *\ 640 + 500
timetwo= timetwo min 500
timetwo= timetwo max 1000
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
The trick lies in the precceding OPERATOR!
timetwo=timetwo-150 *\ 640 + 500
Check out the */ (minor typo above) operator for a better understanding.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
640 is the equivalent to 2.5 (500/200)··in binary math
·
640=500/200*256
Assume that you have a calculator that the decimal point button doesn't work.
In order to multiply 9 by .3 you would multiply .3 by 10 then multiply 9 by the answer (27).
Now in your head you shift the decimal to the left (2.7).
Bytes don't have decimal points they're base 2^8 not 10 therefore you use the */ operator to shift the binary point over 8 bits (in other words multiply by 256).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
'Joystick Control of Two Servos
'5k pots mounted on the joysticks with a .2uf caps.
'{$STAMP BS2}
'{$PBASIC 2.5}
PosX VAR Word
PosY VAR Word
DO
GOSUB AxisX
GOSUB AxisY
PULSOUT 0, PosY
PULSOUT 1, PosX
'DEBUG HOME, "PosY = ", DEC5 PosY
'DEBUG CR, "PosX = ", DEC5 PosX
LOOP
AxisX:
HIGH 7
PAUSE 5
RCTIME 7,1,PosX
PosX = PosX */ 1100 - 360
PosX = PosX MIN 500
PosX = PosX MAX 1000
RETURN
AxisY:
HIGH 8
RCTIME 8,1,PosY
PosY = PosY */ 1150 - 364
PosY = PosY MIN 500
PosY = PosY MAX 1000
RETURN
Where did you get the joystick that you are using can·you post a web page where you bought them at
I·am thing about·doing a project that will·use a joystick
This is a cool project
·I have a joystick with 5k pots when I run the RCTIME command and then debug the value I dont go to Zero because the pot does not rotate all the way CW OR CCW due to the mecanical stops on the joystick. How can I change that number to control a servo I dont really understand how to scale and offset the number..
Sam··············
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
digikey has a few mini joystick pots
email me at bennettdan@bellsouth.net I might have some joysticks you might be interested in..also I can send you my curcuit diagram and code I used when I get home tonight.