Commit Graph

901 Commits

Author SHA1 Message Date
Gold856
2102a543d1 Change Java JSON to Avaje Jsonb (#8721)
Jackson is a very heavy library; it supports loads of features that we
don't need, and historically has caused issues due to long class loading
times (a little over 2 seconds to load AprilTagFieldLayout). This often
manifests as a help request in the form of "my robot disables when I do
X, but doesn't disable when doing X in subsequent attempts until code
restart." While SC has brought down Jackson loading times significantly,
with AprilTagFieldLayout loads taking only 330 milliseconds, that's
still a rather long delay, and while libraries should handle any JSON
loading ahead of time to prevent delays in auto/teleop, it would still
be good to make the worst case better to reduce user frustration.
Benchmarks indicate using [Avaje
Jsonb](https://github.com/avaje/avaje-jsonb) to load AprilTagFieldLayout
only takes ~70 ms, a fair chunk of which isn't actually in Avaje Jsonb
(~4 ms is spent on using getResourceAsStream to retrieve the JSON file,
~8 ms is spent on just loading the AprilTag class and its dependencies).

Note that all times listed are end-to-end, meaning nothing else was done
except for the operation being benchmarked, and doing arithmetic on them
can be flawed due to some classes being loaded twice, i.e.,
getResourceAsStream and `new AprilTag()` likely load some of the same
JDK classes and so subtracting both from the Avaje Jsonb load time is
likely slightly incorrect because class loading is being double counted.
For our purposes, it's likely accurate enough and is mostly just for
contextualization.

Benchmarks were run on a Raspberry Pi CM5 with 2 GB of RAM. Source code
for the
[results](https://github.com/user-attachments/files/26471452/benchmark.txt)
can be found in the "Fastjson2" commit
(2456d15ca8ebd17635e607cd40bf8816e77869a1).

Avaje Jsonb uses code generation via annotation processors to generate
the classes needed to do JSON serde and uses service providers to find
them, which will require downstream changes in robot projects, as the
different service providers in each library must be merged together for
Avaje Jsonb to function. We will use the Gradle shadow plugin, as its
already used by the installer and therefore adds zero additional
dependencies.
2026-04-10 23:21:00 -07:00
Tyler Veness
5a96685c86 [upstream_utils] Upgrade to Sleipnir 0.5.2
This fixes a bug in Sleipnir's Newton solver (the exit status was inaccurate because unconstrained optimization problems can't be infeasible).
2026-04-09 17:03:57 -07:00
Peter Johnson
9ca93fa190 Update for jart/json.cpp change 2026-04-08 08:28:28 -07:00
Tyler Veness
5b4769ea0a [upstream_utils] Upgrade to Sleipnir 0.5.1 (#8726)
There's changes to the diagnostic output and a performance improvement
for autodiff setup. I also updated Java's Options docs to more closely
match upstream.
2026-04-07 23:52:30 -07:00
Tyler Veness
d248c040bf [wpimath] Add Sleipnir Java bindings (#8236)
The wrapper includes reverse mode autodiff, the Problem DSL, and the
optimal control problem API. I wrote it by directly translating the
upstream
[API](https://github.com/SleipnirGroup/Sleipnir/tree/main/include/sleipnir)
and [tests](https://github.com/SleipnirGroup/Sleipnir/tree/main/test) to
Java (i.e., copy-paste-modify).

I replaced the ArmFeedforward and Ellipse2d JNIs with implementations
using the Sleipnir Java bindings. Switching dev binary JNIs to release
by default sped up wpimath test runs from several minutes to 7 seconds.
2026-03-29 22:34:21 -07:00
Tyler Veness
f3757bdeae [upstream_utils] Upgrade to Sleipnir 0.5.0 (#8711) 2026-03-29 20:39:18 -07:00
Peter Johnson
aa88fa0fcf [wpiutil] Rename struct constants to all caps 2026-03-20 13:24:22 -06:00
Peter Johnson
e944ae9aca [hal,wpilib] Rename FPGA clock to monotonic clock (#8672)
- Remove status return from HAL level (clock getting should never fail)
- Remove 32-bit timestamp expand function
- Make monotonic_clock.hpp (formerly fpga_clock.hpp) header-only and
move to root hal include directory
2026-03-15 15:08:41 -07:00
Gold856
d1fba06851 Remove deprecated code (#8656) 2026-03-14 21:28:31 -07:00
Thad House
b2b111dc11 Rename FRC to WPILib (#8637) 2026-03-13 23:05:55 -07:00
Tyler Veness
907bf05607 [ci] Upgrade to wpiformat 2026.56 (#8666) 2026-03-13 13:15:01 -07:00
PJ Reiniger
c0f8159540 [copybara] Resync with mostrobotpy (#8662) 2026-03-08 21:38:21 -07:00
Tyler Veness
71cd434699 [wpimath] Don't clamp Rotation2d interpolation (#8661)
Extrapolation is also valid.
2026-03-07 15:58:48 -08:00
Tyler Veness
b29bde123f [wpimath] Implement Rotation3d interpolation as slerp instead of lerp (#8529)
Also replace arithmetic operators since they're not commutative, which
is confusing for users.
2026-03-06 15:15:00 -08:00
Tyler Veness
9bd9656871 [wpimath] Replace Speeds with Velocities (#8479)
I left "free speed" alone since that's the technical term for it. In
general, velocity is a vector quantity, and speed is a magnitude (i.e.,
a strictly positive value).

This PR also replaces the speed verbiage in MotorController with duty
cycle.

Fixes #8423.
2026-03-06 14:19:15 -08:00
PJ Reiniger
51a3876330 [robotpy] Build examples (#8629)
This hooks up the bazel build to the robotpyExamples. It can use the
(formly pyfrc or whatever) automatic unit tests for an example, as well
as exposing the ability to run the example in simulation, with or
without `halsim_gui` with a command such as `bazel run
//robotpyExamples:AddressableLED-sim`

This required building and using wheels instead of just a normal
`py_library`, so that things like `ENTRY_POINTS` can be used. I took a
bare bones approach to building and naming the wheels (for example the
native ones don't have the OS info or python version in them, so they
wouldn't be suitable publish to pypi, but that can always be updated
later.
2026-03-05 23:18:37 -08:00
Tyler Veness
26b2b08c8d [wpimath] Clean up KalmanFilter tests (#8651)
Also synchronize C++ and Java versions of tests.
2026-03-05 23:17:36 -08:00
Gold856
c8780950c0 [wpimath] Simplify LinearSystem#slice in Java (#8658)
Avoids boxing to reduce allocations, combines for loops as an
optimization, and removes massive switch statement because Java's
generics are type erased, so the different type parameters make no
difference.
2026-03-05 23:16:44 -08:00
Peter Johnson
f08258f784 [wpiutil] Split C++ header files 2026-03-04 22:09:40 -07:00
Peter Johnson
c8c68329fa [build] Fix Robotpy pregeneration post-merge (#8641) 2026-02-27 15:14:47 -08:00
Peter Johnson
7513846c72 Merge branch 'main' into 2027 2026-02-27 14:24:41 -08:00
amsam0
7ca35e5678 [wpimath] Add limit setters to SlewRateLimiter (#8581)
This is just #7793 with requested changes applied.
2026-02-27 12:53:18 -08:00
Sam Carlberg
793b0a3187 [build] Migrate to Gradle version catalogs (#8524)
Also fixes the google compile-testing library to 0.23.0 (the latest
available at time of writing) instead of a wildcard

Jackson versions were inconsistent across projects; most were on 2.19.2,
but the fields subproject was on 2.15.2. All projects are now on 2.19.2
for consistency
2026-02-20 15:31:33 -08:00
PJ Reiniger
8f9fc4d1b6 [copybara] Import robotpy examples (#8608)
GitOrigin-RevId: 9ba4bc3040fa7e772f5a594039e78fc6c43d114e
2026-02-20 15:30:35 -08:00
PJ Reiniger
1dbffb972f [robotpy] Fixup build after merge (#8618) 2026-02-15 10:22:58 -08:00
Peter Johnson
af865f8020 Merge branch 'main' into 2027 2026-02-15 00:51:21 -08:00
Tyler Veness
245186cb15 Fix clangd #include warnings (#8565) 2026-02-11 12:15:02 -07:00
Charlotte Wilson
1680e676b6 [wpimath, wpiutil] Use java_multiple_files for Protobuf (#8555)
Closes #8256
2026-02-09 17:11:57 -08:00
PJ Reiniger
227c89ab23 [copybara] Resync robotpy (#8585)
Project import generated by Copybara.
    
GitOrigin-RevId: fd000778e9b78c72cc7ca7b2ebe476129b78c6e0
2026-02-08 07:36:35 -08:00
Tyler Veness
2c5529d714 [wpimath] Speed up pose estimator correction computation (#8574)
In C++, we use a diagonal matrix to avoid an expensive matrix
multiplication. EJML doesn't have a diagonal matrix type, so in Java, we
use a double array and implement the multiplication manually.
2026-02-06 21:47:49 -08:00
Michael Lesirge
21b5389bbe [wpimath,cmd] Add multi tap boolean stream filter and multi tap trigger modifier (double tap detector) (#8307)
Add a simple tap counting filter for boolean streams. 

The filter activates when the input has risen (transitioned from false
to true, like when a button is tapped) the required number of times
within the time window after the first rising edge. Once activated, the
output remains true as long as the input is true. The tap count resets
when the time window expires or when the input goes false after
activation.

Example usage:
```java
    xbox.a()
      .multiPress(2, 0.2) // Detect a double tap within 0.2 seconds
      .onTrue(Commands.print("Double tapped A button"));
      
     xbox.y()
      .multiPress(2, 0.5) // Detect a double tap within 0.5 seconds
      .whileTrue(Commands.print("Y held after tap").repeatedly());
```

This is not a noise reduction and/or input smoothing filter, but it is
similar in usage to debounce, so I believe it could be considered a
filter, but am open to a better location.

I believe this would be a useful addition, as double/triple tapping a
button is a common control option in games, yet is not often utilized by
newer FRC teams. I believe adding it to WPILib in a standard way will
allow more teams to make the most out of their controls.
2026-01-14 20:22:07 -08:00
Joseph Eng
9e1258440b [wpimath] Fix Rotation3d interpolation and document extrinsic vs intrinsic (#8544)
Documents the extrinsic vs intrinsic semantics of `plus()` and
`minus()`. (`rotateBy()` was documented in [a previous
PR](https://github.com/wpilibsuite/allwpilib/pull/5508))
Fixes usage of `plus()` and `minus()` in `Rotation3d.interpolate()`.
(Fixes #8523)
Fixes incorrect usages of `plus()`, `minus()`, and `rotateBy()`
throughout `Odometry3d`.
Adds explanatory comments for some `plus()`, `minus()`, and `rotateBy()`
operations.
Fixes `TimeInterpolatableBuffer` not using twists for `Pose3d` (this was
just because I happened to notice it, it isn't really related to the PR)

To check all of our usages of `plus()`, `minus()`, and `rotateBy()`, I
marked them as deprecated, checked compile errors from `./gradlew
compileJava`, and then undeprecated them. You can see all of the spots
that showed up (at least on the Java side) by viewing the diff for
241109c.

I wanted to present this alternative to #8526 because the change has its
own quirks, there's little time before kickoff, and there would be no
code-side warning to teams (and mentors) already used to the current
behavior.
2026-01-14 20:16:24 -08:00
PJ Reiniger
eccc2301ac [py] Add wpimath/kinematics tests (#8461)
Used Gemini to convert the C++ tests in wpimath/.../kinematics to
pytest. For ease of use required a better constructor for
`MecanumDriveWheelPositions`

I did this conversion months ago (before robotpy landed and before the
reorg), so new tests might be missing. At least its better than nothing
🤷

Broke the huge pr that does almost everything into parts so its easier
to review.

---------

Co-authored-by: David Vo <auscompgeek@users.noreply.github.com>
2026-01-12 19:14:14 -08:00
PJ Reiniger
762d1e8b93 [copybara] mostrobotpy to allwpilib (#8545)
Project import generated by Copybara.
GitOrigin-RevId: f10284b37498bb6a088891ca41f160793ec7fd90
2026-01-12 19:11:02 -08:00
Tyler Veness
7e1260b003 [wpilib] Replace unit .to<double>() with .value() (#8548)
This is consistent with the rest of the library. I left instances alone
which intended a specific typecast.
2026-01-12 19:10:10 -08:00
Tyler Veness
00fa8361dd [wpimath] Reorganize LinearSystem factories (#8468) 2026-01-12 19:09:35 -08:00
Tyler Veness
89d0759ef2 [wpimath] Remove unused #includes (#8549)
This is based on a filtered list of #includes clangd reported were
unused.
2026-01-12 19:08:21 -08:00
Austin Schuh
1724e59f8d [bazel] Move the easy pieces of the build over to bzlmod (#8542)
bzlmod is the future, and makes it easier to depend on AOS.

---------

Signed-off-by: Austin Schuh <austin.linux@gmail.com>
2026-01-12 15:30:31 -07:00
Tyler Veness
67ae589c11 [wpimath] Replace convolution operator with multiplication in derivations (NFC) (#8557) 2026-01-10 11:44:50 -08:00
PJ Reiniger
8518b7014c [py] Add wpimath/geometry tests (#8460) 2026-01-02 09:10:02 -08:00
PJ Reiniger
40fb9ff562 [copybara] mostrobotpy to allwpilib (#8503)
Resync with `mostrobotpy`

This mostly involves the big "ignore almost everything in the HAL
project" and some fixups for the Addressable LED classes.

Required two small hand fixes to get it building over here with bazel,
and with more compiler warnings on.

I also manually zeroed out the `repo_url` field in the toml files to
avoid unnecessary churn whenever it goes from a release build to a
development build. I already did this with `version` field in there, and
will do a follow up PR that updates the copybara script to do it
automatically.

---------

Co-authored-by: Default email <default@default.com>
2025-12-31 09:06:01 -08:00
Bryce Roethel
ab3af00d07 [wpimath] TrapezoidProfile.State implement StructSerializable (#8499)
Seems like this was missed in #8163
2025-12-21 10:08:32 -06:00
PJ Reiniger
a38499dcd7 [py] Fixup new acceleration classes (#8459)
I tried to sync `mostrobotpy` with `allwpilib` and was getting a
compilation error I had not seen before when it tried to do the stub
generation (which `allwpilib` does not do).

Luckily, I was able to debug it here by writing some unit tests (i.e.,
having Gemini convert the C++ tests into python) that failed in a
similar way. The main problem was needing to write a custom constructor
for the class and adding a `force_type_casters`. I used `ChassisSpeed`
as my main example, but I did not copy all of the other custom code like
overriding the index operator, `__repr__` operator, feet helpers, etc. I
can gladly add those in.

In the future, we should start enforce a policy that if you add a C++ or
Java unit test, you also have to add a python test. That developer might
have gotten more stuck on the minutia of how to fix it, but this problem
would have at least been caught earlier before it landed.
2025-12-17 19:19:12 -08:00
PJ Reiniger
e2c9af862e [py] Fix maven coordinates for native downloads (#8474)
This got missed in the reorg, and these values aren't actually used for
anything when building in `allwpilb`, but we might as well fix them here
to make the copybara process easier.
2025-12-13 21:44:31 -08:00
Benjamin Hall
3dc334c1ee [wpimath] Fix ResetTranslation and ResetRotation in PoseEstimator and PoseEstimator3d causing the robot to teleport (#8285)
Fixes https://github.com/wpilibsuite/allwpilib/issues/8284.

If we have vision updates at the time of the `Reset*` call, we can
correct the translation/rotation of the new odometry pose by adding a
new vision update where:
- `ResetTranslation`: the translation is hard-coded to the new
translation, and the rotation components are set to those of the latest
vision update (prior to clearing the map).
- `ResetRotation`: the rotation is hard-coded to the new rotation, and
the translation components are set to those of the latest vision update
(prior to clearing the map).
2025-12-13 15:53:53 -08:00
Tyler Veness
cca035787c [upstream_utils] Upgrade to Sleipnir 0.3.3 (#8463) 2025-12-12 19:40:43 -08:00
Zach Harel
936be71a7d [wpimath] Add ChassisAccelerations and drivetrain accelerations classes and add forward and inverse kinematics for accelerations to the interface (#8185)
ChassisAccelerations and the drivetrain acceleration types are added in
both Java and C++. `ChassisAccelerations` is basically just
`ChassisSpeeds` but for accelerations!
`DifferentialDriveWheelAccelerations`, `MecanumDriveWheelAccelerations`,
and `SwerveModuleAccelerations` are the acceleration equivalent of the
drivetrain speeds types.

In Java, the `Kinematics` interface now has an additional generic
parameter `A` which represents the accelerations, and
`toChassisAccelerations` and `toWheelAccelerations` methods, which are
implemented the same way as `toChassisSpeeds` and `toWheelSpeeds`.

Protobuf and struct classes were also added for all four classes in Java
and C++.

---------

Signed-off-by: Zach Harel <zach@zharel.me>
Co-authored-by: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com>
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
2025-12-08 17:25:07 -07:00
Peter Johnson
baa6379267 [wpimath] Add usage reporting for state-space classes (#8453)
- LinearQuadraticRegulator
- Kalman filters
- Pose estimators
- LinearSystemLoop

Fixes #2925.
2025-12-06 09:17:02 -08:00
Tyler Veness
08784dc2d1 [upstream_utils] Upgrade to Sleipnir 0.3.2 (#8323)
Also includes a C++ benchmark, which has a Java counterpart in #8236.
2025-12-01 13:51:28 -07:00
Tyler Veness
a79f86ade3 [wpimath] Refactor StateSpaceUtil into separate files (#8421)
* Moved makeWhiteNoiseVector() to random.Normal.normal()
* Moved isControllable() and isDetectable() to system.LinearSystemUtil
* Renamed makeCostMatrix() to costMatrix() (Java)
* Renamed makeCovarianceMatrix() to covarianceMatrix() (Java)
* Renamed MakeCostMatrix() to CostMatrix() (C++)
* Renamed MakeCovMatrix() to CovarianceMatrix() (C++)
* Removed deprecated poseTo3dVector(), poseTo4dVector(), poseToVector()
* Removed clampInputMaxMagnitude()
* We don't use it, and Eigen has this functionality built in via `u =
u.array().min(u_max.array()).max(u_min.array());`
* Simplified implementation of desaturateInputVector()
2025-11-29 10:28:38 -08:00