What is WPILib

The WPI Robotics library (WPILib) is a set of software classes that interfaces with the hardware and software in your FRC robot’s control system. There are classes to handle sensors, motor speed controllers, the driver station, and a number of other utility functions such as timing and field management. In addition, WPILib supports many commonly used sensors that are not in the kit, such as ultrasonic rangefinders.

What's included in the library

What's included in the library

There are three versions of the library, one for each supported language. This document specifically deals with the text-based languages, C++ and Java. There is considerable effort to keep the APIs for Java and C++ very similar with class names and method names being the same. There are some differences that reflect language differences such as pointers vs. references, name case conventions, and some minor differences in functionality. These languages were chosen because they represent a good level of abstraction, are used heavily in industry, and are often taught in High School and college courses. The WPI Robotics Library is designed for maximum extensibility and software reuse with these languages.

WPILib has a generalized set of features, such as general-purpose counters, to provide support for custom hardware and devices. The FPGA hardware also allows for interrupt processing to be dispatched at the task level, instead of as kernel interrupt handlers, reducing the complexity of many common real-time issues.

Fundamentally, C++ offers the highest performance possible for your robot programs (this only comes into effect with very tight timing or very CPU intensive processing). Java on the other hand has acceptable performance and includes extensive run-time checking of your program to make it much easier to debug and detect errors. Those with extensive programming experience can probably make their own choices, and beginning might do better with Java to take advantage of the ease of use.

There is a detailed list of the differences between C++ and Java on Wikipedia available here. Below is a summary of the differences that will most likely effect robot programs created with WPILib.

WPILib Documentation

WPILib Documentation

Documentation for WPILib APIs for C++ and Java can be found here:

C++: http://first.wpi.edu/FRC/roborio/release/docs/cpp 
Java: http://first.wpi.edu/FRC/roborio/release/docs/java 

with separate sections for C++ and Java documentation. Both languages are documented similarly with a tree showing all the classes, methods, and public constants. This will automatically update as new versions of the library are released.

WPILib Source Code

Source code for WPILib is not currently bundled with the Eclipse Plugins. To browse the source code for WPILib online or for information about checking out the repository using GIT, see the "allwpilib" project on GitHub: https://github.com/wpilibsuite/allwpilib

Java programming with WPILib

Java
public void autonomousInit() { isAuto = true; CommandBase.shooter.zeroRPMOffsets(); \ CommandBase.turret.zeroAngleOffsets(); // instantiate the command used for the autonomous period autonomousCommand = (Command) (OI.getInstance().auton.getSelected()); \ // schedule the autonomous command (example) autonomousCommand.start(); }

  • Java objects must be allocated manually, but are freed automatically when no references remain.
  • References to objects instead of pointers are used. All objects must be allocated with the new operator and are referenced using the dot (.) operator (e.g. gyro.getAngle()).
  • Header files are not necessary and references are automatically resolved as the program is built.
  • Only single inheritance is supported, but interfaces are added to Java to get most of the benefits that multiple inheritance provides.
  • Checks for array subscripts out of bounds, uninitialized references to objects and other runtime errors that might occur in program development.
  • Compiles to byte code for a virtual machine, and must be interpreted.

C++ programming with WPILib

C++
void Claw::Open() { victor->Set(1); } void Claw::Close() { victor->Set(-1); } void Claw::Stop() { victor->Set(0); }

  • Memory allocated and freed manually.
  • Pointers, references, and local instances of objects.
  • Header files and preprocessor used for including declarations in necessary parts of the program.
  • Implements multiple inheritance where a class can be derived from several other classes, combining the behavior of all the base classes.
  • Does not natively check for many common runtime errors.
  • Highest performance on the platform, because it compiles directly to machine code for the ARM processor in the roboRIO

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