Shop OBEX P1 Docs P2 Docs Learn Events
Joystick not reading Zero — Parallax Forums

Joystick not reading Zero

bennettdanbennettdan Posts: 614
edited 2006-08-23 12:36 in BASIC Stamp
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..

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-08-01 19:37
    Hello,

    ·· 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
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-08-01 21:23
    You'll probably need to have a little 'range' in there, too. By this I mean. if your range is 150 to 350, then 'center' position will be around 250. Add a +- 5 range, and your BS2 should conclude you're 'centered' for values from 245 through 255.
  • bennettdanbennettdan Posts: 614
    edited 2006-08-01 21:59
    Thanks guys after I subtract the number down to then I need to ofset it to get the 500-750-1000 values to control the servo?
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2006-08-02 00:23
    bennettdan,

    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.
  • bennettdanbennettdan Posts: 614
    edited 2006-08-02 01:09
    I got it to debug the correct values not 500-750-1000 but the servo jerks all the time. I then made a small centering program then ran it and the servo does not jerk..any sugestions?
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2006-08-02 03:31
    bennettdan,

    Can you post your code?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • bennettdanbennettdan Posts: 614
    edited 2006-08-02 23:57
    Beau,
    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
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2006-08-03 10:29
    your subtracting 200 when your minimum value is 150
    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
  • bennettdanbennettdan Posts: 614
    edited 2006-08-03 10:56
    How did you come up with the number 640 Technorobbo?
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-08-03 12:13
    bennetdan -

    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 -->
  • bennettdanbennettdan Posts: 614
    edited 2006-08-03 16:36
    yeah but I dont understand where the 640 comes into play?
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2006-08-03 23:51
    He's right it's a typo it is */

    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
  • bennettdanbennettdan Posts: 614
    edited 2006-08-04 00:19
    Hey guys I got it working real smooth with this code thanks for the help..

    '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
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2006-08-04 17:12
    ·bennettdan

    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·············· idea.gif
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2006-08-05 05:14
    What values (hi and lo) does your joystick return when you use rctime.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun
  • bennettdanbennettdan Posts: 614
    edited 2006-08-05 06:56
    The original joystick gave me some problems so I got a different one that read 208 min and about 315 max. then I read up on the operator you talked about and came up with the right values in the debug window. I had to use a .22 cap to get a larger # span than the .1 cap also..thanks for you help it runs real smooth now.
  • robot makerrobot maker Posts: 17
    edited 2006-08-23 07:05
    bennettdan said...
    The original joystick gave me some problems so I got a different one that read 208 min and about 315 max. then I read up on the operator you talked about and came up with the right values in the debug window. I had to use a .22 cap to get a larger # span than the .1 cap also..thanks for you help it runs real smooth now.
    do you have circuit for joystick pot to basic stamp looking for for trhis for 6 axis servo cantrol proget i am working on
    digikey has a few mini joystick pots
  • bennettdanbennettdan Posts: 614
    edited 2006-08-23 12:36
    Robot maker,
    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.
Sign In or Register to comment.