Loading#
The loading subpackage includes some classes for complex load estimation algorithms. See examples.future_loading
for more details.
Load Estimator Class interface#
The key aspect of a load estimator is that it needs to be able to be called with either time or time and state. The most common way of accomplishing this is with a function, described in the dropdown below.
Functional Load Estimator
>>> def load_estimator(t, x = None):
>>> # Calculate loading as function of time (t) and state (x)
>>> return load
The second approach for load estimators is a load estimation class. This is used to represent complex behavior. The interface for this is described in the dropdown below.
Class Load Estimator
>>> class LoadEstimator:
>>> def __init__(self, *args, **kwargs):
>>> # Initialize the load estimator
>>> pass
>>> def __call__(self, t, x = None):
>>> # Calculate loading as function of time (t) and state (x)
>>> return load
Load Estimator Classes#
- class progpy.loading.Piecewise(InputContainer, times, values)#
New in version 1.5.0.
This is a simple piecewise future loading class. It takes a list of times and values and returns the value that corresponds to the current time. The object replaces the future_loading_eqn for simulate_to and simulate_to_threshold.
- Parameters
InputContainer (class) – The InputContainer class for the model (model.InputContainer)
values (dict[str, list[float]]) – A dictionary with keys matching model inputs. Dictionary contains list of value for that input at until time in times (i.e., index 0 is the load until time[0], then it’s index 1). Values dictionary should have the same or one more value than times. If values has one more value than times, then the last value is the default and will be applied after the last time has passed
Example
>>> from progpy.loading import Piecewise >>> m = SomeModel() >>> future_load = Piecewise(m.InputContainer, [0, 10, 20], {'input0': [0, 1, 0, 0.2]}) >>> m.simulate_to_threshold(future_load)
- class progpy.loading.MovingAverage(InputContainer: type, window: int = 10)#
New in version 1.5.0.
This is a simple moving average future loading class. It takes input values and stores them in a window. When called, it returns the average of the values in the window. The object replaces the future_loading_eqn for simulate_to and simulate_to_threshold.
- Parameters
InputContainer (class) – The InputContainer class for the model (model.InputContainer)
window (int, optional) – The size of the window to use for the moving average, by default 10
Example
>>> from progpy.loading import MovingAverage >>> m = SomeModel() >>> future_load = MovingAverage(m.InputContainer) >>> for _ in range(WINDOW_SIZE): >>> load = load_source.get_load() >>> future_load.add_load(load) >>> m.simulate_to_threshold(future_load)
- class progpy.loading.GaussianNoiseWrapper(fcn: collections.abc.Callable, std: float, seed: int = None, std_slope: float = 0, t0: float = 0)#
New in version 1.5.0.
This is a simple wrapper for future loading functions that adds gaussian noise to the inputs. It takes a future loading function and a standard deviation and returns a new future loading function that adds gaussian noise to the inputs.
- Parameters
fcn (Callable) – The future loading function to wrap
std (float) – The standard deviation of the gaussian noise to add
- Keyword Arguments
seed ({int, SeedSequence, BitGenerator, Generator}, optional) – The seed for random number generator. This can be set to make results repeatable.
Example
>>> from progpy.loading import GaussianNoiseLoadWrapper >>> m = SomeModel() >>> future_load = GaussianNoiseLoadWrapper(future_load, STANDARD_DEV) >>> m.simulate_to_threshold(future_load)
Controllers#
- class progpy.loading.controllers.LQR(x_ref, vehicle, **kwargs)#
Linear Quadratic Regulator UAV Controller
A Controller that calculates the vehicle control inputs for a UAV model (progpy.models.uav_model).
- Parameters
- Keyword Arguments
Q (np.ndarray) – State error penalty matrix, size num_states x num_states (where num_states only includes dynamic states) Represents how ‘bad’ an error is in the state vector w.r.t. the reference state vector
R (np.ndarray) – Input penalty matrix, size num_inputs x num_inputs (where num_inputs only includes inputs that inform the system dynamics) Represents how ‘hard’ it is to produce the desired input (thrust and three moments along three axes)
scheduled_var (str) – Variable used to create the scheduled controller gains; must correspond to a state key
index_scheduled_var (int) – Index corresponding to the scheduled_var in the state vector
- class progpy.loading.controllers.LQR_I(x_ref, vehicle, **kwargs)#
Linear Quadratic Regulator with Integral Effect
- Parameters
- Keyword Arguments
Q (np.ndarray) – State error penalty matrix, size num_states x num_states (where num_states only includes dynamic states) Represents how ‘bad’ an error is in the state vector w.r.t. the reference state vector
R (np.ndarray) – Input penalty matrix, size num_inputs x num_inputs (where num_inputs only includes inputs that inform the system dynamics) Represents how ‘hard’ it is to produce the desired input (thrust and three moments along three axes)
int_lag (int) – Length of the time window, in number of simulation steps, to integrate the state position error. The time window is defined as the last int_lag discrete steps up until the current discrete time step. The integral of the state position error adds to the overall state error to compute the gain matrix, and helps compensate for constant offsets between the reference (desired) position and the actual position of the vehicle.
scheduled_var (str) – Variable used to create the scheduled controller gains; must correspond to a state key
index_scheduled_var (int) – Index corresponding to the scheduled_var in the state vector