Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another initial fit of HI and LO coils #91

Merged
merged 1 commit into from
Dec 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions optimization/HIData.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Voltage,Current,Speed,Torque,Efficiency
131,0.41,739,0,0
131,0.73,731,0.6,45.7
131,2,724,2.7,78.3
131,3,719,4.4,84.2
131,4,713,6,87.2
131,5,707,7.9,88.9
131,6,703,9.6,89.9
131,8,692,13.1,90.7
131,10,683,16.7,91.3
131,12,673,20.4,91.5
131,14,664,24.2,91.8
131,16,657,57.9,91.5
131,18,649,31.7,91.4
131,20,641,35.5,90.9
131,25,625,44.9,89.7
131,30,611,54,88
17 changes: 17 additions & 0 deletions optimization/LOData.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Voltage,Current,Speed,Torque,Efficiency
131,0.34,638,0,0
131,0.63,637,0.6,50.1
131,2,630,3.2,81.8
131,3,624,5.3,87.9
131,4,619,7.3,90.4
131,5,614,9.4,91.9
131,6,610,11.4,92.3
131,8,599,15.4,92.3
131,10,590,19.6,92.4
131,12,582,23.8,92.4
131,14,573,28.3,92.5
131,16,566,32.6,92.5
131,18,559,36.9,91.5
131,20,552,41.2,91
131,25,537,52.1,89.5
131,30,524,62.6,87.4
51 changes: 51 additions & 0 deletions optimization/motor_efficiency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import argparse
import math
import matplotlib.pyplot as plt
import pandas as pd
from sklearn import linear_model

class MotorEfficiency:

def __init__(self, coil):
self.coil = coil
dataset = pd.read_csv(coil + 'Data.csv')

# let us determine relationship between speed and torque with voltage*current
# we will use this predicted value in place of actual current and voltage

x = dataset[['Speed', 'Torque']]
y = dataset['Voltage'] * dataset['Current']
regr = linear_model.LinearRegression()
regr.fit(x, y)

self.speed_k = regr.coef_[0]
self.torque_k = regr.coef_[1]
self.c = regr.intercept_

def calc_efficiency(self, speed, torque):
# formula: efficiency (%) = [pi/30 * speed * torque] / [voltage * current] * 100
return (math.pi/30 * speed * torque) / (self.speed_k * speed + self.torque_k * torque + self.c) * 100

def graph_default(self):
dataset = pd.read_csv(self.coil + 'Data.csv')
dataset['CalcEfficiency'] = dataset.apply(lambda x: self.calc_efficiency(x.Speed, x.Torque), axis=1)

plt.scatter(dataset.index, dataset['Efficiency'], color='blue', label='True')
plt.scatter(dataset.index, dataset['CalcEfficiency'], color='red', label='Calculated')
plt.legend()
plt.title("Efficiency Calculation Comparions (" + self.coil + " Coil)")
plt.xlabel("Datapoint #")
plt.ylabel("Efficiency (%)")
plt.show()

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="See coil fit graphs")
parser.add_argument('-c', '--coil', help='Select HI or LO coil', default="LO")
args = parser.parse_args()

if args.coil.upper() != "LO" and args.coil.upper() != "HI":
print("Choose HI or LO please")
else:
motor_efficiency_curve = MotorEfficiency(args.coil.upper())
motor_efficiency_curve.graph_default()