LinearSystemLoop_2_1_1

class wpimath.system.LinearSystemLoop_2_1_1(*args, **kwargs)

Bases: pybind11_object

Combines a controller, feedforward, and observer for controlling a mechanism with full state feedback.

For everything in this file, “inputs” and “outputs” are defined from the perspective of the plant. This means U is an input and Y is an output (because you give the plant U (powers) and it gives you back a Y (sensor values). This is the opposite of what they mean from the perspective of the controller (U is an output because that’s what goes to the motors and Y is an input because that’s what comes back from the sensors).

For more on the underlying math, read https://file.tavsys.net/control/controls-engineering-in-frc.pdf.

@tparam States Number of states. @tparam Inputs Number of inputs. @tparam Outputs Number of outputs.

Overloaded function.

  1. __init__(self: wpimath._controls._controls.system.LinearSystemLoop_2_1_1, plant: wpimath._controls._controls.system.LinearSystem_2_1_1, controller: wpimath._controls._controls.controller.LinearQuadraticRegulator_2_1, observer: wpimath._controls._controls.estimator.KalmanFilter_2_1_1, maxVoltage: volts, dt: seconds) -> None

Constructs a state-space loop with the given plant, controller, and observer. By default, the initial reference is all zeros. Users should call reset with the initial system state before enabling the loop. This constructor assumes that the input(s) to this system are voltage.

Parameters:
  • plant – State-space plant.

  • controller – State-space controller.

  • observer – State-space observer.

  • maxVoltage – The maximum voltage that can be applied. Commonly 12.

  • dt – The nominal timestep.

  1. __init__(self: wpimath._controls._controls.system.LinearSystemLoop_2_1_1, plant: wpimath._controls._controls.system.LinearSystem_2_1_1, controller: wpimath._controls._controls.controller.LinearQuadraticRegulator_2_1, observer: wpimath._controls._controls.estimator.KalmanFilter_2_1_1, clampFunction: Callable[[numpy.ndarray[numpy.float64[1, 1]]], numpy.ndarray[numpy.float64[1, 1]]], dt: seconds) -> None

Constructs a state-space loop with the given plant, controller, and observer. By default, the initial reference is all zeros. Users should call reset with the initial system state before enabling the loop. This constructor assumes that the input(s) to this system are voltage.

Parameters:
  • plant – State-space plant.

  • controller – State-space controller.

  • observer – State-space observer.

  • clampFunction – The function used to clamp the input vector.

  • dt – The nominal timestep.

  1. __init__(self: wpimath._controls._controls.system.LinearSystemLoop_2_1_1, controller: wpimath._controls._controls.controller.LinearQuadraticRegulator_2_1, feedforward: wpimath._controls._controls.controller.LinearPlantInversionFeedforward_2_1, observer: wpimath._controls._controls.estimator.KalmanFilter_2_1_1, maxVoltage: volts) -> None

Constructs a state-space loop with the given controller, feedforward and observer. By default, the initial reference is all zeros. Users should call reset with the initial system state.

Parameters:
  • controller – State-space controller.

  • feedforward – Plant inversion feedforward.

  • observer – State-space observer.

  • maxVoltage – The maximum voltage that can be applied. Assumes that the inputs are voltages.

  1. __init__(self: wpimath._controls._controls.system.LinearSystemLoop_2_1_1, controller: wpimath._controls._controls.controller.LinearQuadraticRegulator_2_1, feedforward: wpimath._controls._controls.controller.LinearPlantInversionFeedforward_2_1, observer: wpimath._controls._controls.estimator.KalmanFilter_2_1_1, clampFunction: Callable[[numpy.ndarray[numpy.float64[1, 1]]], numpy.ndarray[numpy.float64[1, 1]]]) -> None

Constructs a state-space loop with the given controller, feedforward, observer and clamp function. By default, the initial reference is all zeros. Users should call reset with the initial system state.

Parameters:
  • controller – State-space controller.

  • feedforward – Plant-inversion feedforward.

  • observer – State-space observer.

  • clampFunction – The function used to clamp the input vector.

U(*args, **kwargs)

Overloaded function.

  1. U(self: wpimath._controls._controls.system.LinearSystemLoop_2_1_1) -> numpy.ndarray[numpy.float64[1, 1]]

Returns the controller’s calculated control input u.

  1. U(self: wpimath._controls._controls.system.LinearSystemLoop_2_1_1, i: int) -> float

Returns an element of the controller’s calculated control input u.

Parameters:

i – Row of u.

clampInput(u: numpy.ndarray[numpy.float64[1, 1]]) numpy.ndarray[numpy.float64[1, 1]]

Clamps input vector between system’s minimum and maximum allowable input.

Parameters:

u – Input vector to clamp.

Returns:

Clamped input vector.

correct(y: numpy.ndarray[numpy.float64[1, 1]]) None

Correct the state estimate x-hat using the measurements in y.

Parameters:

y – Measurement vector.

error() numpy.ndarray[numpy.float64[2, 1]]

Returns difference between reference r and current state x-hat.

nextR(*args, **kwargs)

Overloaded function.

  1. nextR(self: wpimath._controls._controls.system.LinearSystemLoop_2_1_1) -> numpy.ndarray[numpy.float64[2, 1]]

Returns the controller’s next reference r.

  1. nextR(self: wpimath._controls._controls.system.LinearSystemLoop_2_1_1, i: int) -> float

Returns an element of the controller’s next reference r.

Parameters:

i – Row of r.

predict(dt: seconds) None

Sets new controller output, projects model forward, and runs observer prediction.

After calling this, the user should send the elements of u to the actuators.

Parameters:

dt – Timestep for model update.

reset(initialState: numpy.ndarray[numpy.float64[2, 1]]) None

Zeroes reference r and controller output u. The previous reference of the PlantInversionFeedforward and the initial state estimate of the KalmanFilter are set to the initial state provided.

Parameters:

initialState – The initial state.

setNextR(nextR: numpy.ndarray[numpy.float64[2, 1]]) None

Set the next reference r.

Parameters:

nextR – Next reference.

setXhat(*args, **kwargs)

Overloaded function.

  1. setXhat(self: wpimath._controls._controls.system.LinearSystemLoop_2_1_1, xHat: numpy.ndarray[numpy.float64[2, 1]]) -> None

Set the initial state estimate x-hat.

Parameters:

xHat – The initial state estimate x-hat.

  1. setXhat(self: wpimath._controls._controls.system.LinearSystemLoop_2_1_1, i: int, value: float) -> None

Set an element of the initial state estimate x-hat.

Parameters:
  • i – Row of x-hat.

  • value – Value for element of x-hat.

xhat(*args, **kwargs)

Overloaded function.

  1. xhat(self: wpimath._controls._controls.system.LinearSystemLoop_2_1_1) -> numpy.ndarray[numpy.float64[2, 1]]

Returns the observer’s state estimate x-hat.

  1. xhat(self: wpimath._controls._controls.system.LinearSystemLoop_2_1_1, i: int) -> float

Returns an element of the observer’s state estimate x-hat.

Parameters:

i – Row of x-hat.