:py:mod:`aeroshield.controller` =============================== .. py:module:: aeroshield.controller Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: aeroshield.controller.AeroController .. py:class:: AeroController(aero_shield: aeroshield.aeroshield.AeroShield) .. py:method:: variables() -> None Define variables to be used by the controller or saved during the experiment. .. py:method:: add_tracked_variable(name: str, size: Optional[int] = 1) -> dict[str, int] 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! :param name: Name of the variable, without 'self.' :type name: str :param size: Size of the variable, e.g. 3 for a three-dimensional position vector. Defaults to 1, i.e. single values. :type size: int, optional :return: A copy of the current map of tracked variables and their respective size. :rtype: dict[str, int] .. py:method:: controller(t: float, dt: float, ref: float, pot: float, angle: float) -> float Implement the controller here. You can subclass AeroController and overwrite the controller. :param t: Time since start of run in seconds. :type t: float :param dt: Length of current time step in seconds. :type dt: float :param ref: reference value for the current step. :type ref: float :param pot: potentiometer value in percent. :type pot: float :param angle: calibrated angle in degrees. :type angle: float :return: input value for motor. the motor value will be saturated (int between 0 and 255 incl.) afterwards :rtype: float .. py:method:: run(freq: int, cycles: int, ref: Optional[float | int | Iterable[float | int]] = None, live_plotter: Optional[aeroshield.plotting.LivePlotter] = None) -> numpy.ndarray Run the controller on the AeroShield. :param freq: Desired frequency of the loop. :type freq: int :param cycles: Number of cycles to run the experiment. :type duration: int :param ref: The reference to follow should have a lenght equal to freq * time. :type ref: np.ndarray[float|int] :param live_plotter: Optional. LivePlotter instance to use for displaying a live plot. :type live_plotter: LivePlotter .. py:method:: _update_hist(hist: numpy.ndarray[float], cntr: int, t: float, ref: float, pot: float, angle: float, motor: float) 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. :param hist: array to update. :type hist: np.ndarray[float] :param cntr: Iteration counter. Provides the first index to hist. :type cntr: int :param t: Time. :type t: float :param ref: Current reference value. :type ref: float :param angle: Current pendulum angle :type angle: float :param motor: Current Motor value. :type motor: float