Skip to content

Instantly share code, notes, and snippets.

@olexs
Created December 8, 2015 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olexs/c872f20519da441cd039 to your computer and use it in GitHub Desktop.
Save olexs/c872f20519da441cd039 to your computer and use it in GitHub Desktop.
Motor thrust/efficiency plotter script
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
InterpolatedToFile = "plot.png"
MotorPropThrust = np.array([34, 77, 127, 198, 266, 354, 457, 555, 689, 805, 943, 1064, 1136, 1330])
MotorPropAmps = np.array([0.23, 0.48, 0.74, 1.15, 1.67, 2.41, 3.42, 4.29, 5.91, 7.59, 9.24, 10.48, 12.76, 16.38])
MotorPropVolts = np.array([16.66, 16.66, 16.66, 16.66, 16.66, 16.66, 16.52, 16.52, 16.38, 16.38, 16.22, 16.22, 16.22, 16.08]);
MotorPropTitle = "Flyduino X2212-1000kv, HQ 9043 Endurance, 16.8V"
#MotorPropThrust2 = np.array([24, 56, 101, 159, 221, 296, 388, 474, 584, 698, 806, 908, 1007, 1170])
#MotorPropAmps2 = np.array([0.21, 0.41, 0.66, 1.02, 1.47, 2.18, 3.04, 3.74, 5, 6.78, 8.31, 10, 11.39, 14.12])
#MotorPropVolts2 = np.array([15.5, 15.5, 15.5, 15.5, 15.35, 15.35, 15.35, 15.35, 15.21, 15.20, 15.06, 15.06, 15.06, 14.91]);
#MotorPropTitle2 = "Flyduino X2212-1000kv, HQ 9043 Endurance, 15.5V"
MotorPropWatts = MotorPropAmps * MotorPropVolts
#MotorPropWatts2 = MotorPropAmps2 * MotorPropVolts2
Coefficients = np.polyfit(MotorPropThrust, MotorPropWatts, 2)
#Coefficients2 = np.polyfit(MotorPropThrust2, MotorPropWatts2, 2)
fig, ax1 = plt.subplots(figsize=(7,6))
fig.suptitle(MotorPropTitle)
plt.xlabel('Thrust [g]')
plt.xlim((0,1500))
plt.ylim((0,300))
plt.grid()
x = np.linspace(0,MotorPropThrust.max(),100)
y = Coefficients[0] * x * x + Coefficients[1] * x + Coefficients[2]
ax1.plot(x,y, color='#0000ff')
#x2 = np.linspace(0,MotorPropThrust2.max(),100)
#y2 = Coefficients2[0] * x2 * x2 + Coefficients2[1] * x2 + Coefficients2[2]
#ax1.plot(x2,y2, color='#8888ff')
plt.scatter(MotorPropThrust, MotorPropWatts, s=30, c='#0000ff')
#plt.scatter(MotorPropThrust2, MotorPropWatts2, s=30, c='#8888ff')
ax1.set_ylabel('Electrical power [W]', color='#000088')
for tl in ax1.get_yticklabels():
tl.set_color('#000088')
ax2 = ax1.twinx()
ye = x/y
ax2.plot(x,ye,color='#880000')
#ye2 = x2/y2
#ax2.plot(x2,ye2,color='#ff4444')
ax2.set_ylabel('Efficiency [g/W]', color='#880000')
for tl in ax2.get_yticklabels():
tl.set_color('#880000')
plt.savefig(InterpolatedToFile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment