How do i use the javadocs? since the javadocs doesnt give examples, its hard to understand how to use it.
Is there any tutorial for the classes or examples of some of the classes such as joystick, jaguar and hid?
I am willing to help you as much as you need, just I have a few questions first. Do you know java? About how much experience in Java do you have?
thanks, I am in APCS currently so I know enough. I also had some c++ last year so im not new to programming.
basically what I want to do is use the Joystick class and System.out.println the x and y value of the joystick.
I also want to get boolean for if a button is pressed or not, but I dont understand the parameters: getButton(Joystick.ButtonType button)
I can’t find any examples of using the Joystick class other than the stuff for like tank drive.
btw, have they made sunspot for win 7 yet? or is there another virtual Crio thing?
THANKS A LOT for helping!
Okay, you want to print out the Joystick values right?
I’m assuming you have created a FRC Java project and figured out all the cRIO, Java plugins…etc stuff. I find the Iterative framework the best for us.
Joysticks
First, you declare a Joystick object, after the place where you declare the class and before your constructor:
Joystick leftStick;
Then, you initialize it in the constructor. I use “1” because it’s the first joystick:
leftStick = new Joystick(1);
After that, you can begin to use it. In your teleopPeriodic (or teleopContinuous) function, print out the value of the x and y axis:
System.out.println(leftStick.getX());
System.out.println(leftStick.getY());
Another way you can do it is:
System.out.println(leftStick.getAxis(Joystick.AxisType.kX));
To get the trigger button, you would do this:
leftStick.getButton(Joystick.ButtonType.kTrigger)
If you use Joystick.AxisType or Joystick.ButtonType, you would need to import them. (A nifty shortcut in netbeans is Shift+Ctrl+I which imports everything you need.)
More detailed explanation on the Button stuff and Javadocs:
See what getButton() has inside the parenthesis in the docs? It says “Joystick.ButtonType button” which means it takes in one (and only one) parameter with type Joystick.ButtonType. This means that you may NOT use integers, doubles, floats, booleans…etc, and you MUST use Joystick.ButtonType (kTop, kTrigger, kNumButton)
If you have a button that’s not the trigger or the enumerated buttons in Joystick.ButtonType, you can use the getRawButton() function. So, if you know the button number of what you want, you’d just do (example for button number 4):
leftStick.getRawButton(4);
To find out the button number, go to your Control Panel (switch to Classic View) and find Game Controllers. Pull up the properties menu of your controller and the rest should be pretty self-explanatory.
Drive System
A simple 2-motor tank drive system (Jaguars plugged into PWM 1 and 2) would look like this:
Declaration:
RobotDrive drive;
Joystick leftStick, rightStick;
Initialization:
drive = new RobotDrive(1,2);
leftStick = new Joystick(1);
rightStick = new Joystick(2);
teleopContinuous:
drive.tankDrive(leftStick.getY(),rightStick.getY());
According to the Javadocs, you can also directly feed the Joysticks into the RobotDrive. Never done it before, but it should work exactly the same (code is the same too, except for the teleopContinuous portion):
drive.tankDrive(leftStick, rightStick);
If you need more help (for the drive system, joysticks…etc), just ask.
Javadocs are the bible of java there are 3 main sections.
1 Constructors
2 Fields
3 Methods
Constructors explain what parameters (if any) are needed to be passed to create the object. From the example above …
Joystick joy = new Joystick(1);
Take a peek into the javadoc to see . . .
Joystick
public Joystick(int$@#port)
Construct an instance of a joystick. The joystick index is the usb port on the drivers station.
Parameters:
port - The port on the driver station that the joystick is plugged into.
So if you look at an example then the javadoc everything starts to become self explanatory.
Also note that if you run into a method or field that is declared static then you do not need to construct an object to use those methods or fields.
An example of static call would be
System.out.println("Something");
the System.out object is declared static so there is no
System.out = new ...
As to your other question about sunspot for win7, there is no reason it shouldn’t work. The file which installs the SDK now also recognizes 64-bit systems as valid. This is true whether you are using the NetBeans plug-ins or the Eclipse plug-ins (since the SDK for both is the same).
WOW you guys are really helpful! THANKS a BUNCH!!!
and Ryan, I got sunspot to work. Turns out, there weren’t any instructions for win 7 and i just had to follow the vista instructions. It didn’t work before because I didn’t set the permission to run as admin.
UM, what does it mean if we get only 0.0 as the output
Sorry this is a bit late in answering.
But if you see 0.0 as the output, that means that the joystick inputs are being read, and they’re showing 0.0. Check your driver station setup interface to see if the Joysticks are plugged into the right usb locations.
Also, keep in mind that you should keep outputting values instead of doing it only once.
If you only println it once, this is what happens:
Robot starts -> get joystick value -> print value -> you move joystick.
When you move the joystick, the robot has already printed the joystick value. It won’t update by itself, so you’ll get the default 0.0
You should println it continuously. You could put it into the teleopPeriodic or teleopContinuous loops. If you just want to test it, you could run an infinite loop as such:
while(true){
System.out.println(leftStick.getX());
}