From e15365387cff5586f09dc85af3bb89a58e530609 Mon Sep 17 00:00:00 2001 From: Anonymoustank Date: Wed, 7 Sep 2022 15:00:28 -0600 Subject: [PATCH 1/2] Add pid solver --- pid-solver/pid.py | 92 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 pid-solver/pid.py diff --git a/pid-solver/pid.py b/pid-solver/pid.py new file mode 100755 index 0000000..5f839d2 --- /dev/null +++ b/pid-solver/pid.py @@ -0,0 +1,92 @@ +import csv +import sys +import argparse +from os.path import exists +mode = "BOTH" + +parser = argparse.ArgumentParser(description='Find PID values') +parser.add_argument('filename', metavar='filename', type=str, nargs=1, help='File that will be parsed') +parser.add_argument('mode', metavar='mode', choices = ["ZN", "CC", "BOTH"], default = "BOTH", nargs=1, help='Type of pid tuning method that will be used') +args = parser.parse_args() + +if (len(sys.argv) < 2): + print("Please input filename") + sys.exit() +else: + filename = sys.argv[1] +if (len(sys.argv) > 2): + mode = sys.argv[2] + mode = mode.upper() + +if not exists(filename): + print("Please input a valid file") + sys.exit() + +if (mode != "BOTH" and mode != "ZN" and mode != "CC"): + print("Please pass in a valid method:\n ZN for Ziegler Nichol's Open Loop Method \n CC for the Cohen-Coon Open Loop Method \n BOTH for both of them") + sys.exit() + +c = 2 +distance = 0.01 +x1 = 0 # +x2 = -1 +middle_point = -1 +x3 = -1 +t = -1 +l = -1 +max_slope = 0 + + +def zn_open(): #Ziegler Nichols Open Loop Method + gain_kc = (1.2/k)*t/l + reset_time = 2 * l + derivative_time = 0.5 * l + + print("ZN gain_kc, reset_time, derivative_time: " + str(gain_kc) + ", " + str(reset_time) + ", " + str(derivative_time)) + +def cc_open(): #Cohen-Coon Open Loop Method + gain_kc = 1.35/(k*(t/l+0.092)) + reset_time = 2.5*l*(t+0.185*l)/(t+0.611*l) + derivative_time = 0.37*l*(t/(t+0.185*l)) + + print("CC gain_kc, reset_time, derivative_time: " + str(gain_kc) + ", " + str(reset_time) + ", " + str(derivative_time)) + + + +with open(filename, 'r') as csvfile: + datareader = csv.reader(csvfile) + datareader_list = list(datareader)[1:] #convert csv to list, get rid of headers at the top + setpoint = float(datareader_list[len(datareader_list)-1][2]) #target value we're going towards (setpoint of the final row) + for i in range(len(datareader_list)): + if i>0: #ignore first point because no points behind it + if (float(datareader_list[i][2]) - float(datareader_list[i-1][2]))/(float(datareader_list[i][0]) - float(datareader_list[i-1][0]))>c: #If there's a sudden spike in the setpoint value, we mark this point's x value as x1 + x1=float(datareader_list[i][0]) + if abs(float(datareader_list[i][1])-setpoint) < distance and x3 < 0: #If a point's y value is reeaaaally close to the setpoint, we set its x value as x3 + x3=float(datareader_list[i][0]) + if i < len(datareader_list) - 1: #ignore last point no points after it + if (float(datareader_list[i+1][1]) - float(datareader_list[i-1][1]))/(float(datareader_list[i+1][0]) - float(datareader_list[i-1][0])) > max_slope: #calculate max slope by doing slope formula on adjacent points + max_slope = (float(datareader_list[i+1][1]) - float(datareader_list[i-1][1]))/(float(datareader_list[i+1][0]) - float(datareader_list[i-1][0])) + middle_point = datareader_list[i] #the point with the max slope + + x2 = (-float(middle_point[1])/max_slope) + float(middle_point[0]) #calculate the x value of the point where the tangent line that goes through middle_point intersects the y axis + print("x1, x2, x3: " + str(x1) + ", " + str(x2) + ", " + str(x3)) + t = x3-x2 + l = x2-x1 + print(" ") + print("t, l: " + str(t) + ", " + str(l)) + k= setpoint - float(datareader_list[0][1]) + print(" ") + + if (mode == "CC"): #parse command line inputs to display the appropriate tuning method + cc_open() + elif (mode == "ZN"): + zn_open() + else: + cc_open() + zn_open() + + + + + + From 5b3f3da8894c2af38a62042efd2eb06830fa5b76 Mon Sep 17 00:00:00 2001 From: Anonymoustank Date: Tue, 7 Feb 2023 18:38:25 -0700 Subject: [PATCH 2/2] Add css for scouting app --- style.css | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 style.css diff --git a/style.css b/style.css new file mode 100644 index 0000000..498a80b --- /dev/null +++ b/style.css @@ -0,0 +1,36 @@ +.styled-table { + border-collapse: collapse; + margin: 25px 0; + font-size: 0.9em; + font-family: sans-serif; + min-width: 400px; + box-shadow: 0 0 20px rgba(0, 0, 0, 0.15); +} + +.styled-table thead tr { + background-color: #009879; + color: #ffffff; + text-align: left; +} + +.styled-table th, +.styled-table td { + padding: 12px 15px; +} + +.styled-table tbody tr { + border-bottom: 1px solid #dddddd; +} + +.styled-table tbody tr:nth-of-type(even) { + background-color: #f3f3f3; +} + +.styled-table tbody tr:last-of-type { + border-bottom: 2px solid #009879; +} + +.styled-table tbody tr.active-row { + font-weight: bold; + color: #009879; +} \ No newline at end of file