Commit Graph

8244 Commits

Author SHA1 Message Date
Peter Johnson
e085c3e8b3 [examples,cscore] Don't use assertTimeoutPreemptively in tests (#8951)
Particularly with short timeouts, this results in spurious failures
under high CPU load.
2026-06-05 07:28:51 -07:00
Sam Carlberg
98c03baf54 [javac] Add compiler check for integer division in floating-point contexts (#8885)
Useful for catching bad behavior when doing math or configuring ratios
with integers. Errors can be turned off with
`@SuppressWarnings("IntegerDivision")`

```java
double kV = 12 / 6000; // error: integer division in a floating-point context
double kV = 12. / 6000; // OK
double kV = 12 / 6000.; // OK

int kV = 12 / 6000; // OK, but evaluates to 0

double ratio = 42 / 12; // error: integer division in a floating-point context

@SuppressWarnings("IntegerDivision")
double ratio = 42 / 12; // OK, evaluates to 2
```

```
Execution failed for task ':developerRobot:compileJava'.
> Compilation failed; see the compiler output below.
  /Users/sam/code/wpilib/allwpilib/developerRobot/src/main/java/wpilib/robot/Robot.java:10: error: integer division in a floating-point context
    double kV = 12 / 6000;
                   ^
  1 error
```

Also adds the compiler plugin as a dependency to the developerRobot
project for dev testing
2026-06-04 21:56:22 -07:00
sciencewhiz
8353b95507 Add avahi license to ThirdPartyNotices (#8883) 2026-06-04 21:54:00 -07:00
Benjamin Hall
a41679854b [wpimath] Fix C++ Odometry ResetRotation missing a negation (#8949)
The original implementation was `m_gyroOffset + (rotation -
m_pose.Rotation())`, which means the first `RotateBy` should be using
`-m_pose.Rotation()` (see `ResetPose()`). Java is already correct. This
also adds new tests to catch this particular error.
2026-06-04 17:03:22 -07:00
PJ Reiniger
fdc6fd9cb1 [build][bazel] Combine remote setup CI actions (#8893)
When the bazel remote cache was switched from buildbuddy to a self
hosted server in #8342, I asked that the buildbuddy hooks be remain so
that I could still use their caching service for local builds.

The downside of this was that my forks builds aren't leveraging
buildbuddy, so if I'm fiddling with something heavy like a wpimath
robotpy thing, my CI builds never update a cache and never are warm when
I push fixups.


This PR combines the `setup-bazel-remote` and `setup-build-buddy`
actions which set up the bazel remote cache. Rather than having two
different version, the correct one will be choosen in the following
order:
1. Use wpi's server with write access if the `bazel_remote` information
is set (This basically would only happen on main branch in
`wpilibsuite/allwpilib` since secrets aren't accessible from builds
originating in forks)
2. Use buildbuddy if the key it is present (This would work for my fork
builds)
3. Fall back to the readonly version of wpi's server


As seen
[here](https://github.com/bzlmodRio/allwpilib/actions/runs/25777428163/job/75712863120#step:7:28)
the build in my fork will run with buildbuddy, and my PR's build here
should fall back to readonly mode.
2026-06-03 20:16:42 -07:00
PJ Reiniger
dca59147e1 [robotpy][examples] Split examples and snippets (#8944)
This also updates the bazel scripts to behave more like the C++ and Java
examples, and updates the copybara scripts to be able to sync up
`mostrobotpy`
2026-06-03 19:43:16 -07:00
Benjamin Hall
a734275cc5 [wpimath] Add const qualifier to C++ SwerveModuleVelocity Optimize and CosineScale (#8946)
These two functions were changed to return new objects instead of
modifying in-place, so the `const` qualifier should be added. Otherwise,
users with a const reference to a `SwerveModuleVelocity` need to make a
temporary copy first.
2026-06-03 19:42:05 -07:00
Peter Johnson
3f0d7bc2c4 [wpiutil,hal] Move C++ Handle wrapper to wpiutil (#8935)
Also move WPI_Handle typedef to its own header (util/Handle.h).
2026-06-01 14:57:25 -06:00
Vasista Vovveti
3d982f81dd [ntcore] Update period on added or removed, not XOR (#8941)
`added ^ removed` (XOR) is incorrect for the update guard.
Both `added` and `removed` can be true simultaneously (e.g. subscription
options change), and XOR would incorrectly skip the period update. Fixed
to `added || removed`.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-01 14:56:23 -06:00
sciencewhiz
a3c18d24a7 [examples] Add mecanum drive snippets (#8931)
shows both polar, and cartesian
2026-05-29 23:10:42 -07:00
Peter Johnson
c597116f02 [hal] HALSIM_StepTiming: Avoid underflow (#8933)
Don't advance time if the only active timer is in the past; just wake up
any notifiers.
2026-05-29 23:10:02 -07:00
Peter Johnson
9adffd356d [hal] Update waitForProgramStart to optionally wait for first notifier (#8932)
This addresses a race condition caused by TimedRobot and other
frameworks not creating their first notifier alarm until after signaling
program start.

Default this to true because it's the most common desired use case when
combined with TimedRobot.
2026-05-29 23:09:25 -07:00
Thad House
635e971a02 [wpilib] Add a default deadband to all gamepads (#8897)
The FTC DS had a deadband. Additionally, the FRC one had an implicit
deadband due to the only 8 bit resolution. We need a deadband by default
now with the high resolution gamepads.
2026-05-29 16:31:48 -07:00
sciencewhiz
40fdb779d8 [examples] Add differential drive snippets (#8927)
Shows tank, arcade, and curvature for wpilib-docs
2026-05-29 15:00:12 -07:00
Tyler Veness
e728ee27f2 [upstream_utils] Upgrade to Sleipnir 0.6.1 (#8930)
This fixes a memory leak on Windows.
2026-05-29 14:59:39 -07:00
Guinea Wheek
50fd29e697 [ntcore] Fix unbounded memory size tracker (#8929)
If a `ClientMessageQueue` is at a
memory limit, `ClientMessageQueueImpl::ClientSetValue` will still
increment `m_valueSize.size` even though no element has actually been
actually been added.

This quickly results in things like topics completely shutting down
under high load, as no new elements can be added as `m_valueSize.size`
explodes to infinity unless `ClearQueue()` is explicitly called. You can
see this pretty easily with the following code, be it in sim or on a
robot:

```cpp
#include "wpi/framework/TimedRobot.hpp"
#include "wpi/smartdashboard/SmartDashboard.hpp"
class Robot : public wpi::TimedRobot {
  public:
  // ...
  uint64_t value{0};
  /**
   * This function is called periodically during all modes
   */
  void RobotPeriodic() override {
    for (int i = 0; i < 1'000'000; i++) {
      value += 1;
      wpi::SmartDashboard::PutNumber("value", value);
    }
  }
}
```

Connecting via your favorite dashboard quickly reveals that no new
values get added after a while. However, with this patch implemented,
values do still continue to increment as updates gradually get serviced.
2026-05-29 11:01:13 -07:00
Sam Carlberg
4fa5dacfc4 [epilogue] Improve support for robot base classes in epilogue (#8886)
Generate an `update` method for any logged Robot class, not just
TimedRobot

Continue to generate a `bind` method for TimedRobot subclasses

Also removes unnecessary import statements for generated loggers, since
they're using fully-qualified names in the generated Epilogue class now.
2026-05-29 00:14:30 -04:00
sciencewhiz
1e12408a7d [examples] add motor safety and invert to motor snip (#8924) 2026-05-28 20:09:07 -07:00
sciencewhiz
14db070c2c [build] Add guard for missing arm64 msvc runtime (#8922) 2026-05-28 20:08:46 -07:00
sciencewhiz
5c3a474a58 Replace references of frc-docs with wpilib-docs (NFC) (#8926) 2026-05-28 09:01:11 -06:00
Tyler Veness
f1d95ee5f8 [upstream_utils] Upgrade to Sleipnir 0.6.0 (#8923) 2026-05-27 21:26:42 -07:00
Jonah Snider
7ff32d7756 [epilogue,ntcore,wpiunits] Use pattern matching switch expressions where possible (#8925)
Use [pattern matching switch
expressions](https://docs.oracle.com/en/java/javase/17/language/pattern-matching-switch.html)
where possible. This is a JVM 21+ feature which wasn't available until
recently.

If you look at the Java bytecode, this improves performance from an O(n)
runtime check of literally each of the `if (x instanceof y)` checks to
instead be an O(1) tableswitch.

---------

Signed-off-by: Jonah Snider <jonah@jonahsnider.com>
2026-05-27 18:06:15 -07:00
Tyler Veness
aedee56e22 [upstream_utils] Add cbegin()/cend()/crbegin()/crend() to SmallVector (#8918)
std::vector has these.
2026-05-26 21:55:50 -07:00
Peter Johnson
ac7a9524f8 [wpigui] Add stdint.h include to PFD (#8920)
Needed for uint8_t.
2026-05-26 21:55:22 -07:00
Thad House
b100586cab [wpilib] Finish gamepad face button rename (#8921) 2026-05-26 21:55:07 -07:00
Tyler Veness
254ca64106 [upstream_utils] Upgrade to LLVM 22.1.6 (#8919) 2026-05-26 16:25:29 -07:00
Peter Johnson
1392db4529 [romi] Fix Romi motor support (#8915)
Since Servo has been removed from WPILib, add a RomiServo to replace it
(similar to XRPServo).

For Romi, move allocation of PWM channels to OnBoardIO since Motor and
Servo share channels.
2026-05-23 17:38:36 -07:00
Peter Johnson
40f9a87e70 [xrp] Fix motor support (#8916)
The protocol layer got out of sync with the rename to throttle.
2026-05-23 17:37:38 -07:00
Sam Carlberg
94fda36e04 [cmd3] Add trigger multi press and continuous bindings (#8901)
`Trigger.multiPress(N, T)` creates a trigger that fires when there are
at least N rising edges within the last T timespan, eg `multiPress(3,
Seconds.of(1.25))` for 3 rising edges within the last 1.25 seconds.

`Trigger.retryWhileTrue` and `retryWhileFalse` will continuously attempt
to schedule a command while the binding condition is met. This is
similar to `whileTrue` and `whileFalse`, but will reschedule the command
if it ends or is canceled while the binding condition is still met,
rather than requiring a new rising edge to reschedule it.
2026-05-23 16:51:45 -07:00
Sam Carlberg
f217dfe747 [cmd3] Make sideload functions scoped and improve docs (#8900)
Notably, this removes the ability to escape command scoping by using a
sideloaded function to schedule another command
2026-05-23 16:50:46 -07:00
crueter
d86378d353 [wpimath,wpiunits] Add PoundSquareInches MOI unit, and improve KilogramMetersSquaredPerSecond definition (#8838)
As discussed in the discord. lb-in^2 is the common imperial MOI unit,
e.g. Onshape uses it.

Also, improved the Java docstring for `KilogramMetersSquaredPerSecond`
to explain what it represents.

---------

Co-authored-by: Benjamin Hall <bhall@ctr-electronics.com>
2026-05-23 16:41:35 -07:00
Gold856
ac41523eb4 [ci] Run wpilibc through asan (#8868) 2026-05-23 16:40:32 -07:00
David Vo
d48f1cd0e5 [bazel] Add mrclib dependency (#8873)
This pulls in the `mrclib` maven repository as shared libraries, as a
prereq for #8858.

Alternative to #8869, which avoids the unnecessary lockfile entry. This
should be a one-to-one replacement for that PR.

Closes #8869

---------

Co-authored-by: PJ Reiniger <pj.reiniger@gmail.com>
2026-05-23 16:39:47 -07:00
Gold856
e88729c67e [ci] Start avahi-daemon in sentinel builds (#8914)
This fixes the mDNS test failures in the sentinel builds.
2026-05-23 15:39:22 -07:00
Daniel Chen
e35ca772fd [cmd3] Make Mechanism an interface (#8303)
Since there is no longer a requirement for Subsystems/Mechanisms to be
registered to the command scheduler via a register() call, Mechanism can
be changed to an interface instead to allow for more flexible
inheritance structures.

Specifically, this would allow compatibility with CTRE swerve (which
previously required implementing Subsystem so that it could extend
CTRE's base class).
2026-05-18 19:30:12 -05:00
Thad House
fa24446ce3 [wpilib,cmd] Rename gamepad face-button trigger APIs to directional names (faceUp/Down/Left/Right) (#8896)
This updates gamepad trigger naming from cardinal-style face buttons
(`northFace/southFace/eastFace/westFace` and
`NorthFace/SouthFace/EastFace/WestFace`) to directional naming
(`faceUp/faceDown/faceRight/faceLeft` and
`FaceUp/FaceDown/FaceRight/FaceLeft`) to match the requested API shape.
The change is applied across Java and C++ HID/command layers, along with
related examples and binding metadata.

- **API surface updates (Java)**
  - Renamed trigger/event methods in:
    - `wpilibj` `Gamepad`
    - `commandsv2` `CommandGamepad`
    - `commandsv3` `CommandGamepad`
  - Mapping preserved:
    - `southFace` → `faceDown`
    - `eastFace` → `faceRight`
    - `westFace` → `faceLeft`
    - `northFace` → `faceUp`

- **API surface updates (C++)**
  - Renamed trigger/event methods in:
    - `wpilibc` `Gamepad`
    - `commandsv2` `CommandGamepad`
  - Mapping preserved:
    - `SouthFace` → `FaceDown`
    - `EastFace` → `FaceRight`
    - `WestFace` → `FaceLeft`
    - `NorthFace` → `FaceUp`

- **Python semiwrap updates**
- Updated `wpilibc/src/main/python/semiwrap/Gamepad.yml` method mappings
to the renamed C++ method names (`FaceDown/FaceRight/FaceLeft/FaceUp`).

- **Callsite migration**
- Updated Java examples/template code and C++ examples/template code to
use the new method names so samples remain aligned with the API rename.

- **Docs/comments alignment**
- Updated related Javadoc/reference text and example comments to use
directional terminology.

```java
// Before
driverController.southFace().onTrue(command);
driverController.eastFace().onTrue(command);

// After
driverController.faceDown().onTrue(command);
driverController.faceRight().onTrue(command);
```

```cpp
// Before
driverController.SouthFace().OnTrue(command);
driverController.EastFace().OnTrue(command);

// After
driverController.FaceDown().OnTrue(command);
driverController.FaceRight().OnTrue(command);
```

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ThadHouse <7727148+ThadHouse@users.noreply.github.com>
2026-05-15 00:08:57 -05:00
Thad House
67b795057b [build] Add arm64 MSVC Runtime (#8840) 2026-05-15 00:06:18 -05:00
sciencewhiz
e4ae671b49 [ci] Add CI spelling check and fix spelling errors (#8882)
reviewdog/action-misspell is used on frc-docs. It has a dictionary of
commonly misspelled words, so it has less false positives then other
tools.
2026-05-14 21:55:02 -07:00
David Vo
f751ca88eb [bazel] Enforce up-to-date lock file in CI (#8860)
The Bazel lock file was missing a few dependencies. This adds a check in
CI that the lock file is up-to-date.
2026-05-14 21:54:04 -07:00
PJ Reiniger
6ba5734a94 [robotpy] Add wrapper for timestamp functions, like SetNowImpl (#8889)
`SetNowImpl` is used somewhat often in unit tests. It is a little bit
goofier to wrap because it takes a C function, so a little bit more work
has to be done to get that wrapped in pybind.

Claude helped.
2026-05-14 21:53:26 -07:00
PJ Reiniger
68d24bb29e [python] Improve robotpy generation (#8867)
The initial build file generation for robotpy projects was relatively
naive and purpose built to get `allwpilib` compiling, without supporting
all the available features.

This modifies the generation scripts to be able to support multiple
embedded libraries, which will be necessary for #8858, since `mrclib.so`
will need to be bundled along with the hal libraries. In addition some
cleanup was done to get the wheels looking more like what is in pypi.
2026-05-14 21:52:39 -07:00
Thad House
3f1cf3cabe [wpilib] ExHub Follower Fixes (#8892)
A chunk of updates to followers on Expansion Hub

Fixes followers not implicitly enabling.
Allows followers to follow other followers
Throws exceptions on construction if a follower cycle is detected.
Allows reversing followers.

The enable thing will fix
https://github.com/wpilibsuite/SystemcoreTesting/discussions/259#discussioncomment-16886195

Closes #8843

Depends on https://github.com/wpilibsuite/scservices/pull/30
2026-05-14 21:50:38 -07:00
Jade
b91001f504 Add nix files to gitignore (#8894)
Based on discord comments I assume we don't want to support a Nix shell
or flake for use with building allwpilib so we should just ignore these
files so users can have their own
2026-05-14 21:49:01 -07:00
Thad House
ffd36eb091 [developerRobot] Add an OpModeRobot instance to DeveloperRobot (#8891)
You can switch to it just by switching Main.java
2026-05-14 21:48:09 -07:00
crueter
97c0b0c40a [upstream_utils] Patch LLVM SmallSetIterator for AppleClang 21 (#8877)
Signed-off-by: crueter <crueter@eden-emu.dev>
2026-05-08 12:49:47 -07:00
sciencewhiz
16fcf016de [examples] Update command template names with v2 to disambiguate (NFC) (#8875)
Partially addresses wpilibsuite/vscode-wpilib#876
2026-05-08 09:34:52 -07:00
Ryan Blue
878da3d54c [cmd3] Fix StateMachineTest (#8876) v2027.0.0-alpha-6 2026-05-07 21:42:16 -07:00
Sam Carlberg
1021ff88a9 [cmd3] Add a declarative state machine API on top of commands v3 (#8297)
This provides an API for writing a finite state machine compatible with
the commands v3 framework. Individual states in the state machine are
wrappers around command objects (which may themselves be state
machines). Transitions between states are defined with a staged builder
DSL similar to command builders, and uses `@NoDiscard` to catch
partially configured transitions.

The FSM API is meant to handle highly complex cases that the fluent
command chaining DSL and coroutine-based imperative commands cannot
easily represent; specifically, where a command sequence may want to go
back to an arbitrary previous state or skip forward to an arbitrary
future state.

Here's an example from the design doc for a command that will drive to a
known scoring location, aim at a scoring target, and repeatedly shoot
balls until a storage hopper is empty. It also has conditions to stop
shooting and move back to the scoring location if it's jostled away, and
then automatically resume firing.

```java
public Command autoWithStateMachine() {
  // Declare the state machine
  StateMachine stateMachine = new StateMachine("Auto With State Machine");

  // Define states
  State getInPosition = stateMachine.addState(drivetrain.driveToScoringLocation());
  State aiming = stateMachine.addState(turret.aimAtGoal());
  State scoring = stateMachine.addState(shooter.fireOnce());
  State celebrating = stateMachine.addState(leds.celebrate());

  // Set the initial state. Neglecting this will cause a runtime exception when the state machine starts.
  // Teams using the WPILib compiler plugin will get a compiler error if they do not set this
  stateMachine.setInitialState(getInPosition);

  // Switch to aiming when we reach the scoring location.
  getInPosition.switchTo(aiming).whenComplete();
  // Set the swerve wheels in an X shape after reaching the scoring location to resist being pushed away.
  getInPosition.onExit(() -> Scheduler.getDefault().fork(drivetrain.setX()));

  // Then start scoring once the turret is aimed at the goal.
  aiming.switchTo(scoring).when(turret::aimedAtGoal);

  // Loop the scoring state as long as the hopper has a ball.
  scoring.switchTo(scoring).whenCompleteAnd(() -> hopper.hasBall());

  // Automatically interrupt any part of the aiming or scoring sequence if
  // the robot is moved away from the scoring location and move back into position.
  stateMachine.switchFromAny(aiming, scoring).to(getInPosition).when(atScoringLocation.negate());

  // Start celebrating once the final ball has been scored.
  scoring.switchTo(celebrating).whenCompleteAnd(() -> !hopper.hasBall());

  return stateMachine;
}
```

A compiler check is added to detect object construction that's not
followed by post-construction initializer methods (as defined by the
class by placing `@PostConstructionInitializer` on such methods).
`StateMachine.setInitialState` uses this to detect team code that
creates a state machine but does not set its initial state.
2026-05-07 20:08:09 -07:00
Thad House
0af65ea787 [sim] Make HalSim DS extension a no-op (#8872)
This way this doesn't crash until we get real support added.
2026-05-07 20:04:37 -07:00
Gold856
8832d6a7c2 [sim] GUI: Fix game message string lifetime (#8874)
Fixes an issue where game data can't be set.
2026-05-07 20:03:28 -07:00