Skip to content

Commit

Permalink
PDR
Browse files Browse the repository at this point in the history
  • Loading branch information
djlee9812 committed Apr 21, 2020
1 parent 7fcb75d commit 3cf22c0
Show file tree
Hide file tree
Showing 21 changed files with 19 additions and 98 deletions.
92 changes: 2 additions & 90 deletions climb.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def plot_trajectory(data_file="cycle.npz"):

fig = plt.figure(figsize=(7,7.5))
ax1 = plt.subplot(311)
ax1.set_title("24 Hour Cycle for each Propeller")
ax1.set_title("Climb for each Propeller")
# ax1.plot(t_d, h_d/304.88, ".-", label="Day", color="cornflowerblue")
# ax1.plot(t_n, h_n/304.88, ".-", label="Night", color="midnightblue")
ax1.plot(t, h/304.88, ".-", color="cornflowerblue")
Expand Down Expand Up @@ -142,7 +142,7 @@ def plot_trajectory(data_file="cycle.npz"):
# ax32.plot(t_n, Q_n, ".-", label="Night", color="maroon")
ax32.plot(t, Q, ".-", color="indianred")
ax32.set_ylabel('Required Torque [Nm]', color="maroon")
ax3.set_xlabel("Time from Solar Noon [hr]")
ax3.set_xlabel("Time after Takeoff [hr]")
ax32.grid(None)

plt.figure()
Expand All @@ -158,49 +158,6 @@ def plot_trajectory(data_file="cycle.npz"):
plt.title("Motor Torque Requirement vs RPM")
plt.show()

def plot_motor_eff(Kv, R, I0):
Qs = np.linspace(5, 30, 50)
RPMs = np.linspace(400, 2000, 60)
mot_effs = np.zeros((50, 60))
for i, Q in enumerate(Qs):
for j, RPM in enumerate(RPMs):
# I = Q*Kv + I0
# V = RPM * Kv + I*R
# mot_effs[i, j] = (1 - I*R/V) * (1 - I0/I)
mot_effs[i,j] = (Kv*RPM/(Kv*RPM+Q*R*Kv+I0*R))*(Q*Kv/(Q*Kv+I0))
# return np.mean(mot_effs)
print(np.mean(mot_effs))
plt.figure()
X, Y = np.meshgrid(RPMs, Qs)
plt.contourf(X, Y, mot_effs)
plt.xlabel("RPMs")
plt.ylabel("Torques")
plt.title("Motor Efficiencies over Operating Range")
plt.colorbar()
plt.show()


def rpm_trade(rpms, ts, hs, vs, thrusts, optimize):
"""
Trade study of design RPM vs average efficiency over cycle. Given a range
of rpms, redesign "test_prop" to be optimized at the given rpm and use
the output propeller to get average efficiency over cycle
"""
effs = np.zeros(len(rpms))
for i, rpm in enumerate(rpms):
print("Design rpm:", rpm, "Design eff:", -design_prop(rpm, "test_prop"))
effs[i] = follow_trajectory(ts, hs, vs, thrusts, npt=200,
optimize=optimize, show=False,
prop="test_prop")
# plt.figure()
# plt.plot(rpms, effs)
# opt_title = "with Variable Pitch" if optimize else ""
# plt.title("Design RPM vs Average Efficiency " + opt_title)
# plt.xlabel("QMil Design RPM")
# plt.ylabel(r"Average $\eta$ over 24 Hour Cycle")
# plt.show()
return effs

if __name__ == "__main__":
num_motor = 6
data = np.load('climb_path.npz')
Expand All @@ -209,35 +166,6 @@ def rpm_trade(rpms, ts, hs, vs, thrusts, optimize):
vs = data['v'][:55]
thrusts = data['thrust'][:55]/num_motor

# plot_motor_eff(20*np.pi/30, 0.2, .5)
# Kvs = np.linspace(3, 10, 10)
# I0s = np.linspace(1, 5, 15)
# effs = np.zeros((10, 15))
# for i, Kv in enumerate(Kvs):
# for j, I0 in enumerate(I0s):
# effs[i,j] = plot_motor_eff(Kv*np.pi/30, 1.1, I0)
# plt.figure()
# X, Y = np.meshgrid(I0s, Kvs)
# plt.contourf(X, Y, effs)
# plt.title("Average Efficiencies for Various Motors")
# plt.xlabel(r"$I_0$")
# plt.ylabel("Kv")
# plt.colorbar()
# plt.show()

# rpms = np.arange(800, 1700, 50)
# opt_eff = rpm_trade(rpms, ts, hs, vs, thrusts, True)
# unopt_eff = rpm_trade(rpms, ts, hs, vs, thrusts, False)
# np.savez("rpm_trade.npz", opt_eff, unopt_eff)
# plt.figure()
# plt.plot(rpms, opt_eff, label="Variable Pitch")
# plt.plot(rpms, unopt_eff, label="Fixed Pitch")
# plt.title("Design RPM vs Average Efficiency")
# plt.xlabel("QMil Design RPM")
# plt.ylabel(r"Average $\eta$ over 24 Hour Cycle")
# plt.legend()
# plt.show()

