WPILib Example Projects¶
While every attempt is made to keep WPILib examples functional, they are not intended to be used “as-is.” At the very least, robot-specific constants will need to be changed for the code to work on a user robot. Many empirical constants have their values “faked” for demonstration purposes. Users are strongly encouraged to write their own code (from scratch or from an existing template) rather than copy example code.
WPILib example projects demonstrate a large number of library features and use patterns. Projects range from simple demonstrations of a single functionality to complete, competition-capable robot programs.
These examples demonstrate basic/minimal robot functionality. They are useful for beginning teams who are gaining initial familiarity with robot programming, but are highly limited in functionality.
TankDrive (Java): Demonstrates a simple differential drive implementation using “tank”-style controls through the
These examples demonstrate WPILib implementations of common robot controls. Sensors may be present, but are not the emphasized concept of these examples.
DifferentialDriveBot (Java, C++): Demonstrates an advanced differential drive implementation, including encoder-and-gyro odometry through the
DifferentialDriveOdometryclass, and composition with PID velocity control through the
MecanumBot (Java, C++): Demonstrates an advanced mecanum drive implementation, including encoder-and-gyro odometry through the
MecanumDriveOdometryclass, and composition with PID velocity control through the
SwerveBot (Java, C++): Demonstrates an advanced swerve drive implementation, including encoder-and-gyro odometry through the
SwerveDriveOdometryclass, and composition with PID position and velocity control through the
These examples demonstrate sensor reading and data processing using WPILib. Mechanisms control may be present, but is not the emphasized concept of these examples.
These examples demonstrate the use of the Command-Based framework.
DriveDistanceOffboard (Java, C++): Demonstrates the use of a
TrapezoidProfileCommandin conjunction with a “smart motor controller” to drive forward by a set distance with a trapezoidal motion profile.
HatchbotInlined (Java, C++): A complete set of robot code for a simple hatch-delivery bot typical of the 2017 FRC game Steamworks. Commands are written in an “inline” style, in which explicit subclassing of
HatchbotTraditional (Java, C++): A complete set of robot code for a simple hatch-delivery bot typical of the 2017 FRC game Steamworks. Commands are written in a “traditional” style, in which subclasses of
Commandare written for each robot action.
RamseteCommand (Java, C++): Demonstrates trajectory generation and following with a differential drive using the
RamseteCommandclasses. A matching step-by-step tutorial can be found here.
These examples demonstrate miscellaneous WPILib functionality that does not fit into any of the above categories.
DMA (C++): Demonstrates the use of DMA (Direct Memory Access) to read from sensors without using the RoboRIO’s CPU (C++ only).