2017 FRC Control SystemFRC C++ Programming FRC C++ BasicsC++ conventions for objects, methods, and variables

C++ conventions for objects, methods, and variables

Every sensor, actuator and operator interface component is an object in either C++ or Java programs. To use one of these you must create an instance of it using the class name. Any references to the objects such as reading values, setting values, or setting parameters is done through the reference. There are a number of utility objects in WPILib such as the RobotDrive and Compressor that don't represent a single sensor or actuator, but a larger subsystem.

Another convention used throughout the library is the case of the method names. In C++ all methods start with an upper case letter, then are camel case (intermediate words capitalized). In Java all methods start with lower case letters then camel case for the remainder of the name.

Creating objects that are connected to the roboRIO in C++

C++
Gyro *headingGyro = new AnalogGyro(1); // Creates a Gyro object connected to channel 1 float heading  = headingGyro->GetAngle(); // Gets the current heading from the Gyro and stores it in the variable heading

Generally all the objects in WPILib that connect to roboRIO 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 both C++ and Java.

Creating operator interface objects

C++
Joystick *stick = new Joystick(1); // Creates a Joystick object connected to USB on port 1 of the driverstation double speed = stick->GetX(); // Gets the current X axis value of the joystick nd stores it in the variable "speed"

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.

Class, method, and variable naming

Class, method, and variable naming

Names in WPILib follow the conventions shown in the table above. It makes it very easy to determine what the scope and use of a variable is just by looking a the name and is a convention that is used throughout WPILib.

MXP IO Numbering

MXP IO Numbering

In C++ and Java the numbering for the MXP IO is a continuation of the numbering from the headers, meaning MXP DIO 0 is DIO 10, MXP DIO 1 is DIO 11 and so on. This applies to DIO, PWM and Analog Input on the MXP. The I2C and SPI buses have enumerations used to indicate which port you are using.

0 Report Errors

Use this form to report any errors with the documentation. For help with WPILib, please use the FIRST Forums at http://forums.usfirst.org For reporting WPILib bugs, please submit an issue on GitHub at https://github.com/wpilibsuite/allwpilib/issues/new

Ignore