-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqprop.py
More file actions
139 lines (105 loc) · 4.7 KB
/
qprop.py
File metadata and controls
139 lines (105 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import numpy as np
import subprocess
from scipy.optimize import fsolve
import matplotlib.pyplot as plt
import os
class QPROP():
def __init__(self, prop, motor, verbose=True):
self.prop = prop
self.motor = motor
self.kv = float(open(self.motor, 'r').readlines()[-1])
print(self.motor.split('\\')[-1] + " loaded successfully.") if verbose else None
print(self.prop.split('\\')[-1] + " loaded successfully.") if verbose else None
def raw(self, Vel, RPM):
self.rawOutput = subprocess.run(["qprop", self.prop, self.motor, str(Vel), str(RPM)], stdout=subprocess.PIPE)
self.rawOutput = self.rawOutput.stdout.decode('utf-8')
def parse(self):
output = self.rawOutput
with open("temp_out.txt", "w") as f:
f.write(output)
linesArr = []
for line in output.split('\n'):
linesArr.append(line.split())
dataHeaders = linesArr[16][1:]
try:
dataValues = [float(i) for i in linesArr[17][1:]]
self.parsedOutput = dict(zip(dataHeaders, dataValues))
except:
self.parsedOutput = dict(zip(dataHeaders, [0 for i in range(len(dataHeaders))]))
return self.parsedOutput
def run(self, Vel, RPM):
self.raw(Vel, RPM)
self.parse()
# print("Vel: " + str(Vel) + " RPM: " + str(RPM) + " Thrust: " + str(self.parsedOutput['T(N)']) + "N" + " Pele:" + str(self.parsedOutput['Pelec']) + "W")
return self.parsedOutput
def convergeThrust(self, Vel, Treq):
def f(RPM):
self.run(Vel, RPM[0])
return self.parsedOutput['T(N)'] - Treq
sol = fsolve(f, 5000)
return sol[0]
def thrustAvailableSweep(self, VelArr, cellCount):
# cellCount: integer count of battery cells, assumed each at 3.7V
maxRPM = 3.7 * cellCount * self.kv
thrustArr = []
ampArr = []
for Vel in VelArr:
self.run(Vel, maxRPM)
thrustArr.append(self.parsedOutput['T(N)'])
ampArr.append(self.parsedOutput['Amps'])
return thrustArr, ampArr
if __name__ == "__main__":
"""Motor/Prop Sweep"""
props = os.listdir("Props")
motors = os.listdir("Motors")
Treq = 10 # N
Vcruise = 11 # m/s
outputName = "output.csv"
for prop in props:
motor = "FlightLine_5055_390.txt"
qprop = QPROP("Props/" + prop, "Motors/" + motor)
trimRPM = qprop.convergeThrust(Vcruise, Treq)
qprop.run(Vcruise, trimRPM)
output = qprop.parsedOutput
thrust = output['T(N)']
if prop == props[0]:
with open("output.csv", "w") as f:
f.write("Motor,Prop,Trim RPM,Pelec,Thrust\n")
f.write(motor + "," + prop + "," + str(trimRPM) + "," + str(output['Pelec']) + "," + str(thrust) + "\n")
else:
with open("output.csv", "a") as f:
f.write(motor + "," + prop + "," + str(trimRPM) + "," + str(output['Pelec']) + "," + str(thrust) + "\n")
"""Vmax and Current Draws"""
motor = "Motors/FlightLine_5055_390.txt"
props = ["Props/apce_11x8.txt", "Props/apce_11x10.txt", "Props/apce_12x8.txt", "Props/apce_14x12.txt", "Props/apce_17x12.txt"]
labels = ["11x8", "11x10", "12x8", "14x12", "17x12"]
velArr = np.linspace(0, 30, 100)
cellCount = 6
# 2 figures: thrust vs velocity, thrust vs current
fig1, ax1 = plt.subplots()
fig2, ax2 = plt.subplots()
for prop in props:
qprop = QPROP(prop, motor, verbose=False)
thrustArr, ampArr = qprop.thrustAvailableSweep(velArr, cellCount)
ax1.plot(velArr, thrustArr, label=labels[props.index(prop)], linestyle='--')
ax2.plot(ampArr, thrustArr, label=labels[props.index(prop)], linestyle='--')
trimRPM = qprop.convergeThrust(Vcruise, Treq)
qprop.run(Vcruise, trimRPM)
print("Prop: " + prop + " | Cruise Amp: " + str(qprop.parsedOutput['Amps']) + " | Cruise Thrust: " + str(qprop.parsedOutput['T(N)']) + "N")
CD0 = 0.036 * 2
e = 0.96
AR = 10
k = 1 / (np.pi * e * AR)
rho = 1.225
S = 0.929
Treq = 0.5 * rho * S * CD0 * np.float_power(velArr, 2) + 2 * k * np.float_power(velArr, 2)
ax1.plot(velArr, Treq, label="Required", linestyle='-', color='black')
fig1.suptitle("Thrust Available/Required vs Velocity")
ax1.set_xlabel("Velocity (m/s)")
ax1.set_ylabel("Thrust (N)")
ax1.legend()
fig2.suptitle("Thrust vs Current")
ax2.set_xlabel("Current (A)")
ax2.set_ylabel("Thrust (N)")
ax2.legend()
plt.show()