multirotor.controller.pid

Module Contents

Classes

PIDController

Proportional Integral Derivative controller. Tracks a reference signal and outputs

PosController

Position controller. Convert xy-waypoint into required xy-velocity in the body-frame.

VelController

Velocity controller. Takes reference x/y body-frame velocity and outputs reference

AttController

Attitude controller. Convert velocity reference into angular rate control

RateController

Attitude rate controller. Tracks reference roll, pitch, yaw rates and outputs

AltController

Altitude Controller. Tracks z-position and outputs velocity.

AltRateController

Climb rate controller. Tracks z-velocity and outputs thrust force needed.

Controller

The cascaded PID controller. Tracks position and yaw, and outputs thrust and

Functions

sqrt_control(err, k_p, derr_dt2_lim, dt)

multirotor.controller.pid.sqrt_control(err: float, k_p: float, derr_dt2_lim: float, dt: float)
class multirotor.controller.pid.PIDController

Proportional Integral Derivative controller. Tracks a reference signal and outputs a control signal to minimize output. The equation is:

err = reference - measurement

u = k_p * err + k_d * d(err)/dt + k_i * int(err . dt)

Can control a single or an array of signals, given float or array PID constants.

property state: numpy.ndarray
k_p: numpy.ndarray

Proportional constant

k_i: numpy.ndarray

Integral constant

k_d: numpy.ndarray

Derivative constant

max_err_i: numpy.ndarray

Maximum accumulated error

__post_init__()
reset()
set_params(**params: Dict[str, numpy.ndarray | bool | float | int])
get_params() Dict[str, numpy.ndarray]
step(reference: numpy.ndarray, measurement: numpy.ndarray, dt: float = 1.0, ref_is_error: bool = False, persist: bool = True) numpy.ndarray

Calculate the output, based on the current measurement and the reference signal.

Parameters

referencenp.ndarray

The reference signal(s) to track. Can be a number or an array.

measurementnp.ndarray

The actual measurement(s).

ref_is_error: bool

Whether to interpret the reference input as the error.

persist: bool

Whether to store the current state for the next step.

Returns

np.ndarray

The action signal.

class multirotor.controller.pid.PosController

Bases: PIDController

Position controller. Convert xy-waypoint into required xy-velocity in the body-frame.

property leash: float
vehicle: multirotor.simulation.Multirotor
max_velocity: float = 7.0

Maximum velocity in m/s

max_acceleration: float = 3.0

Maximum acceleration in m/s/s

max_jerk: float = 100.0

Maximum jerk in m/s/s/s

square_root_scaling: bool = True

Whether to scale P-gain with the square root of the error

leashing: bool = True

Whether to limit proportional position error

__post_init__()
step(reference, measurement, dt, persist: bool = True)

Calculate the output, based on the current measurement and the reference signal.

Parameters

referencenp.ndarray

The reference signal(s) to track. Can be a number or an array.

measurementnp.ndarray

The actual measurement(s).

ref_is_error: bool

Whether to interpret the reference input as the error.

persist: bool

Whether to store the current state for the next step.

Returns

np.ndarray

The action signal.

class multirotor.controller.pid.VelController

Bases: PIDController

Velocity controller. Takes reference x/y body-frame velocity and outputs reference pitch and roll angles for x and y motion, respectively.

Compares against measured velocity. The deficit is used to change pitch and roll angles to increase and decrease velocity.

Able to limit tilt angles when tracking reference waypoints.

vehicle: multirotor.simulation.Multirotor
max_tilt: float

Maximum tilt angle in radians

__post_init__()
step(reference, measurement, dt, persist: bool = True)

Calculate the output, based on the current measurement and the reference signal.

Parameters

referencenp.ndarray

The reference signal(s) to track. Can be a number or an array.

measurementnp.ndarray

The actual measurement(s).

ref_is_error: bool

Whether to interpret the reference input as the error.

persist: bool

Whether to store the current state for the next step.

Returns

np.ndarray

The action signal.

class multirotor.controller.pid.AttController

Bases: PIDController

Attitude controller. Convert velocity reference into angular rate control signal.

vehicle: multirotor.simulation.Multirotor
max_acceleration: float = 0.2

Maximum acceleration in rad/s/s

