Shop OBEX P1 Docs P2 Docs Learn Events
I cant get mo robot working! — Parallax Forums

I cant get mo robot working!

MbiddleMbiddle Posts: 2
edited 2012-05-08 08:36 in Propeller 1
I have a problem with my servos, they will not work with the buttons on my Ps2 controller. Ive tried just about everything. Does anyone know whats wrong with this section of code.
if |< 26
servo[6] := (!buttons & |< 26 - 128) * vspeed

if |< 27
servo[3] := (!buttons & |< 27 - 128) * vspeed

if |< 24
servo[6] := (128 - !buttons & |< 24) * vspeed

if |< 25
servo[3] := (128 - !buttons & |< 25) * vspeed






repeat vspeed := 4
if !buttons & |< 26 'L1
pst.Str (String (" L1_ON: "))
dira [22] := 1
outa [22] := 1
elseifnot buttons == 1
outa [22] := 0

if !buttons & |< 24 'L2
pst.Str(String(" L2_ON: "))
dira [22] := 1
outa [22] := 1
elseifnot buttons == 1
outa [22] := 0

if !buttons & |< 27 'R1
pst.Str(String(" R1_ON: "))
dira [21] := 1
outa [21] := 1
elseifnot buttons == 1
outa [21] := 0

if !buttons & |< 25 'R2
pst.Str (String (" R2_ON: "))
dira [21] := 1
outa [21] := 1

Comments

  • Heater.Heater. Posts: 21,230
    edited 2012-05-03 06:51
    Mbiddle,

    Welcome to the forum.

    You are going to have to edit your post and add code markup around your code so that we can read it properly.
    Look for the # button in the advanced edit box.
    With out it the code has no indentation and the logical flow is lost.

    Oh yes, and you may need to add a space after each opening square bracket [ and before each closing square bracket ] so that they don't get interpreted as text formatting by the forum.
  • Mike GMike G Posts: 2,702
    edited 2012-05-03 07:15
    The first thing I noticed was
    if |< 26 
    

    This statement is always true.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-05-03 08:24
    I recently modified a PlayStation 2 object to made it easier to find the button values.

    Each button is an element of an array. If the element is one then the button is pressed.

    So to check if the "R1" button is pressed you use:
    if digitalButton[_R1Ps2] == 1
        ' do something when R1 is pressed
    

    The constant "_R1Ps2" is defined as four in the constant section.

    The code can also read the analog values of the button pressure.

    I made a demo of the object and posted it here.

    Once the object is started all the button values and joystick values are continuously updated so the variable "rightX" always contains the most recent x value of the right joystick.

    I also added the ability to change from digital to analog mode with software so you don't need to remember to press the "analog" button in order to use the joysticks.

    I personally think the analog buttons are cool. This is the first object I know of to read the analog values of the buttons. I didn't even know the buttons were pressure sensitive a few weeks ago.

    I hope you try it out. I think it's pretty darn cool (if I do say so myself).

    Edit: I just added my version of the PS2 controller to the OBEX.
  • MbiddleMbiddle Posts: 2
    edited 2012-05-08 05:24
    i cant seem to get two buttons to controle a servo in 2 directions
    plus i dont understand what ur saying
  • StefanL38StefanL38 Posts: 2,292
    edited 2012-05-08 08:36
    Hello and welcome to the propeller-Forum.

    your last post is too short to understand what you are not understanding.
    please ask concrete questions like "I don't understand what you mean by writing ....."
    or "I don't know what a ... is"

    Best thing is to use the archive-function of the propeller-tool to put ALL files that are needed to compile into one zip-file and attaching this file to a posting.
    a general advice about code-developing is to divide the code into small pieces and to test each piece on its own.
    This will make it much easier to narrow down a problem.
    best regards
    Stefan
Sign In or Register to comment.