Author Topic: PS2 Controller Problem  (Read 1638 times)

0 Members and 1 Guest are viewing this topic.

Offline tzankoffTopic starter

  • Robot Overlord
  • ****
  • Posts: 122
  • Helpful? 0
PS2 Controller Problem
« on: October 07, 2012, 11:36:40 PM »
I am sorry for making it look like I am beating a dead horse with my Axon II / PS2 Controller questions, but I do have one more. When this one gets figured out, for better or for worse, it will be the last on this subject from me. I know I have gone back and forth on this before and the wired controller setup I have now is fine, but wireless is the way I really want to go on this.

Therefore, I am really going to bite the bullet on this one and hope things work out.

A while back, I made an inquiry regarding why a wired PS2 controller works fine on an Axon II whereas a wireless PS2 controller does not. KurtEck successfully made a PS2 controller work with the original Axon and I asked if he could somehow help me out here.

In Project Designer, I started a new project and added a servo and the PS2 controller to the device list.
  • Servo: H3
  • PS2: Software SPI Bus >> MOSI=A1, MISO=A0, SCK=A5, and SELECT=A2
I saved and generated code using webbotLib 2.09. Next, in AVR Studio, I loaded the basic code that comes with each new project and added KurtEck's PS2-related code that he posted.

Code: [Select]
#include "hardware.h"

// *************************
// added from KurtEck's code.
#include "ps2_controller.h"
#include <stdlib.h>
#include <string.h>

PS2PACKET ps2p;
PS2PACKET ps2pPrev;
// *************************

void appInitHardware(void){
initHardware();
}

TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
controller.calibrate(27);
return 0;
}

TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){

// *************************
// added from KurtEck's code.

if (PS2_Query(ps2p.bData,sizeof(ps2p)))
{
if (memcmp(ps2p.bData,ps2pPrev.bData,sizeof(ps2p))!=0)
{
ps2pPrev=ps2p;
rprintfInit(&uart1SendByte);
rprintf("%2x%2x %2x %2x %2x %2x\n",ps2p.bData[0],ps2p.bData[1],ps2p.s.bRJoyLR,ps2p.s.bRJoyUD,ps2p.s.bLJoyLR,ps2p.s.bLJoyUD);
Toggle.toggle();
}
}

delay_ms(10);
// *************************

return 20000;
}

I tried compiling and generated errors said that PS2_CMD, PS2_CLK, PS2_DAT, and PS2_SEL were not defined in the scope. Normally, I thought this would have been taken care of in initHardware() or something, but I guess not. However, borrowing from what I believe to be the original Axon version of this code, I defined them myself like so:

Code: [Select]
#include "hardware.h"

#define PS2_CMD A1
#define PS2_CLK A5
#define PS2_DAT A0
#define PS2_SEL A2

// *************************
// added from KurtEck's code.
#include "ps2_controller.h"
#include <stdlib.h>
#include <string.h>

PS2PACKET ps2p;
PS2PACKET ps2pPrev;
// *************************

void appInitHardware(void){
initHardware();
}

// and so on...

I tired compiling again. It seemed to understand the definitions, but now I am getting several of these sets of errors:

Code: [Select]
../webbotlib/2.09/ps2_controller.h:60: error: 'const struct IOPin' has no member named 'high'
../webbotlib/2.09/ps2_controller.h:62: error: 'const struct IOPin' has no member named 'low'
../webbotlib/2.09/ps2_controller.h:67: error: 'const struct IOPin' has no member named 'isHigh'

test.cpp:35: error: 'Toggle' was not declared in this scope

I have no idea at all what the Toggle error is all about. I don't see that anywhere. The section of code from the "ps2_controller.h" errors:

Code: [Select]
uint8_t gameuint8_t(uint8_t command)
{
short int i ;
short int j;
        delay_us(1);
        short int data = 0x00; // clear data variable to save setting low bits later.
       
for(i=0;i<8;i++)
        {
if (command & 0x1)
PS2_CMD.high(); // sbi(PORTK, PScommand); // bit bang "command" out on PScommand wire.
else
PS2_CMD.low(); // cbi(PORTK, PScommand);
PS2_CLK.low(); // cbi(PORTK, PSclock); // CLOCK LOW
// delay_us(1); // wait for output to stabilise
for (j=10; j > 0; j--);
if ( PS2_DAT.isHigh()) // if((PINK & _BV(PSdata)))
sbi(data, i);
PS2_CLK.high(); // sbi(PORTK, PSclock); // CLOCK HIGH
command = command >> 1;
}
PS2_CMD.high(); // sbi(PORTK, PScommand);
// delay_us(20); // wait for ACK to pass.
for (j=100; j > 0; j--);
        return(data);
}

I did send a message to KurtEck asking for some help since this is beyond my admittedly limited knowledge. He is tied up with other stuff at the moment, but said he would look into it when he has time. There is no rush on my part; but for now, I thought I would post this hoping somebody else might have a solution.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: PS2 Controller Problem
« Reply #1 on: November 11, 2012, 08:18:17 AM »
Did you ever get this to work?

 


data_list