Skip to content

PI Module

This class is a proportional-integral controller which is used in the passiv eand active tracking modes to determine the velocity for the motors on the primary and secondary axis.

Class Documentation

Bases: QObject

A class implementing a Proportional-Integral controller.

Attributes:

Name Type Description
array list

A list to store past error values.

P float

Proportional gain.

I float

Integral gain.

grad2step float

Conversion factor.

E float

Current error value.

V float

Current process variable value.

rest float

Rest value from previous calculations.

sum float

Summation of past errors.

Source code in PI_module.py
class PI(QObject):
    """A class implementing a Proportional-Integral controller.

    Attributes:
        array (list): A list to store past error values.
        P (float): Proportional gain.
        I (float): Integral gain.
        grad2step (float): Conversion factor.
        E (float): Current error value.
        V (float): Current process variable value.
        rest (float): Rest value from previous calculations.
        sum (float): Summation of past errors.
    """
    def __init__(self, N_array, P, I, conversion):
        """Initialize the PI controller.

        Args:
            N_array (int): Length of the array to store past error values.
            P (float): Proportional gain.
            I (float): Integral gain.
            conversion (float): Conversion factor.
        """

        self.array = [0] * N_array
        self.P = P
        self.I = I
        self.grad2step= conversion
        self.E = 0
        self.V = 0
        self.rest = 0
        self.sum = 0

    def feed(self, E,V):
        """
        Feed the controller with the current error and process variable values.

        Args:
            E (float): Current error value.
            V (float): Current process variable value.
        """
        self.V = V
        self.E = E
        self.array = np.roll(self.array, 1).tolist()
        self.array[0] = self.E




    def get_speed(self):
        """
        Calculate and return the control output.

        Returns:
            None
        """
        self.sum = self.sum +self.E
        self.M = (self.V+np.mean(self.array)*self.P+self.sum*self.I)*self.grad2step + self.rest
        self.rest = self.M-round(self.M)
        return self.M

__init__(N_array, P, I, conversion)

Initialize the PI controller.

Parameters:

Name Type Description Default
N_array int

Length of the array to store past error values.

required
P float

Proportional gain.

required
I float

Integral gain.

required
conversion float

Conversion factor.

required
Source code in PI_module.py
def __init__(self, N_array, P, I, conversion):
    """Initialize the PI controller.

    Args:
        N_array (int): Length of the array to store past error values.
        P (float): Proportional gain.
        I (float): Integral gain.
        conversion (float): Conversion factor.
    """

    self.array = [0] * N_array
    self.P = P
    self.I = I
    self.grad2step= conversion
    self.E = 0
    self.V = 0
    self.rest = 0
    self.sum = 0

feed(E, V)

Feed the controller with the current error and process variable values.

Parameters:

Name Type Description Default
E float

Current error value.

required
V float

Current process variable value.

required
Source code in PI_module.py
def feed(self, E,V):
    """
    Feed the controller with the current error and process variable values.

    Args:
        E (float): Current error value.
        V (float): Current process variable value.
    """
    self.V = V
    self.E = E
    self.array = np.roll(self.array, 1).tolist()
    self.array[0] = self.E

get_speed()

Calculate and return the control output.

Returns:

Type Description

None

Source code in PI_module.py
def get_speed(self):
    """
    Calculate and return the control output.

    Returns:
        None
    """
    self.sum = self.sum +self.E
    self.M = (self.V+np.mean(self.array)*self.P+self.sum*self.I)*self.grad2step + self.rest
    self.rest = self.M-round(self.M)
    return self.M