Skip to content

Worker Logger

Bases: QObject

A class representing a worker for logging data.

Attributes:

Name Type Description
log_file_path str

Path to the log file.

Source code in GUI.py
class WorkerLogger(QObject):
    """
    A class representing a worker for logging data.

    Attributes:
        log_file_path (str): Path to the log file.
    """
    def __init__(self, log_file_path):
        """
        Initialize the WorkerLogger.

        Args:
            log_file_path (str): Path to the log file.
        """
        self.log_file_path = log_file_path
        if os.path.exists(self.log_file_path):
            pass
        else:
            with open(self.log_file_path, "w") as file:
                file.write('time state POS_A POS_E FQ_X FQ_Y V_A V_E E_A E_E\n')
    def log(self, time, state, pos, M, E):
        """
        Log data to the log file.

        Args:
            time (float): Time value.
            state (str): State information.
            pos (dict): Dictionary containing position information.
            M (dict): Dictionary containing motor speed values.
            E (dict): Dictionary containing error values.
        """
        with open(self.log_file_path, "a") as file:
            file.write(f"{round(time,4)} {state} {pos['A']} {pos['E']} {pos['FQ'][0]} {pos['FQ'][1]} {M['A']} {M['E']} {E['DA']} {E['DE']}\n")   

__init__(log_file_path)

Initialize the WorkerLogger.

Parameters:

Name Type Description Default
log_file_path str

Path to the log file.

required
Source code in GUI.py
def __init__(self, log_file_path):
    """
    Initialize the WorkerLogger.

    Args:
        log_file_path (str): Path to the log file.
    """
    self.log_file_path = log_file_path
    if os.path.exists(self.log_file_path):
        pass
    else:
        with open(self.log_file_path, "w") as file:
            file.write('time state POS_A POS_E FQ_X FQ_Y V_A V_E E_A E_E\n')

log(time, state, pos, M, E)

Log data to the log file.

Parameters:

Name Type Description Default
time float

Time value.

required
state str

State information.

required
pos dict

Dictionary containing position information.

required
M dict

Dictionary containing motor speed values.

required
E dict

Dictionary containing error values.

required
Source code in GUI.py
def log(self, time, state, pos, M, E):
    """
    Log data to the log file.

    Args:
        time (float): Time value.
        state (str): State information.
        pos (dict): Dictionary containing position information.
        M (dict): Dictionary containing motor speed values.
        E (dict): Dictionary containing error values.
    """
    with open(self.log_file_path, "a") as file:
        file.write(f"{round(time,4)} {state} {pos['A']} {pos['E']} {pos['FQ'][0]} {pos['FQ'][1]} {M['A']} {M['E']} {E['DA']} {E['DE']}\n")