Shop OBEX P1 Docs P2 Docs Learn Events
controller help — Parallax Forums

controller help

science_geekscience_geek Posts: 247
edited 2007-05-21 22:47 in Robotics
im working on using an atari controller to control a boe bot, but when ever i push a button it does what i want until i let go then i jitters and moves backwards, heres my code

·········· ' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "test", CR,
····· "on ",CR
DO
IF (IN0 = 1 ) THEN
PULSOUT 12, 650
PULSOUT 13,850
PAUSE 50
ELSEIF (IN1 = 1) THEN
PULSOUT 12, 850
PULSOUT 13, 650
PAUSE 50
ELSEIF (IN2 = 1) THEN
PULSOUT 12, 650
PAUSE 50
ELSEIF ( IN0 = 0 AND IN1 = 0 AND IN2 = 0 AND IN3 = 0 AND IN4 = 0) THEN
PAUSE 100
ENDIF
LOOP

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-05-19 23:10
    Hi sg, try removing all the pauses , then adjust the last part of the code to look like this

    pulsout 12,750

    pulsout 13,750

    endif

    pause 20

    loop

    you need to keep refreshing the servo, when you release the button there is no refresh the way it is. You also need to command them to the neutral position (750).

    Jeff T.

    Edit sorry I should say your refresh rate is too long you need around 20 - 30 mS
  • science_geekscience_geek Posts: 247
    edited 2007-05-20 03:16
    ive added what you said to do and its still not working, so i re-wrote it so that it would tell me what it was doing in the debug window and it will jump around from forward to backward(those are the only two i am trying hard to get right now) it will start out at neutral, then i hit a switch (forward for example) and it will say forward, but as soon as i let off it will jump to backward and then it will jump back around to all the other commands
  • DgswanerDgswaner Posts: 795
    edited 2007-05-20 04:24
    I like to break out my commands to subroutines, that way when I get down the road adding sensors or what ever it's easier to "GOSUB" a command. than to retype the multiple lines to get it to do something How about something like this:

    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}

    Main:

    IF (IN0 = 1 ) THEN GOSUB forward
    IF (IN1 = 1 ) THEN GOSUB Backwards
    IF (IN2 = 1 ) THEN GOSUB Left
    IF (IN3 = 1 ) THEN GOSUB Right
    GOSUB Halt
    GOTO Main

    Forward:
    PULSOUT 12, 650
    PULSOUT 13,850
    PAUSE 50
    RETURN

    Backwards:
    PULSOUT 12, 850
    PULSOUT 13, 650
    PAUSE 50
    RETURN

    Left:
    PULSOUT 12, 650
    PAUSE 50
    RETURN

    Right:
    PULSOUT 13, 650
    PAUSE 50
    RETURN

    Halt:
    LOW 12
    LOW 13
    RETURN

    You'll have to modify the code slightly, I'm not sure if I have the left and right mixed up or not. Rather than sending out a neutral freq. to the servos I'd set there lines low stopping the servo completely.
    ----EDIT
    it might be better to set 12 and 13 to inputs rather than low. just in case.

    Halt:
    INPUT 12
    INPUT 13
    pause 20
    RETURN

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    A complex design is the sign of an inferior designer. - Jamie Hyneman

    Post Edited (Dgswaner) : 5/20/2007 4:34:29 AM GMT
  • FranklinFranklin Posts: 4,747
    edited 2007-05-20 04:25
    Make sure all your pins have pull down resistors to force the pins to 0 when not activated.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • science_geekscience_geek Posts: 247
    edited 2007-05-20 05:25
    what do you mean by pull down resistors
  • UncandayUncanday Posts: 28
    edited 2007-05-20 05:50
    I means a resistor in the range of, say, 47k which conducts just enough to discharge the input capacitance of the pin when there is nothing else driving it. If the controller just has a switch which shorts to Vcc, when all the switches are open the pins are then floating, and what they will see is whatever the capacitative charge is.

    HTH

    Duncan
  • bennettdanbennettdan Posts: 614
    edited 2007-05-20 22:11
    How do you have a wiring diagram you can provide as to how you have it hooked to the Joystick.
  • science_geekscience_geek Posts: 247
    edited 2007-05-21 00:37
    this is basicly what i have ive tried alternating the V pins with no luck


    ·
    · vdd
    · ······!
    ······· !
    O/ O
    ······················· ······················· ··········· ····························· ·!
    ······················· ······················· ··········· ····························· ·!
    ······················· ······················· ········································ ·pin 0············

    i cant seem to upload the picture but heres a crude example wher i have vdd going threw a switch and into pin 0 i did try putting resistors in and it didnt completely cure it it still would shake and sometimes take off backwards but it did seem to help, i tried putting bigger and smaller resistors but the smaller would make it shake more, and the bigger would make it not shake as much but it would do really weird stuff that i cant explain
  • agfaagfa Posts: 295
    edited 2007-05-21 12:33
    science_geek,

    lots of good advice here.· I just wanted to add the results of my experience with the boe bot and the servos.

    First, using the debug statements are an excelent way of troubleshooting.· It sounds that you do have a problem with the joystick interface to the boe bot. Take a look at page 168 in the "Robotics with the Boe-bot" manual.· It gives an example of interfacing a simple switch.· If I remember correctly the joystick uses a common wire to all switches.· you will have to take that into consideration.

    Second, even if the pauses were too long the servos should still operate, they would just pulse on and off.· Even though the pauses may need to be shortened, keep in mind you can also cause problems by sending the pulsout commands too often.· Also the servos will still operate correctly with a pause longer than 20, depending on your code.

    Third, I don't think you need to send a command to neutral position.· when the servo no longer recieves a pulse it will coast to a stop.· Now if you want it to brake instead of coasting the neutral position command is an excellent way of doing that.· Keep in mind sudden changes in speed are hard on the servos.

    agfa
  • science_geekscience_geek Posts: 247
    edited 2007-05-21 14:05
    i think it is browning out, the leads to the switch and the switch i think are bigger than their supposed to be so i tried a smaller switch and it works but thanx for the help
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-21 14:08
    It looks to me like you need a pull-down resistor. When the switch is opened (button not pushed) the I/O pin is floating. It could be toggling between states. The pull-down resistor prevents this by holding it toward ground when the button isn’t being pressed. You will need one for each I/O pin connected to the joystick. You can find an example of this in the active-high pushbutton example schematic in the BASIC Stamp Manual or in the Editor Help file under the BUTTON command. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • science_geekscience_geek Posts: 247
    edited 2007-05-21 22:47
    thanx for the help i got it working just a simple resistor, lol it kind of stupid me being good at electronics and all since i couldnt figure this out but hey its new to me so yeah now for my big plandevil.gif
Sign In or Register to comment.