Log in

View Full Version : Joystick Buttons


KRibordy
23-01-2009, 17:55
We have two servos on our robot, which I would like to have controlled by a single button on the joystick. The servos will go up when the button is pressed, and down when it's released. I can't seem to get the buttons on the joystick to work. stick->GetRawButton(1) works, but that corresponds to the trigger, which is already in use.

I can't seem to get "GetTop()" or "GetRawButton(2)" to work, though. We've verified that the servos work, but the button won't work. We updated the software on the driver station when we set it up. Are there any updates that we missed?

Thanks in advance.

LinuxMercedes
23-01-2009, 20:33
Hmmm...have you set the software to printf() the value of the joystick buttons? If it prints 'false' when you've got the joystick button down, you've got hardware problems (or really bad software problems). If it prints 'true' (or something to that extent) when the button is down, you've got software problems.

Out of curiosity, are you controlling your servos through the Servo class? I wasn't able to get them to work with that...currently I drive them with a RobotDrive, although that's a kluge.

KRibordy
23-01-2009, 21:03
How do I use the printf() function? Right now I'm using a laptop that is wirelessly connected to the router, which I download the code through. Do I have to be "running" code instead of "downloading" it?

I am using the servo class to control the servos, and it worked wonderfully. Like I said, I use stick->GetRawButton(1); which gets the value of the trigger. That works. But none of the other buttons work--not GetTop() or GetRawButton(x).

LinuxMercedes
24-01-2009, 01:02
You should be debugging your code...FRC has instructions for that in one of their manuals. Put printf() statements in your code...I assume you know how to do this. If not, http://www.learncpp.com is a good place for C++ tutorials and will explain that.

Then, in your Remote Systems window down in the left-hand corner of WR, right click on the cRio, then about halfway up the menu there will be a submenu whose name I cannot remember. It's right under the Reset Target section of the menu. In that submenu there will be a Target Console option. Click that, and you will get the cRio's console. All your printf() statements will go there.

Thanks for the info on the servo class...I'll keep trying =]

Pancake
24-01-2009, 01:09
To use "printf", simply do
printf("Hello World!");

Or if you want to print a variable:

float number = 7.241;
printf("The value is: %f", number); // The value is: 7.241

And you need the cRIO connected to your computer via a serial cable to see the output :D

For the joystick issue, (I haven't actually tested it myself), I think it should work like:

Joystick stick(1); // Joystick plugged into USB port 1
Servo sv1(5);


if(stick.GetRawButton(2))
{
// Set the servo
sv1.set(someAngle);
}


Hope this helps, haven't actually tried this myself :)

byteit101
24-01-2009, 08:16
LinuxMercedes, do you do
Servo sv(3);
sv.Set(value between 0 and 170);
?

KRibordy
24-01-2009, 10:06
That's how we've been doing it, byteit. It worked fine for the servos. Actually it worked very well. It's just the buttons that our code hasn't been working with.

We've been debugging, just not with the console...:o
I'll try this today.