Controller base class

pynamics.controllers.base

This module contains the controller base class. Every controller class compatible with pynamics should inherit from this class.

Classes:

Name Description
BaseController

Controller base class.

BaseController(n_inputs, n_outputs, sampling_time)

Bases: ABC

Base class for all controllers supported by this package.

Every controller class compatible with pynamics should inherit from this class. This is simply an abstract base class. As such, it should not be used directly. Derived classes may naturally provide methods and attributes that are not strictly required by this base class.

Parameters:

Name Type Description Default
n_inputs int

Number of controller inputs.

required
n_outputs int

Number of controller outputs. Should be the same as the system's input dimension.

required
sampling_time int | float

Controller sampling time (in seconds).

required

Attributes:

Name Type Description
input_dim int

Number of controller inputs.

output_dim int

Number of controller outputs.

Ts int | float

Controller sampling time (in seconds).

Methods:

Name Description
info

Display useful information regarding the controller.

control

Compute control actions for the next time instant.

Warning

This is an abstract base class. It should not be used directly.

Source code in pynamics/controllers/base.py
def __init__(self, n_inputs: int, n_outputs: int, sampling_time: int | float) -> None:

    """
    Class constructor.
    """

    super().__init__();
    self._input_dim = n_inputs;
    self._output_dim = n_outputs;
    self._sampling_time = sampling_time;

    return;

Ts: int | float property writable

Get the controller's sampling time.

This method can be used to access the controller's sampling time using dot notation.

Returns:

Type Description
int | float

Controller sampling time (seconds).

input_dim: int property

Get the controller's input dimension.

This method can be used to access the number of controller input variables using dot notation.

Returns:

Type Description
int

Number of controller inputs.

output_dim: int property

Get the controller's output dimension.

This method can be used to access the number of controller output variables using dot notation.

Returns:

Type Description
int

Number of controller outputs.

control(ref, y) abstractmethod

Computes the control actions for the next time instant.

Abstract method. Implementation details are specific to each controller and should therefore vary considerably.

Parameters:

Name Type Description Default
ref ndarray

Array of reference values. For regulation problems, this should be an array of zeros.

required
y ndarray

System state vector. Note that this refers only to the latest time instant. If a controller requires information from earlier time instants, it should store it internally.

required

Returns:

Type Description
ndarray

Array of control actions.

Source code in pynamics/controllers/base.py
@abstractmethod
def control(self, ref: np.ndarray, y: np.ndarray) -> np.ndarray:
    """
    Computes the control actions for the next time instant.

    Abstract method. Implementation details are specific to each controller and should therefore vary considerably.

    Parameters
    ----------
    ref : np.ndarray
        Array of reference values. For regulation problems, this should be an array of zeros.

    y : np.ndarray
        System state vector. Note that this refers only to the latest time instant. \
        If a controller requires information from earlier time instants, it should store \
        it internally.

    Returns
    -------
    np.ndarray
        Array of control actions.
    """

    pass

info() abstractmethod

Provides useful information regarding the controller.

Abstract method. Implementation details are specific to each controller and should therefore vary considerably.

Source code in pynamics/controllers/base.py
@abstractmethod
def info(self) -> None:
    """
    Provides useful information regarding the controller.

    Abstract method. Implementation details are specific to each controller and should therefore vary considerably.
    """

    pass