2014 FRC Control SystemGetting started with Java Creating Robot ProgramsJava conventions for objects, methods and variables

Java conventions for objects, methods and variables

Creating objects that are connected to the cRIO in Java

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.

  1. 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.
  2. Creates a DigitalInput object connected to the 2nd installed digital module using channel 3 and stores the address in the variable "limitSwitch".
  3. Gets the current heading from the Gyro in degrees and stores it in the variable "heading".

Creating operator interface objects in Java

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.

  1. Creates a Joystick object connected to USB port 1 on the DS (listed first in the Setup tab of the DS).
  2. Gets the current X axis value of the joystick and stores it in the variable "speed".

Class, method and variable naming

Class, method and variable naming

Module ordering and numbering

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.