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. https://github.com/wpilibsuite/allwpilib/blob/master/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/selectcommand/RobotContainer.java

6 Likes

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: https://github.com/BitBucketsFRC4183/FRC2020_Infinite_Recharge/blob/master/InfiniteRecharge/src/main/java/frc/robot/config/ConfigChooser.java

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)

3 Likes

You can port forward things around on the rio using the PortForwarder class, https://docs.wpilib.org/en/stable/docs/networking/networking-utilities/portforwarding.html

2 Likes

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

4 Likes

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
    intakeButton.and(finalConveyorDetector.or(launcherConveyorDetector).negate())
        .whileActiveContinuous(new IntakeBallIntake(ballIntake));

    // Conveyor
    intakeButton.and(initialConveyorDetector.or(finalConveyorDetector).and(launcherConveyorDetector.negate()))
        .whileActiveContinuous(new AdvanceConveyor(conveyor));

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

5 Likes

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);

  @Override
  public teleopPeriodic() {
    // Toggle a solenoid when a button is pressed
    if (controller.getAButtonPressed()) {
      intakeStower.set(!intakeStower.get());
    }
  }
}
2 Likes

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

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.