Skip to content
Tempo on GitHub (opens in a new tab)

3.22 Live tuning

Some config settings take a supplier (a function that returns the current value) in place of a number, and Tempo uses a new value without a redeploy. PID gains change on the running route and everything else changes on the next route Tempo builds. The settings are listed under What takes a supplier.

NetworkTables example

This example tunes the follower’s two proportional gains and the robot’s top path speed from NetworkTables entries under /Tempo/Tuning/.

Java
import com.tempo.config.LimitsConfigs;
import com.tempo.config.TempoConfig;
import edu.wpi.first.networktables.DoubleEntry;
import edu.wpi.first.networktables.NetworkTableInstance;

// Fields.
private final DoubleEntry translationKp = tunable("/Tempo/Tuning/TranslationKp", 8.0);
private final DoubleEntry rotationKp = tunable("/Tempo/Tuning/RotationKp", 6.0);
private final DoubleEntry maxSpeed = tunable("/Tempo/Tuning/MaxSpeed", 4.0);   // m/s

private static DoubleEntry tunable(String key, double initial) {
    DoubleEntry entry = NetworkTableInstance.getDefault().getDoubleTopic(key).getEntry(initial);
    entry.set(initial);   // publish the starting value
    return entry;
}

// Runs once at startup, in place of the fixed-value config.
TempoConfig config = new TempoConfig()
    // ... the rest of the config
    .withPID(translationKp::get, rotationKp::get)
    .withLimits(new LimitsConfigs().maxVelocity(maxSpeed::get));
Python
from ntcore import NetworkTableInstance
from tempo import LimitsConfigs, TempoConfig


def tunable(key: str, initial: float):
    entry = NetworkTableInstance.getDefault().getDoubleTopic(key).getEntry(initial)
    entry.set(initial)  # publish the starting value
    return entry


def robotInit(self):
    # Runs once at startup, in place of the fixed-value config.
    self.translation_kp = tunable("/Tempo/Tuning/TranslationKp", 8.0)
    self.rotation_kp = tunable("/Tempo/Tuning/RotationKp", 6.0)
    self.max_speed = tunable("/Tempo/Tuning/MaxSpeed", 4.0)  # m/s

    config = (TempoConfig()
        # ... the rest of the config
        .with_pid(self.translation_kp.get, self.rotation_kp.get)
        .with_limits(LimitsConfigs().max_velocity(self.max_speed.get)))
C++
#include <networktables/DoubleTopic.h>
#include <networktables/NetworkTableInstance.h>
#include <tempo/Tempo.h>

// Members, so they outlive the config.
static nt::DoubleEntry Tunable(std::string_view key, double initial) {
    auto entry = nt::NetworkTableInstance::GetDefault().GetDoubleTopic(key).GetEntry(initial);
    entry.Set(initial);  // publish the starting value
    return entry;
}
nt::DoubleEntry translationKp = Tunable("/Tempo/Tuning/TranslationKp", 8.0);
nt::DoubleEntry rotationKp = Tunable("/Tempo/Tuning/RotationKp", 6.0);
nt::DoubleEntry maxSpeed = Tunable("/Tempo/Tuning/MaxSpeed", 4.0);  // m/s

// Runs once at startup, in place of the fixed-value config.
auto config = tempo::TempoConfig{}
    // ... the rest of the config
    .with_pid([this] { return translationKp.Get(); },
              [this] { return rotationKp.Get(); })
    .with_limits(tempo::LimitsConfigs{}.max_velocity([this] { return maxSpeed.Get(); }));

The three entries show up under /Tempo/Tuning in a dashboard such as Elastic or AdvantageScope. The entries have to last as long as the robot program, so keep them in fields. The gains start at 8.0 and 6.0 because those are the values Tempo uses when the config has no withPID.

A mecanum config also needs maxAcceleration in the same LimitsConfigs.

