Tell me something I didn’t know about WPILIB

Here you can post a feature of WPILib you didn’t know about that other people might also have missed.

Example from my teammate:
The SelectCommand:
Ok here’s another cool thing I just found: SelectCommand. I had no idea this existed but it looks useful.


WPILib has a Preferences class (Java, C++) that lets you store values on the RoboRIO and get them at run time. Our team has some classes with configuration values like PID constants, gear ratios, max velocities, etc… and the specific instance we use depends on the RIO it’s loaded on. If you want to look at it, here’s our code for our ConfigChooser:

Another fun thing that isn’t quite as useful, there’s a utility class for matrix math that has a method for matrix exponentiation (Java, I don’t think there’s a C++ implementation. WPILibc uses Eigen which already has an expm(), but Java’s EJML doesn’t)


You can port forward things around on the rio using the PortForwarder class,


There’s a Guitar Hero controller wrapper for WPILIB and any other game controller should be usable as long as it’s wired.


One I posted before that several people were surprised about was being able to Link Triggers in order to create more advanced functionality.

3468 Made significant use of this with our Intake and Firing mechanism this year along with our three IR Diffuse Reflective Sensors.

    // Intake
        .whileActiveContinuous(new IntakeBallIntake(ballIntake));

    // Conveyor
        .whileActiveContinuous(new AdvanceConveyor(conveyor));

    // Launcher
    //    new SetLauncherVelocity(launcher, () -> Launcher.distanceToVelocity(camera.getDistanceFromGoal())));
    launchButton.and(launcherOnTarget).whileActiveContinuous(new AdvanceConveyor(conveyor));
        .whileActiveContinuous(new AdvanceConveyor(conveyor));   
    launchButton.whenPressed(new CameraLightOn(camera)).whenReleased(new CameraLightOff(camera));     


I wouldn’t really call support for it a “wrapper”. There’s Joystick and XboxController classes, but no GuitarHeroController class. GenericHID does have kXInputGuitar though (they all enumerate through Windows’s XInput), so making a wrapper would just be a matter of making an API that maps to the buttons and axes to human-readable names. It wouldn’t be that hard to write. I would be very amused by a PR containing the mappings. :wink:

I’m always surprised by how few teams know the following exists. WPILib’s HID classes like Joystick and XboxController have getButtonPressed() and getButtonReleased() methods. This lets you trigger actions once when a button goes from pressed to released or vice versa in two lines of code; the code reads basically how you’d describe it in English. (No more flip-flopping booleans to keep track of the button state!)

pubilc class Robot extends TimedRobot {
  private XboxController controller = new XboxController(0);
  private Solenoid intakeStower = new Solenoid(0);

  public teleopPeriodic() {
    // Toggle a solenoid when a button is pressed
    if (controller.getAButtonPressed()) {

Okay. I must have been remembering somebody’s custom code.