aeroshield.controller

Module Contents

Classes

AeroController

class aeroshield.controller.AeroController(aero_shield: aeroshield.aeroshield.AeroShield)[source]
variables() None[source]

Define variables to be used by the controller or saved during the experiment.

add_tracked_variable(name: str, size: int | None = 1) dict[str, int][source]

Add a variable to the list of variables whose value should be tracked during the experiment and returned afterwards. Variables should be instance variables of the class, otherwise they won’t be accessible!

Parameters:
  • name (str) – Name of the variable, without ‘self.’

  • size (int, optional) – Size of the variable, e.g. 3 for a three-dimensional position vector. Defaults to 1, i.e. single values.

Returns:

A copy of the current map of tracked variables and their respective size.

Return type:

dict[str, int]

controller(t: float, dt: float, ref: float, pot: float, angle: float) float[source]

Implement the controller here. You can subclass AeroController and overwrite the controller.

Parameters:
  • t (float) – Time since start of run in seconds.

  • dt (float) – Length of current time step in seconds.

  • ref (float) – reference value for the current step.

  • pot (float) – potentiometer value in percent.

  • angle (float) – calibrated angle in degrees.

Returns:

input value for motor. the motor value will be saturated (int between 0 and 255 incl.) afterwards

Return type:

float

run(freq: int, cycles: int, ref: float | int | Iterable[float | int] | None = None, live_plotter: aeroshield.plotting.LivePlotter | None = None) numpy.ndarray[source]

Run the controller on the AeroShield.

Parameters:
  • freq (int) – Desired frequency of the loop.

  • cycles – Number of cycles to run the experiment.

  • ref (np.ndarray[float|int]) – The reference to follow should have a lenght equal to freq * time.

  • live_plotter (LivePlotter) – Optional. LivePlotter instance to use for displaying a live plot.

_update_hist(hist: numpy.ndarray[float], cntr: int, t: float, ref: float, pot: float, angle: float, motor: float)[source]

Update hist array with variables of the current iteration (cntr). If variables were added to extra_hist_vars, add them to the hist as well.

Parameters:
  • hist (np.ndarray[float]) – array to update.

  • cntr (int) – Iteration counter. Provides the first index to hist.

  • t (float) – Time.

  • ref (float) – Current reference value.

  • angle (float) – Current pendulum angle

  • motor (float) – Current Motor value.