View Single Post
  #4   Spotlight this post!  
Unread 19-01-2011, 23:57
Patrick Chiang Patrick Chiang is offline
Programming
FRC #3070 (Team Pronto)
Team Role: Mentor
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Seattle
Posts: 162
Patrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to all
Re: How to use JAVADOCS?

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:
Code:
Joystick leftStick;
Then, you initialize it in the constructor. I use "1" because it's the first joystick:
Code:
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:
Code:
System.out.println(leftStick.getX());
System.out.println(leftStick.getY());
Another way you can do it is:
Code:
System.out.println(leftStick.getAxis(Joystick.AxisType.kX));
To get the trigger button, you would do this:
Code:
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):
Code:
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:
Code:
RobotDrive drive;
Joystick leftStick, rightStick;
Initialization:
Code:
drive = new RobotDrive(1,2);
leftStick = new Joystick(1);
rightStick = new Joystick(2);
teleopContinuous:
Code:
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):
Code:
drive.tankDrive(leftStick, rightStick);
If you need more help (for the drive system, joysticks...etc), just ask.

Last edited by Patrick Chiang : 20-01-2011 at 00:06.
Reply With Quote