diff --git a/.idea/misc.xml b/.idea/misc.xml index e158a33..116cb80 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/control_functions.py b/control_functions.py index 4cbe1d1..987deef 100644 --- a/control_functions.py +++ b/control_functions.py @@ -14,7 +14,6 @@ import csv # CSV handling from datetime import datetime # Date and time formatting import time # Time formatting -from serial.tools.list_ports_osx import kCFNumberSInt8Type ######################################## Variables (start) ################################## # Variables to control sensor @@ -36,20 +35,20 @@ SCREEN: bool = True # Log data to screen DEBUG: bool = False # More data to display # Variables to assist PID calculations -current_time: float = 0 -integral: float = 0 -time_prev: float = -1e-6 -error_prev: float = 0 +current_time = 0 +integral = 0 +time_prev = -1e-6 +error_prev = 0 # Variables to control PID values (PID formula tweaks) -p_value: float = 2 -i_value: float = 0 -d_value: float = 0 +p_value = 2 +i_value = 0 +d_value = 0 # Initial variables, used in pid_calculations() -i_result: float = 0 -previous_time: float -previous_error: float +i_result = 0 +previous_time = 0 +previous_error = 0 # Init array, used in read_distance_sensor() sample_array: list = [] @@ -153,18 +152,18 @@ def pid_calculations(setpoint): error_sum: float = 0.0 if previous_time is None: - previous_error: float = 0.0 - previous_time: float = current_time - i_result: float = 0.0 - error_sum: float = error * 0.008 # sensor sampling number approximation. + previous_error = 0.0 + previous_time = current_time + i_result = 0.0 + error_sum = error * 0.008 # sensor sampling number approximation. - error_sum: float = error_sum + (error * (current_time - previous_time)) - p_result: float = p_value * error - i_result: float = i_value * error_sum - d_result: float = d_value * ((error - previous_error) / (current_time - previous_time)) - pid_result: float = offset_value + p_result + i_result + d_result - previous_error: float = error - previous_time: float = current_time + error_sum = error_sum + (error * (current_time - previous_time)) + p_result = p_value * error + i_result = i_value * error_sum + d_result = d_value * ((error - previous_error) / (current_time - previous_time)) + pid_result = offset_value + p_result + i_result + d_result + previous_error = error + previous_time = current_time return pid_result