Java conventions for objects, methods and variables
Creating objects that are connected to the roboRIO in Java
Gyro headingGyro = new AnalogGyro(1); double heading = headingGyro.getAngle();
Generally all the objects in WPILib that connect to one of the roboRIO breakout boards have one argument 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 Java.
- Creates an AnalogGyro object connected to analog channel 1 and stores its address in "headingGyro".
- Gets the current heading from the AnalogGyro 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 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".