Author Topic: PlayStation 2 Controller Arduino Library  (Read 45739 times)

0 Members and 1 Guest are viewing this topic.

Offline madsci1016Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: PlayStation 2 Controller Arduino Library
« Reply #90 on: January 16, 2011, 10:05:15 AM »
Well first thing tpalmieri,

You are missing the config statement (  ps2x.config_gamepad(13,11,10,12);   )  in setup()

Then we have some other issues.

This doesn't work.

Code: [Select]
basepos = map (PSAB_PAD_RIGHT, 0, 255, 0, 180); // Scale Servo Positions from PS2 Controller
But it is the right approach for this section:

Code: [Select]
if(ps2x.Button(PSS_RX)) shoulderpos++;  // This is a joystick. Want 128 to 0 to move servo in one direction and 128 to 256 in the other.

 if(ps2x.Button(PSS_RY)) elbowpos++;

 if(ps2x.Button(PSS_LX)) wristpos++;

 if(ps2x.Button(PSS_LY)) wristrotatepos++;

 if(ps2x.Button(PSB_R2)) gripperpos++;

But to control the servos from the thumbsticks each should look like this:

shoulderpos = map(ps2x.Analog(PSS_RX),  0, 255, 0, 180);

Using the if() statements with ++ is only if you want to move a servo with a button.

Offline btmcmahan

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Re: PlayStation 2 Controller Arduino Library
« Reply #91 on: May 06, 2011, 08:52:59 AM »
Hey, I'm new to arduino so I'm sure this is going to be a silly question.  When I try to upload this code to my arduino mega, I get the following error:

"PS2X is not a type" and it highlights this code
Code: [Select]
PS2X ps2x; // create PS2 Controller Class
what should I do?  I've tried several of your previous versions too, and I always get the same code.

Offline KurtEck

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 12
Re: PlayStation 2 Controller Arduino Library
« Reply #92 on: May 06, 2011, 09:00:34 AM »
My guess is that you have not downloaded or expanded the library into your library and you have not imported it into your sketch.

In particular:
Have you downloaded and expanded his library into your arduino library directory?

Also when you have the Arduino IDE running with your sketch, you have you gone to the sketch menu/Import Library menu item and imported the library into your sketch?

Good Luck
Kurt

Offline btmcmahan

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Re: PlayStation 2 Controller Arduino Library
« Reply #93 on: May 06, 2011, 05:18:27 PM »
Okay, I'm doing better.  I got the code onto the board, the problem was the file folder like you suggested.  My new problem is this:  Where do I attatch the Ack wire from the controller?  I can't seem to find the answer to that. And I may need to change what pin # it is, for the Mega.  What line of code dictates the Ack pin? 

Also, I want to change the pins for Data, Attn, Clk, and Comand too.  Am I right to change it in this line of code:
 error = ps2x.config_gamepad(13,11,10,12, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error

Offline madsci1016Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: PlayStation 2 Controller Arduino Library
« Reply #94 on: May 06, 2011, 05:42:21 PM »
Hi btmcmahan,

Welcome to arduino!!

My library does not use the "Acknowledge" wire from the controller, so you don't have to connect it to anything.

For changing the other pins, yes that is the line of code to change the pin numbers in.

By the way, if you have any more trouble with my library, you can also try some of the suggestions in my 'Troubleshooting Guide'

Offline jdeck

  • Beginner
  • *
  • Posts: 1
  • Helpful? 0
Re: PlayStation 2 Controller Arduino Library
« Reply #95 on: May 08, 2011, 10:17:42 PM »
Hello,

I am very new to Arduino. I am a mechanical engineering student and my only programming background is in MATLAB. I am working on a Senior Design project involving control of a 40lb tank robot using a wireless PS2 controller from Lynxmotion.

I have downloaded your library and looked through its capabilities. It is very impressive. It has more than enough functionality for my purposes, specifically the ability to control 3 DC motors with bidirectional speed control.

I was hoping that you could indicate to me how to read the joystick values from your library into a PWM signal. I really appreciate the help.

Edit: the best I can infer is using if ps2x.Button(RSS_RX) to read a value and then based on that using analogWrite(pin,scale)

Thank you,
John

Also I would like to clarify this point:
I prefer to have pins 10 and/or 11 available for PWM output, as pins 5 and 6 have known issues with low duty-cycle settings.  "The PWM outputs generated on pins 5 and 6 will have higher-than-expected duty cycles. This is because of interactions with the millis() and delay() functions, which share the same internal timer used to generate those PWM outputs. This will be noticed mostly on low duty-cycle settings (e.g 0 - 10) and may result in a value of 0 not fully turning off the output on pins 5 and 6."   Will there be any problems with using pins 5 and/or 6 based on this issue?
« Last Edit: May 09, 2011, 03:09:36 PM by jdeck »

 


Get Your Ad Here