Skip to main content

Constants

Tuning constants in mikLib

Constants struct

A single global instance, constants, stores the defaults applied to every motion. Set these once at startup (or via the Chassis setters).

Drive constants

Used while driving. Heading constants keep the robot facing the target while it drives.

FieldDescription
drive_min_voltageMinimum voltage on the drive, used for chaining movements.
drive_max_voltageMax voltage out of 12.
drive_kp / drive_ki / drive_kdProportional / integral / derivative constants.
drive_startiMinimum distance (inches) for integral to begin.
drive_slewLimits drive acceleration in volts per 10 ms.
drive_exit_errorError (inches) at which the drive motion exits.
drive_settle_errorError (inches) to be considered settled.
drive_settle_timeTime (ms) to be considered settled.
drive_timeoutTime (ms) before quitting and moving on.
heading_max_voltageMax heading-correction voltage out of 12.
heading_kp / heading_ki / heading_kdHeading PID constants.
heading_startiMinimum distance (degrees) for integral to begin.
heading_slewLimits heading-correction acceleration in volts per 10 ms.

Turn constants

FieldDescription
turn_min_voltageMinimum voltage for turning out of 12.
turn_max_voltageMax voltage out of 12.
turn_kp / turn_ki / turn_kdTurn PID constants.
turn_startiMinimum angle (degrees) for integral to begin.
turn_slewLimits turning acceleration in volts per 10 ms.
turn_exit_errorError at which the turn motion exits.
turn_settle_errorError (degrees) to be considered settled.
turn_settle_timeTime (ms) to be considered settled.
turn_timeoutTime (ms) before quitting and moving on.

Swing constants

Swinging turns the robot using one side of the drivetrain.

FieldDescription
swing_min_voltageMinimum voltage for swinging out of 12.
swing_opposite_voltageVoltage on the opposite (non-swung) side out of 12.
swing_max_voltageMax voltage out of 12.
swing_kp / swing_ki / swing_kdSwing PID constants.
swing_startiMinimum distance (degrees) for integral to begin.
swing_slewLimits swinging acceleration in volts per 10 ms.
swing_exit_errorError at which the swing motion exits.
swing_settle_errorError (degrees) to be considered settled.
swing_settle_timeTime (ms) to be considered settled.
swing_timeoutTime (ms) before quitting and moving on.

Boomerang, control, and slew cutoffs

FieldDescription
boomerang_leadScale factor for how far away the carrot point is.
boomerang_driftLower values give slower speeds while turning. Use higher (~8) for traction drives.
control_throttle_deadbandDeadband percent for the throttle axis.
control_throttle_min_outputMinimum throttle output percent after deadband.
control_throttle_curve_gainExpo gain for throttle (1 linear, 1.06 very curvy).
control_turn_deadbandDeadband percent for the turn axis.
control_turn_min_outputMinimum turn output percent after deadband.
control_turn_curve_gainExpo gain for the turn axis.
control_desaturate_biasDesaturation bias for split_arcade_curved (0 = prioritize turn, 1 = prioritize throttle).
turn_cutoffDegrees within which slew stops being applied.
drive_cutoffInches within which slew stops and heading correction stops.

PID structs

Each motion's k (or drive_k / heading_k) field takes one of these. Their fields default to the matching values in constants, so you only override what you need:

// Sets the only the drive PID kP
drive_constants k = { .p = 2.0 };
struct drive_constants   { float p, i, d, starti, slew; };
struct heading_constants { float p, i, d, starti, slew; };
struct turn_constants { float p, i, d, starti, slew; };
struct swing_constants { float p, i, d, starti, slew; };
FieldDescription
pProportional constant.
iIntegral constant.
dDerivative constant.
startiMinimum error for the integral term to begin.
slewLimits acceleration in volts per 10 ms.

Motion parameter structs

Every Chassis motion takes an optional params struct as its last argument. All fields default to the global constants, so you override only what you need with designated initializers:

chassis.turn_to_angle(90, {.max_voltage = 6, .direction = mik::turn_direction::cw});

turn_to_angle_params / turn_to_point_params

FieldDescription
directionThe way the robot should turn (ccw, cw, or shortest path).
angle_offset(point only) Angle turned past the desired heading, in degrees.
min_voltageMinimum voltage on the drive, used for chaining movements.
max_voltageMax voltage on the drive out of 12.
exit_errorDistance from target (degrees) within which the motion exits.
settle_errorError (degrees) to be considered settled.
settle_timeTime (ms) to be considered settled.
timeoutTime (ms) before quitting and moving on.
waitYields the program until the motion finishes (default true).
kA turn_constants override.

swing_to_angle_params / swing_to_point_params

Same as the turn params above, plus:

FieldDescription
opposite_voltageVoltage on the opposite side of the drivetrain out of 12.
kA swing_constants override.

drive_distance_params / strafe_distance_params

FieldDescription
headingDesired heading in degrees. Defaults to the current heading.
min_voltageMinimum voltage on the drive, used for chaining movements.
max_voltageMax voltage on the drive out of 12.
heading_max_voltageMax voltage for getting to heading out of 12.
exit_errorDistance from target (inches) within which the motion exits.
settle_errorError (inches) to be considered settled.
settle_timeTime (ms) to be considered settled.
timeoutTime (ms) before quitting and moving on.
waitYields the program until the motion finishes (default true).
drive_k / heading_kdrive_constants / heading_constants overrides.

drive_to_point_params / drive_to_pose_params

The drive params above, plus:

FieldDescription
directionForce a forward or reverse approach. Defaults to choosing automatically.
lead(pose only) Scale factor for how far away the carrot point is.
drift(pose only) Limits speed while turning; higher values increase lateral speed out of 10.

holonomic_to_pose_params

The drive params above, plus separate turn settling:

FieldDescription
turn_settle_errorTurn error (degrees) to be considered settled.
turn_settle_timeTurn time (ms) to be considered settled.