Shop OBEX P1 Docs P2 Docs Learn Events
play station controller for bs2e — Parallax Forums

play station controller for bs2e

roboneticsrobonetics Posts: 16
edited 2005-09-02 18:04 in Robotics
·hello,
········ is there anyone out there that can give me an idea.gif idea or help programming my bs2e to work with the ps2 controller.
········· i want to assign each button & joystick to different movement for my bipedal robot. but i don't know how to do it. i have seen it done at lynxmoition but it's done for bs1 not 2e. tried to convert it to work with it but i keep getting freaked.giferrors.jumpin.gif·

any help would be great!!!!smilewinkgrin.gif
thank you,
robonetics
aka charlie

Comments

  • roboneticsrobonetics Posts: 16
    edited 2005-09-02 18:04
    hello me again, here is what i am working with, if anyone can look over it & let me know where i am going wrong that would be great....

    thankz again robonetics

    ' {$STAMP BS2e}
    ' {$PBASIC 2.5}
    ' This program allows the remote control of a differentially steered robot
    ' from the Sony Play Station 2 game controller.

    ' The Scorpion has two modes of operation. The default is the mixer mode. This
    ' is where you have a Throttle for forward and reverse speed control, and a
    ' Steering control for turning. In this mode the left input is throttle and
    ' the right input is steering. The other mode is a differential style control.
    ' This is where the left and right channels are controled indepentantly to
    ' steer like a tank. This program uses the mixing mode. It also requires the
    ' BEC (battery eliminator circuit to be dissabled. See the Scorpion manual.

    'Connections
    'Pin 0 Left Scorpion channel.
    'Pin 1 Right Scorpion channel.
    'Pin 2 Pan servo.
    'Pin 3 Tilt servo.
    'Pin 4 PS2 Data
    'Pin 5 PS2 Command
    'Pin 6 PS2 Select
    'Pin 7 PS2 Clock
    'Pin 8 NA
    'Pin 9 Speaker
    'Pin 10 1/0 Controlled from Triangel Button
    'Pin 11 1/0 Controlled from "X" button
    'Pin 12 Gripper up/down servo.
    'Pin 13 Gripper rotate servo.
    'Pin 14 Gripper open/close servo.
    'Pin 15 NA

    DAT CON 4 ' Play Station game controller connections.
    CMD CON 5
    SEL CON 6
    CLK CON 7

    temp VAR Byte ' Variable definetions.
    button1 VAR Byte
    button2 VAR Byte

    bpress1 VAR Bit
    bpress2 VAR Bit

    rhori VAR Word
    rvert VAR Word
    lhori VAR Word
    lvert VAR Word

    ldrive VAR Word
    rdrive VAR Word
    servo0 VAR Word
    servo1 VAR Word

    servo2 VAR Word
    servo3 VAR Word
    servo4 VAR Word
    servo5 VAR Bit

    servo0 = 1500 ' Start the servos at mid position.
    servo1 = 1500
    servo2 = 1500
    servo3 = 1500
    servo4 = 1500

    LOW 0 ' Ensure pulsout commands are positive going.
    LOW 1
    LOW 2
    LOW 3
    LOW 12
    LOW 13
    LOW 14

    LOW 10 ' Ensure device connected to pin 10 and 11 is off on startup
    LOW 11

    HIGH CLK ' Ensure CLK is negative going.

    PAUSE 1000

    setup:' This section sets the PSX Controller to Analog Mode. (red LED should light)
    ' This will work with Sony and Madcatz wired, but not with Medcatz wireless.
    ' You must press the analog button on the controller to set to analog mode.
    LOW SEL
    SHIFTOUT CMD,CLK,LSBPRE,[noparse][[/noparse]$01\8,$43\8,$00\8,$01\8,$00\8] 'Config Mode Enable
    HIGH SEL

    PAUSE 100

    LOW SEL
    SHIFTOUT CMD,CLK,LSBPRE,[noparse][[/noparse]$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] 'Set Mode TO Analog AND Lock
    HIGH SEL

    PAUSE 100

    LOW SEL
    SHIFTOUT CMD,CLK,LSBPRE,[noparse][[/noparse]$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] 'Config Exit
    HIGH SEL

    main:
    GOSUB get_PSX_data
    lvert=255-lvert ' Changes vertical up from 0 to 255 and vertical down from 255 to 0.
    lhori=255-lhori
    ldrive=((lvert*3)+1116) ' Converts a 0-128-255 value to a 1116-1500-1881 value.
    rdrive=((lhori*3)+1116)
    ldrive=((lvert*4)+1000) ' Converts a 0-128-255 value to a 1000-1512-2020 value.
    rdrive=((lhori*4)+1000)
    'SEROUT S_Out,i57600,[noparse][[/noparse]DEC3 lvert\3," ",DEC3 lhori\3," "]
    'SEROUT S_Out,i57600,[noparse][[/noparse]DEC5 ldrive\5," ",DEC5 rdrive\5," ",13]
    servo0=((rhori*4)+1000)
    servo1=((rvert*4)+1000)

    IF rhori > 208 THEN ' Pan servo routine.
    servo0 = servo0 + 25
    ELSEIF rhori > 148 THEN
    servo0 = servo0 + 5
    ENDIF
    IF servo0 < 750 THEN
    servo0 = 750
    ENDIF
    IF rhori < 48 THEN
    servo0 = servo0 - 25
    ELSEIF rhori < 108 THEN
    servo0 = servo0 - 5
    ENDIF
    IF servo0 > 2250 THEN
    servo0 = 2250
    ENDIF

    IF rvert > 208 THEN ' Tilt servo routine.
    servo1 = servo1 + 25
    ELSEIF rvert > 148 THEN
    servo1 = servo1 + 5
    ENDIF
    IF servo1 < 750 THEN
    servo1 = 750
    ENDIF
    IF rvert < 48 THEN
    servo1 = servo1 - 25
    ELSEIF rvert < 108 THEN
    servo1 = servo1 - 5
    ENDIF
    IF servo1 > 2250 THEN
    servo1 = 2250
    ENDIF

    ' Gripper open/close
    temp=button2 & 2 ' Filter out all but bit 2, R2.
    IF temp=0 THEN ' If button is pressed then do the following.
    servo4 = servo4 - 25 ' Open the gripper.
    IF servo4 < 750 THEN ' Hold the value to 750 minimum.
    servo4 = 750
    ENDIF
    ENDIF
    temp=button2 & 8 ' Filter out all but bit 8, R1.
    IF temp=0 THEN ' If button is pressed then do the following.
    servo4 = servo4 + 25 ' Close the gripper.
    IF servo4 > 2250 THEN ' Hold the value to 2250 maximum.
    servo4 = 2250
    ENDIF
    ENDIF
    ' Gripper up/down
    temp=button1 & 16 ' Filter out all but bit 16, D-pad up arrow.
    IF temp=0 THEN ' If button is pressed then do the following.
    servo2 = servo2 - 25 ' Lift gripper.
    IF servo2 < 750 THEN ' Hold the value to 750 minimum.
    servo2 = 750
    ENDIF
    ENDIF
    temp=button1 & 64 ' Filter out all but bit 64, D-pad down arrow.
    IF temp=0 THEN ' If button is pressed then do the following.
    servo2 = servo2 + 25 ' Lower gripper.
    IF servo2 > 2250 THEN ' Hold the value to 2250 maximum.
    servo2 = 2250
    ENDIF
    ENDIF
    ' Gripper Rotate
    temp=button1 & 32 ' Filter out all but bit 32, D-pad right arrow.
    IF temp=0 THEN ' If button is pressed then do the following.
    servo3 = servo3 - 25 ' Gripper rotate right.
    IF servo3 < 750 THEN ' Hold the value to 750 minimum.
    servo3 = 750
    ENDIF
    ENDIF
    temp=button1 & 128 ' Filter out all but bit 128, D-pad left arrow.
    IF temp=0 THEN ' If button is pressed then do the following.
    servo3 = servo3 + 25 ' Gripper rotate left.
    IF servo3 > 2250 THEN ' Hold the value to 2250 maximum.
    servo3 = 2250
    ENDIF
    ENDIF
    ' I/O on/off
    temp=button2 & 16 ' Filter out all but bit 16, Triangle button.
    IF temp=0 AND bpress1=0 THEN ' This makes a latching output pin that responds to button presses.
    bpress1=1
    TOGGLE 10
    ENDIF
    IF temp<>0 AND bpress1=1 THEN
    bpress1=0
    ENDIF
    temp=button2 & 64 ' Filter out all but bit 64, X button.
    IF temp=0 AND bpress2=0 THEN ' This makes a latching output pin that responds to button presses.
    bpress2=1
    TOGGLE 11
    ENDIF
    IF temp<>0 AND bpress2=1 THEN
    bpress2=0
    ENDIF


    ' Send out the servo pulses
    PULSOUT 0,ldrive ' Left Scorpion channel.
    PULSOUT 1,rdrive ' Right Scorpion channel.
    PULSOUT 2,servo0 ' Pan servo.
    PULSOUT 3,servo1 ' Tilt servo.
    PULSOUT 12,servo2 ' Gripper up/down servo.
    PULSOUT 13,servo3 ' Gripper rotate servo.
    PULSOUT 14,servo4 ' Gripper open/close servo.
    PULSOUT 15,servo5
    PAUSE 20
    GOTO main


    get_PSX_data: ' This section gets the data from the PSX controller.
    ' The first shiftin gets the mode. (73)
    ' The next 2 shiftins gets the pushbutton data.
    ' The next 4 shiftins gets the analog joystick data.
    LOW SEL
    SHIFTOUT CMD,CLK,LSBPRE,[noparse][[/noparse]$1\8,$42\8] ' Initiate request for data from PSX controller.
    SHIFTIN DAT,CLK,LSBPOST,[noparse][[/noparse]temp\8] ' This is the Mode value, it will be dumped.
    SHIFTIN DAT,CLK,LSBPOST,[noparse][[/noparse]button1\8,button2\8] ' This puts the button data into two byte variables.
    SHIFTIN DAT,CLK,LSBPOST,[noparse][[/noparse]temp\8] ' This retrieves the RH byte variable.
    rhori=temp ' This plugs the value into a word variable.
    SHIFTIN DAT,CLK,LSBPOST,[noparse][[/noparse]temp\8] ' Note: This is necessary because the shiftin command
    rvert=temp ' can't use a word variable with a byte wide shift.
    SHIFTIN DAT,CLK,LSBPOST,[noparse][[/noparse]temp\8]
    lhori=temp
    SHIFTIN DAT,CLK,LSBPOST,[noparse][[/noparse]temp\8]
    lvert=temp
    HIGH SEL
    ' remove the rems (') to see the joystick values in terminal 1.
    ' SEROUT S_OUT,i57600,[noparse][[/noparse]BIN button1\8," ",BIN button2\8," "]
    'SEROUT S_OUT,i57600,[noparse][[/noparse]DEC3 rhori\3," ",DEC3 rvert\3," ",DEC3 lhori\3," ",DEC3 lvert\3," "]
    'SEROUT S_OUT,i57600,[noparse][[/noparse]13]
    RETURN
Sign In or Register to comment.