max_jerk: float = 100.0

Maximum jerk in rad/s/s/s

square_root_scaling: bool = False

Whether to scale P-gain with the square root of the error

__post_init__()
step(reference, measurement, dt, persist: bool = True)

Calculate the output, based on the current measurement and the reference signal.

Parameters

referencenp.ndarray

The reference signal(s) to track. Can be a number or an array.

measurementnp.ndarray

The actual measurement(s).

ref_is_error: bool

Whether to interpret the reference input as the error.

persist: bool

Whether to store the current state for the next step.

Returns

np.ndarray

The action signal.

class multirotor.controller.pid.RateController

Bases: PIDController

Attitude rate controller. Tracks reference roll, pitch, yaw rates and outputs the necessary moments about each x,y,z axes to achieve them.

Uses change in orientation from measured to reference as approximate reference angular rate. Compares against measured angular rate. Outputs required change in angular rate (angular acceleration) as moments.

vehicle: multirotor.simulation.Multirotor
max_acceleration: float = 0.2

Maximum acceleration in rad/s/s

__post_init__()
step(reference, measurement, dt, persist: bool = True)

Calculate the output, based on the current measurement and the reference signal.

Parameters

referencenp.ndarray

The reference signal(s) to track. Can be a number or an array.

measurementnp.ndarray

The actual measurement(s).

ref_is_error: bool

Whether to interpret the reference input as the error.

persist: bool

Whether to store the current state for the next step.

Returns

np.ndarray

The action signal.

class multirotor.controller.pid.AltController

Bases: PIDController

Altitude Controller. Tracks z-position and outputs velocity.

Uses change in z-position as approximate vertical velocity. Compares against measured velocity. Outputs the change in velocity (acceleration) as thrust force, given orientation of vehicle.

vehicle: multirotor.simulation.Multirotor
max_velocity: float = 5
__post_init__()
step(reference: numpy.ndarray, measurement: numpy.ndarray, dt: float = 1, persist: bool = True) numpy.ndarray

Calculate the output, based on the current measurement and the reference signal.

Parameters

referencenp.ndarray

The reference signal(s) to track. Can be a number or an array.

measurementnp.ndarray

The actual measurement(s).

ref_is_error: bool

Whether to interpret the reference input as the error.

persist: bool

Whether to store the current state for the next step.

Returns

np.ndarray

The action signal.

class multirotor.controller.pid.AltRateController

Bases: PIDController

Climb rate controller. Tracks z-velocity and outputs thrust force needed.

vehicle: multirotor.simulation.Multirotor
__post_init__()
step(reference, measurement, dt, persist: bool = True)

Calculate the output, based on the current measurement and the reference signal.

Parameters

referencenp.ndarray

The reference signal(s) to track. Can be a number or an array.

measurementnp.ndarray

The actual measurement(s).

ref_is_error: bool

Whether to interpret the reference input as the error.

persist: bool

Whether to store the current state for the next step.

Returns

np.ndarray

The action signal.

class multirotor.controller.pid.Controller(ctrl_p: PosController, ctrl_v: VelController, ctrl_a: AttController, ctrl_r: RateController, ctrl_z: AltController, ctrl_vz: AltRateController, period_p: float = 0.1, period_a: float = 0.01, period_z: float = 0.1, feedforward_weight: float = 0.0)

The cascaded PID controller. Tracks position and yaw, and outputs thrust and moments needed.

(x,y) –> Position –> Velocity –> Attitude –> Rate –> (Moments) (z) –> Altitude –> Velocity –> (Forces)

property state: numpy.ndarray
property vehicle: multirotor.simulation.Multirotor
reset()
set_params(**params)
get_params() Dict[str, Dict[str, numpy.ndarray]]
step(reference: numpy.ndarray, measurement=None, ref_is_error: bool = False, feed_forward_velocity: numpy.ndarray = None, persist: bool = True)
predict(ref, deterministic=True)
classmethod make_for(vehicle: multirotor.simulation.Multirotor) Controller

Make a Controller with p-only parameters for a vehicle. The parameters can be learned using the optimize function.

Parameters

vehicleMultirotor

The vehicle to control.

Returns

Controller

The controller with p-only parameters.