# start = time.time()
eff_opt = follow_trajectory(ts, hs, vs, thrusts, npt=200, optimize=True)
print("Average Efficiency:", eff_opt)
Expand All @@ -247,19 +175,3 @@ def rpm_trade(rpms, ts, hs, vs, thrusts, optimize):
print("Average Efficiency:", eff_unopt)
plot_trajectory("climb_unopt.npz")
# print(time.time() - start)


# result = np.load("cycle.npz")["res"].T
# result2 = np.load("cycle_unopt.npz")["res"].T
# t, h, v, p, thrust, rpm, Q, Pshaft, J, dbeta, eta = result
# plt.figure()
# plt.plot(t, rpm, label="Variable Pitch")
# plt.ylabel('RPM')
# result = np.load("cycle_unopt.npz")["res"].T
# t, h, v, p, thrust, rpm, Q, Pshaft, J, dbeta, eta = result
# plt.plot(t, rpm, label="Fixed Pitch")
# plt.xlabel("Time [hr]")
# plt.title("RPM over cycle")
# plt.legend()
# plt.show()
#
Binary file added data/PDR/climb.npz
Binary file not shown.
Binary file added data/PDR/climb_path.npz
Binary file not shown.
Binary file added data/PDR/climb_unopt.npz
Binary file not shown.
Binary file added data/PDR/cycle.npz
Binary file not shown.
Binary file added data/PDR/cycle_unopt.npz
Binary file not shown.
Binary file added data/PDR/opt_sweep.npz
Binary file not shown.
Binary file added data/PDR/rpm_trade.npz
Binary file not shown.
Binary file added data/PDR/time_altitude_airspeed.npz
Binary file not shown.
Binary file modified plots/.DS_Store
Binary file not shown.
Binary file modified plots/climb/Fixedpitch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified plots/climb/Varpitch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified plots/prop_motor_match/mot_Kv_I0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified plots/prop_motor_match/mot_rpm_Q.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified plots/prop_motor_match/mot_rpm_Q_highKv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified plots/prop_motor_match/varpitch_J_eff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plots/prop_motor_match/varpitch_timedata_tot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified plots/prop_motor_match/varpitch_torque_rpm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions qprop_sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ def get_eff(dBeta, vel, thrust, prop="best_prop", motor="est_motor"):
# Grab efficiency
data = get_nums(dBeta, vel, thrust, prop, motor)
eff_prop = -data[9]
eff_tot = -data[14]
return eff_tot
Pshaft = data[5]
motor_loss = np.tanh(3 * Pshaft/2000)
eff_tot = -data[14] * motor_loss
Pelec = data[15]
return eff_prop

def opt_dbeta(vel, thrust, prop="best_prop", motor="est_motor"):
"""
Expand Down
18 changes: 12 additions & 6 deletions trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,13 @@ def plot_trajectory(data_file="cycle.npz"):
plt.show()

def plot_motor_eff(Kv, R, I0):
"""
Calculate and plot motor efficiency over various torque and RPM ranges.
The RPM/Omega used in the calculations and Kv should be in units of
rad/s instead of rpm.
"""
Qs = np.linspace(5, 30, 50)
RPMs = np.linspace(400, 2000, 60)
RPMs = np.linspace(200, 2000, 60)*np.pi/30
mot_effs = np.zeros((50, 60))
for i, Q in enumerate(Qs):
for j, RPM in enumerate(RPMs):
Expand All @@ -164,7 +169,7 @@ def plot_motor_eff(Kv, R, I0):
# return np.mean(mot_effs)
print(np.mean(mot_effs))
plt.figure()
X, Y = np.meshgrid(RPMs, Qs)
X, Y = np.meshgrid(RPMs*30/np.pi, Qs)
plt.contourf(X, Y, mot_effs)
plt.xlabel("RPMs")
plt.ylabel("Torques")
Expand Down Expand Up @@ -203,7 +208,8 @@ def rpm_trade(rpms, ts, hs, vs, thrusts, optimize):
thrusts = data['thrust']/num_motor
# plt.plot(ts, hs)
# plt.show()
# plot_motor_eff(20*np.pi/30, 0.2, .5)

# plot_motor_eff(8*np.pi/30, 1.1, 3.6)
# Kvs = np.linspace(3, 10, 10)
# I0s = np.linspace(1, 5, 15)
# effs = np.zeros((10, 15))
Expand Down Expand Up @@ -233,9 +239,9 @@ def rpm_trade(rpms, ts, hs, vs, thrusts, optimize):
# plt.show()

# start = time.time()
# eff_opt = follow_trajectory(ts, hs, vs, thrusts, npt=200, optimize=True)
# print("Average Efficiency:", eff_opt)
# plot_trajectory("cycle.npz")
eff_opt = follow_trajectory(ts, hs, vs, thrusts, npt=200, optimize=True)
print("Average Efficiency:", eff_opt)
plot_trajectory("cycle.npz")
# print(time.time() - start)
# eff_unopt = follow_trajectory(ts, hs, vs, thrusts, npt=200, optimize=False)
# print("Average Efficiency:", eff_unopt)
Expand Down

0 comments on commit 3cf22c0

Please sign in to comment.