Using BayesOpt for real-time Bayesian tuning of FRC coefficients with AdvantageKit logs in Java with WPILIB
10:07 12 Nov 2025

This is my first Stack Overflow post, and I’m excited to get some guidance from the community!


I’m working on a FIRST Robotics Competition (FRC) robot using Java and WPILib, and I want to implement real-time Bayesian optimization to automatically tune the coefficients in our FiringSolutionSolver.java during operation.


Current Setup

FiringSolutionSolver.java computes projectile firing solutions for a turreted shooter.

It uses LoggedTunableNumbers (via AdvantageKit) for tunable constants such as:

  • drag coefficient

  • projectile mass

  • projectile area

  • launch height

  • target height

  • max exit velocity

  • iterative solver parameters

Other details:

  • Shot results (hit/miss) are logged in AdvantageKit in real-time via operator input buttons.

  • Vision system (PhotonVision) provides target distance and height; these are not** part of the optimization**.

  • The projectile is a 4-inch foam ball (3.5 inches when compressed).


Goal

I want a BOT tuner (Bayesian Optimization Tuner) that does the following:

  1. Adjusts all solver coefficients (LoggedTunableNumbers) in real-time as each new shot is fired and logged.

  2. Uses AdvantageKit hit/miss logs to inform the optimization loop.

    Advantagekit logs but with a method of pressing a button on the dashboard to record a hit or a miss after each shot. Intended to be implemented later.

  3. Updates coefficients instantaneously — no waiting between shots.

  4. Runs entirely in Java — Python or external services are not an option due to roboRIO runtime constraints.

  5. Is lightweight and efficient enough for real-time computation on the robot.


Constraints / Considerations

  • I understand Bayesian optimization conceptually to a high degree (Gaussian process surrogate, acquisition function, sequential updates), but I’ve never implemented it in code. However, I am a quick learner, and I ask you to not take knowledge barrier into account when recommending options or solutions.

  • I don’t need to tune physical ball properties or vision measurements (distance to target across axes); only solver constants.

  • Approximations are acceptable if a full incremental Bayesian optimizer in Java is infeasible.

  • This must integrate directly into the robot codebase for live updates.


Questions

  1. Are there pure Java libraries capable of online/incremental Bayesian optimization suitable for an FRC robot environment? I'm thinking of BayesOpt, but I have concerns/questions regarding its implementation.

  2. If not, what’s the best approach to implement a lightweight surrogate-based or incremental Bayesian tuner for LoggedTunableNumbers in Java?

  3. How should I structure the code for real-time coefficient updates using AdvantageKit shot logs without impacting other robot subsystems?

  4. Are there best practices for embedding a Bayesian optimizer in Java robot code so updates happen safely and efficiently in real-time?

    Note: only update after each shot with the new data that shot gives, that way updates do not happen mid shot. Hence the need for the fast update time.


Why this is challenging

  • We need sub-second updates after each shot.

  • All computations must happen on the roboRIO; no offloading to Python or external servers.

  • We want this to be robust and safe to run during practice sessions.

  • The number of coefficients to tune is ~8–10, and their interactions can be nonlinear.


Any guidance, Java libraries, code patterns, or examples for real-time Bayesian tuning in Java for FRC would be extremely helpful.

Thanks in advance!

java optimization real-time bayesian coefficients