View unanswered posts | View active topics It is currently Wed Oct 01, 2014 8:59 pm






Reply to topic  [ 7 posts ] 
NXT not recognizing joystick buttons 
Author Message
Rookie

Joined: Fri Apr 08, 2011 4:31 pm
Posts: 11
Post NXT not recognizing joystick buttons
I have already switched controllers, NXT's, computers, even the bluetooth and USB connections, and the NXT still won't receive any controller data. The computer recognizes button presses in the joystick debugger, however. When I used the debugging buttons, I found that even if the selected button is pressed, it would still see it as "false". I would appreciate any help!

Here is the code:

Code:
#pragma config(Hubs,  S1, HTServo,  none,     none,     none)
#pragma config(Sensor, S1,     ,                    sensorI2CMuxController)
#pragma config(Servo,  srvo_S1_C1_1,    baller1,              tServoContinuousRotation)
#pragma config(Servo,  srvo_S1_C1_2,    baller2,              tServoContinuousRotation)
#pragma config(Servo,  srvo_S1_C1_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S1_C1_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S1_C1_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S1_C1_6,    servo6,               tServoNone)

#include "JoystickDriver.c"

enum
{
  btn1mask       = 1 << 0,
  btn2mask       = 1 << 1,
  btn3mask       = 1 << 2,
  btn4mask       = 1 << 3,
  btn5mask       = 1 << 4,
  btn6mask       = 1 << 5,
  btn7mask       = 1 << 6,
  btn8mask       = 1 << 7,
  btn9mask       = 1 << 8,
  btn10mask      = 1 << 9,
  btn11mask      = 1 << 10,
  btn12mask      = 1 << 11
};

void initializeRobot()
{
  servo[baller1] = 127;
  servo[baller2] = 127;
}

void ballermove(int button)
{
  if(joy1Btn(button) == true)
  {
    while(joy1Btn(button) == true)
    {
      servo[baller1] = 255;
      servo[baller2] = 0;
    }
    servo[baller1] = 127;
    servo[baller2] = 127;
  }
}

task main
{
  initializeRobot();
  while(true)
  {
    ballermove(4);
  }
}


Thu Oct 13, 2011 6:21 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: NXT not recognizing joystick buttons
Try putting in
Code:
 getJoystickSettings(joystick);
into your while loop in the main task.

_________________
sudo rm -rf /


Thu Oct 13, 2011 7:00 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: NXT not recognizing joystick buttons
How about this?
Code:
task main
{
  initializeRobot();
  while(true)
  {
    getJoystickSettings(joystick);
    ballermove(4);
  }
}


Thu Oct 13, 2011 7:01 pm
Profile
Rookie

Joined: Fri Apr 08, 2011 4:31 pm
Posts: 11
Post Re: NXT not recognizing joystick buttons
Well, I inserted it into the while loop, and it kind of works now. When I press the button, it will enter in the if and while, but now it doesn't exit the loop when I let go of the button.


Fri Oct 14, 2011 4:25 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: NXT not recognizing joystick buttons
Well, when you are spinning in the while loop inside ballermove, you did not update the joystick structure with new button info. You should not have a while loop insdie ballermove. Do this instead:
Code:
#pragma config(Hubs,  S1, HTServo,  none,     none,     none)
#pragma config(Sensor, S1,     ,                    sensorI2CMuxController)
#pragma config(Servo,  srvo_S1_C1_1,    baller1,              tServoContinuousRotation)
#pragma config(Servo,  srvo_S1_C1_2,    baller2,              tServoContinuousRotation)
#pragma config(Servo,  srvo_S1_C1_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S1_C1_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S1_C1_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S1_C1_6,    servo6,               tServoNone)

#include "JoystickDriver.c"

enum
{
  btn1mask       = 1 << 0,
  btn2mask       = 1 << 1,
  btn3mask       = 1 << 2,
  btn4mask       = 1 << 3,
  btn5mask       = 1 << 4,
  btn6mask       = 1 << 5,
  btn7mask       = 1 << 6,
  btn8mask       = 1 << 7,
  btn9mask       = 1 << 8,
  btn10mask      = 1 << 9,
  btn11mask      = 1 << 10,
  btn12mask      = 1 << 11
};

void initializeRobot()
{
  servo[baller1] = 127;
  servo[baller2] = 127;
}

void ballermove(int button)
{
  if(joy1Btn(button) == true)
  {
      servo[baller1] = 255;
      servo[baller2] = 0;
  }
  else
  {
    servo[baller1] = 127;
    servo[baller2] = 127;
  }
}

task main
{
  initializeRobot();
  while(true)
  {
    getJoystickSettings(joystick);
    ballermove(4);
  }
}


Fri Oct 14, 2011 4:31 pm
Profile
Rookie

Joined: Fri Apr 08, 2011 4:31 pm
Posts: 11
Post Re: NXT not recognizing joystick buttons
Thanks! But why do we have to use the getJoystickSettings() function now? It used to be where we didn't have to, it just "worked".


Fri Oct 14, 2011 4:47 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: NXT not recognizing joystick buttons
You always need to call getJoystickSettings. I believe in previous years, some built-in task was calling it for you. It must be that they no longer do that this year. In any case, I never rely on that assumption, so I always call getJoystickSettings myself. It is the mechanism to "update" the joystick structure with new data.


Fri Oct 14, 2011 5:56 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.