Java conventions for objects, methods and variables
Creating objects that are connected to the cRIO in Java
Generally all the objects in WPILib that connect to one of the cRIO breakout boards have one or two arguments in the constructor when created where you specify the channel or port number it is connected to. The above example illustrate the conventions used in WPILib for both C++ and Java.
- Creates a Gyro object connected to analog module 1 channel 1 and stores its address in "headingGyro". For convenience if only a single number is specified it is assumed to be for the first module of a given type (in this case an analog module) and the number is the channel or port number.
- Creates a DigitalInput object connected to the 2nd installed digital module using channel 3 and stores the address in the variable "limitSwitch".
- Gets the current heading from the Gyro in degrees and stores it in the variable "heading".
Creating operator interface objects in Java
Generally objects connected to the Driver station PC via USB (with the exception of the Cypress FIRST Touch board and Microsoft Kinect) take a single argument indicating the USB port they are connected to. A single Joystick class is provided which should provide the functionality needed to interface with any joystick or gamepad which works with the FRC Driver Station.
- Creates a Joystick object connected to USB port 1 on the DS (listed first in the Setup tab of the DS).
- Gets the current X axis value of the joystick and stores it in the variable "speed".
Module ordering and numbering
The device number represents the instance of the module type. For example the first digital module would be 1 and the second one would be 2. If you only had a single module of each type in your robot and you used the short form of the constructors when creating devices (where the slot number argument was left out and defaulted to the first module) then your code doesn’t have to change. The library will continue to default the numbers to the first module of a given type.