Any DoubleSupplier that returns a plain SI number works. A LoggedTunableNumber goes in directly, like .maxVelocity(kMaxV), and a WPILib DoubleEntry goes in as entry::get. For another unit, convert it in a lambda: () -> Units.feetToMeters(kMaxV.get()). withTunablePID takes two suppliers of PIDConstants, for tunable kP, kI and kD.

Python takes any callable that returns a float in SI units, so a bound method like self.max_speed.get works. with_tunable_pid takes two callables that return PIDConstants, for tunable kP, kI and kD.

C++ takes any callable that returns a number in SI units. with_tunable_pid takes two std::function<PidConstants()>, for tunable kP, kI and kD.

What takes a supplier

WhereTunable settings
TempoConfigwithPID (a kP supplier each), withTunablePID, withTolerance, withLag, withObstacleMargin
ModuleConfigscof, topSpeed, statorCurrentLimit, supplyCurrentLimit
LimitsConfigsmaxVelocity, maxAcceleration, maxCentripetal, maxAngularVelocity, maxAngularAcceleration
ReplanningConfigsdrift, rate, blend
TerrainConfigsdefaultCap, cap

A preset’s arguments stay numbers or units, so a tunable current limit goes on the module, like .statorCurrentLimit(kStator). Mass, frame, bumpers, module offsets, wheel radius, gear ratio, measured limits and PlanningConfigs aren’t tunable.

Python and C++ use the snake_case names, such as max_velocity and with_obstacle_margin. C++ spells the gains type PidConstants.

When a new value is used

A new gain is used on the running route within 200 ms. Once a live gain changes, it replaces a leg’s own gains(...) for the rest of that run.

Every other new value is used on the next route Tempo builds, and a route that’s already running keeps its plan and its arrival tolerance. A leg written with speed(...), or with no speed, uses the new limit. A leg with its own limits(...) keeps its numbers, lowered to the new robot limit where one of them is above it.

While the robot is disabled, a changed value other than a gain replans the selected auto once the value has stayed the same for about 400 ms. If the auto is enabled before that, it can be planned again as it starts, and the console prints a [Tempo] line saying so. A route start never waits for a rebuild, so a value changed right before enable can reach the next route instead.

A bad value, such as a negative tolerance, keeps that setting’s last good value and the other settings still apply. The console prints one [Tempo] live config value ignored: line with the setting and the reason. If values are only refused together, the whole config stays as it was and the console prints the reason.

AdvantageKit example

A project’s own LoggedTunableNumber class goes in directly, and so does AdvantageKit’s LoggedNetworkNumber. You don’t need to call hasChanged(...) because Tempo compares each value with the last one it read.

Java
import com.tempo.PIDConstants;
import com.tempo.config.LimitsConfigs;
import com.tempo.config.TempoConfig;
import frc.robot.util.LoggedTunableNumber;

private static final LoggedTunableNumber kP = new LoggedTunableNumber("Path/kP", 8.0);
private static final LoggedTunableNumber kD = new LoggedTunableNumber("Path/kD", 0.0);
private static final LoggedTunableNumber rotationKp =
    new LoggedTunableNumber("Path/RotationKp", 6.0);
private static final LoggedTunableNumber kMaxV =
    new LoggedTunableNumber("Path/MaxSpeed", 4.0);   // m/s

TempoConfig config = new TempoConfig()
    // ... the rest of the config
    .withTunablePID(
        () -> new PIDConstants(kP.get(), kD.get()),      // kP and kD, no I
        () -> new PIDConstants(rotationKp.get()))
    .withLimits(new LimitsConfigs().maxVelocity(kMaxV));

The tuning process is in Tune path following.

If it fails…

A new value is ignored Above → [Tempo] live config value ignored: {reason}

The value failed validation, such as a negative tolerance, and the previous value is kept. The rest of the line gives the reason.

A new speed limit doesn't change the running route Above →

Limits, tolerances and margins are used on the next route Tempo builds. A leg with its own limits(...) keeps its numbers, lowered to the new robot limit where one of them is above it.

esc

Loading search...