SysIdRoutine

class commands2.sysid.SysIdRoutine(config: Config, mechanism: Mechanism)[source]

Bases: SysIdRoutineLog

A SysId characterization routine for a single mechanism. Mechanisms may have multiple motors.

A single subsystem may have multiple mechanisms, but mechanisms should not share test routines. Each complete test of a mechanism should have its own SysIdRoutine instance, since the log name of the recorded data is determined by the mechanism name.

The test state (e.g. “quasistatic-forward”) is logged once per iteration during test execution, and once with state “none” when a test ends. Motor frames are logged every iteration during test execution.

Timestamps are not coordinated across data, so motor frames and test state tags may be recorded on different log frames. Because frame alignment is not guaranteed, SysId parses the log by using the test state flag to determine the timestamp range for each section of the test, and then extracts the motor frames within the valid timestamp ranges. If a given test was run multiple times in a single logfile, the user will need to select which of the tests to use for the fit in the analysis tool.

Create a new SysId characterization routine.

Parameters:
  • config – Hardware-independent parameters for the SysId routine.

  • mechanism – Hardware interface for the SysId routine.

class Config(rampRate: float = 1.0, stepVoltage: float = 7.0, timeout: float = 10.0, recordState: Callable[[State], None] | None = None)[source]

Bases: object

Hardware-independent configuration for a SysId test routine.

Parameters:
  • rampRate – The voltage ramp rate used for quasistatic test routines. Defaults to 1 volt per second if left null.

  • stepVoltage – The step voltage output used for dynamic test routines. Defaults to 7 volts if left null.

  • timeout – Safety timeout for the test routine commands. Defaults to 10 seconds if left null.

  • recordState – Optional handle for recording test state in a third-party logging solution. If provided, the test routine state will be passed to this callback instead of logged in WPILog.

rampRate: float = 1.0
recordState: Callable[[State], None] | None = None
stepVoltage: float = 7.0
timeout: float = 10.0
class Direction(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Motor direction for a SysId test.

kForward = 1
kReverse = -1
class Mechanism(drive: Callable[[float], None], log: Callable[[SysIdRoutineLog], None], subsystem: Subsystem, name: str = None)[source]

Bases: object

A mechanism to be characterized by a SysId routine.

Defines callbacks needed for the SysId test routine to control and record data from the mechanism.

Parameters:
  • drive – Sends the SysId-specified drive signal to the mechanism motors during test routines.

  • log – Returns measured data of the mechanism motors during test routines. To return data, call motor(string motorName) on the supplied SysIdRoutineLog instance, and then call one or more of the chainable logging handles (e.g. voltage) on the returned MotorLog. Multiple motors can be logged in a single callback by calling motor multiple times.

  • subsystem – The subsystem containing the motor(s) that is (or are) being characterized. Will be declared as a requirement for the returned test commands.

  • name – The name of the mechanism being tested. Will be appended to the log entry title for the routine’s test state, e.g. “sysid-test-state-mechanism”. Defaults to the name of the subsystem if left null.

drive: Callable[[float], None]
log: Callable[[SysIdRoutineLog], None]
name: str = None
subsystem: Subsystem
dynamic(direction: Direction) Command[source]

Returns a command to run a dynamic test in the specified direction.

The command will call the drive and log callbacks supplied at routine construction once per iteration. Upon command end or interruption, the drive callback is called with a value of 0 volts.

Parameters:

direction – The direction in which to run the test.

Returns:

A command to run the test.

quasistatic(direction: Direction) Command[source]

Returns a command to run a quasistatic test in the specified direction.

The command will call the drive and log callbacks supplied at routine construction once per iteration. Upon command end or interruption, the drive callback is called with a value of 0 volts.

Parameters:

direction – The direction in which to run the test.

Returns:

A command to run the test.