Tuning
The Tune opmode measures the robot on the field and suggests settings, from the Driver Station or a laptop, and pullConfig keeps what it found.
The Tune opmode
Parts of the robot offer tunings: procedures that measure the part on the real robot and suggest settings. The drivetrain checks its wheels, the path follower measures how fast the robot drives forward, sideways and around, and a flywheel finds the gains of the hub’s speed control. One opmode lists them all, for whatever parts the robot has:
@TeleOp(name = "Tune")
class Tune : TuningOpMode(::MyRobot) // or TuningOpMode(MyRobots), a RobotChoice
After START, gamepad 1 picks a tuning on the Driver Station:
| Key | Does |
|---|---|
| dpad up, down | choose a tuning, by part; in a tuning, choose one of its settings |
| A | open the tuning: what it needs, like room to drive, and its settings; A again runs it |
| dpad left, right | change the chosen setting, to one of the values it offers |
| B | stop a running tuning; go back |
| X | when a tuning ends: apply the settings it suggests |
| Y | show a tuning’s last results |
When nothing runs, the sticks drive the robot, so it can go back to where there is room without another opmode. Pushed far, they stop a tuning that drives, like any action.
The graphs page has the same: a button for each tuning and stop
tuning, the graphs a tuning draws while it runs, and the results of each, with an Apply button. Scripts start
tunings as commands, robotCommand --name="follower: characterize forward", read the results from
/bear/graphs/data, and apply them with POST /bear/tuning/apply?name=follower: characterize forward.
Keeping what it found
Applied settings, and settings changed on the Driver Station, take effect right away and stay on the robot like edits
on the settings page: until the next install, which starts from the project’s config.properties again. To keep them,
bring the robot’s config into the project and commit it:
./gradlew :TeamCode:pullConfig
It writes the robot’s config into TeamCode/src/main/res/raw/config.properties and lists the settings that changed. A
setting goes where its value came from: into the robot’s own section when the config has one for it (see
Settings), so the team’s other robots keep theirs.
What the platform’s parts offer
| Tuning | Measures | Suggests |
|---|---|---|
drive: check wheels |
spins each wheel for a second, as drive.checkWheels() does: each should push the robot forward |
|
follower: characterize forward, strafe, turn |
the power that starts the robot moving, the speed it holds at 0.3, 0.6 and full power, its acceleration, and how far it takes to stop | follower.frictionPower, frictionStrafePower, frictionTurnPower |
follower: test moves |
how long the follower takes for a move forward, to the right, a quarter turn and a diagonal, each and back, how far it overshoots, and how close it ends | |
<flywheel>: find gains |
the power that holds <flywheel>.tuning.speed, and how quickly and steadily a few p get the wheel there |
<flywheel>.hubVelocityGains |
Characterizing the drive
Each characterization drives along one way the robot moves, like WPILib’s SysId. First the power rises slowly, forward and back, until the robot moves: that is the friction power the follower adds. The two often differ, on a floor that slopes or with a drive that pulls one way, and it suggests their average, as the follower needs it both ways. Then steps of power, 0.3, 0.6 and full, each one way and back, so the robot ends about where it started: each step runs until the speed holds, and measures the speed, how quickly it got there, and how far the robot went once the power was off.
It needs the room it says, follower.tuning.room (200 cm) ahead, or to the right, and 30 cm behind, and stops before
it runs out, even if the speed is still rising: then the top speed comes from the slower steps. A localizer has to be
working, as everything is measured with it. With drive.nominalVoltage set, the speeds don’t depend on the battery.
A drive on power alone wanders off to a side, so small corrections keep the robot on the line it started on, and on
its heading: holding its line says how much it took, and a lot means a wheel or a side is off. If it goes 25 cm off
the line or 30° off its heading anyway, slows down suddenly with the power on, or doesn’t move at all, it hit
something: it stops there, and the result says where. characterize turn ends facing where it started.
Forward and sideways are measured apart because a mecanum drive moves differently on each: compare the speed per power
and the acceleration of characterize forward and characterize strafe. A drive with velocity control needs little
friction power, if any.
Test moves
test moves drives the follower through moves its gains have to handle, follower.tuning.moveDistance (60 cm) long,
from where the robot is: it needs that much room plus the robot’s own size ahead and to the right, and in the corner
between, where the diagonal goes. A move that stalls stops them all, as the robot likely hit something. Change the
gains on the settings page, run it again, and compare: the time, the overshoot, and how close each move ended. The graphs show each move, as in tuning the follower.
Finding a flywheel’s gains
find gains does what holding a speed describes
by hand, at <flywheel>.tuning.speed (3000 rpm), about where the wheel shoots. It finds the power that holds that
speed, which gives f. Then it tries p from 2 to 15 times f: for each, the wheel settles at half the speed, then the
speed goes up, and it measures when the wheel was ready to stay, how far it overshot, and how much it wobbled after.
It suggests the p that got the wheel ready soonest without wobbling, the largest of those about as quick, with no i or
d. The wheel needs to be free to spin, with nothing in it. A wheel with several motors has them all spin alike at the
same power: when one spins much faster, it isn’t connected to the wheel, or its belt slips, and it stops saying which.
Offering tunings of your own
A part offers a tuning in its constructor. It runs like any action: it takes over what it drives, stops it at the end,
shows its progress with show() and graph(), and reports what it measured and the settings it suggests.
class Lift(parent: Component) : Component(parent) {
val motor = Motor(this, "lift", ticksPerTurn = 384.5)
val holdPower by config(0.1)
init {
tuning("find hold power", needs = { "the lift free to go up" }) {
val power = takeOver("find hold power") {
try {
findHoldPower() // raises the power until the lift stops sagging
} finally {
motor.power = 0.0
}
}
measured("holds at", "power $power")
suggest("$configScope.holdPower", power)
}
}
}
suggest() takes a setting’s key and a value of its type, written the way config writes it. A tuning’s own settings,
like how far it may go, are config settings too; pass them with settings = listOf(tuningSetting("tuning.height",
"30cm", "60cm")) to let the Driver Station change them before it runs. A tuning that throws doesn’t stop the opmode:
its result says what went wrong.