Commit fa2497ae authored by Chetan Sharma's avatar Chetan Sharma
Browse files

Saving progress

parent 61bc7546
...@@ -9,37 +9,24 @@ ...@@ -9,37 +9,24 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "ename": "AttributeError",
"output_type": "stream", "evalue": "Can't get attribute 'RawDataPacket' on <module '__main__'>",
"text": [ "output_type": "error",
"0.003175\n" "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m~/anaconda3/envs/ampd/lib/python3.8/shelve.py\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 110\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 111\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcache\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 112\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mKeyError\u001b[0m: '6'",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-2-aae045e25021>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mshelve\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'results'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mdb\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mtest_name\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mTEST_NAMES\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 15\u001b[0;31m \u001b[0mresults\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0mdb\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mtest_name\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 16\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[0mdata_points\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdecompose_packet\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresults\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/anaconda3/envs/ampd/lib/python3.8/shelve.py\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 112\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 113\u001b[0m \u001b[0mf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mBytesIO\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mencode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkeyencoding\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 114\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mUnpickler\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mload\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 115\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwriteback\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 116\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcache\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mAttributeError\u001b[0m: Can't get attribute 'RawDataPacket' on <module '__main__'>"
] ]
},
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f9bf7983e50>]"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD7CAYAAABjVUMJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nO3deXwV9b3/8deHhAQIOwRlXwSVRdYj4FK91qq4opUqahV/YnGj1VZtqa0tUu+96q21KlZFsUVQQFyxrVpbtNVqMQmLLAKGiBD2NUAwkOXz++MMNg2BHCAnk5Pzfj4e53HOmfnO5DPDYd7fmTlnxtwdERFJPvXCLkBERMKhABARSVIKABGRJKUAEBFJUgoAEZEkpQAQEUlSMQWAmQ0zs+Vmlmtm4yoZn25mM4Pxc82sSzC8i5l9ZWYLgsdT5aYZZGaLgmkeMzOrroUSEZGqVRkAZpYCPAGcD/QCrjKzXhWajQa2u3t34BHgwXLjVrp7/+Bxc7nhTwJjgB7BY9iRL4aIiByu1BjaDAZy3T0PwMxmAMOBpeXaDAfGB69fBiYeqkdvZm2Bpu7+cfD+eeBS4K1DFdK6dWvv0qVLDCWLiMh+OTk5W9w9s+LwWAKgPbCm3Pt8YMjB2rh7iZkVAK2CcV3NbD6wE/i5u38QtM+vMM/2VRXSpUsXsrOzYyhZRET2M7MvKxseSwBU1pOveP2Ig7VZD3Ry961mNgh43cx6xzjP6IzNxhA9VESnTp1iKFdERGIRy0ngfKBjufcdgHUHa2NmqUAzYJu773X3rQDungOsBI4P2neoYp4E001y94i7RzIzD9iDERGRIxRLAGQBPcysq5mlASOB2RXazAZGBa9HAHPc3c0sMziJjJl1I3qyN8/d1wO7zGxocK7gOuCNalgeER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R3NPA+QLAGQD3Qs974DB+5Cft0m2M1sBmw71LRmVp/oxv8Fd381LpXXnHiso9OAS8xsFdHd3G+a2bR4FF9D4rGO8oF8d9+/9/gy0UBIVPFYR98CvnD3ze5eDLwKnBqX6mvG0ayjQ82zQxXzPECyBEAW0MPMuppZGtGTKrMrtJkNjApejwDmBMfSZgMjg7PyXYEewCfBMcvJwGfu/psaWYr4qvZ15O4/dfcO7t4lmN8cd0/knls81tEGYI2ZnRBMczawNN4LEkfVvo6IHvoZamaNgv93ZxM955aojmYdVcrd1wO7zGxosI6uA96ospKwz4jX1AO4gOg3dVYCPwuGTQAuCV43AGYRPfH0CdCt3LQ/C6ZbTnBmneiZeAc+BRYEjwvCXs7atI4qzPu/SPBvAcVrHQH9gezgs/Q60CLs5ayF6+g+YBmwGJgKpIe9nCGuo1VE9wZ2E+359wqGR4L1sxKYSPBD30M99EtgEZEklSyHgEREpAIFgIhIklIAiIgkKQWAiEiSUgCIiCQpBYCISJJSAIiIJCkFgIhIkvr/+NRz8TwE55UAAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
} }
], ],
"source": [ "source": [
...@@ -48,7 +35,7 @@ ...@@ -48,7 +35,7 @@
"import shelve\n", "import shelve\n",
"import logging\n", "import logging\n",
"import queue\n", "import queue\n",
"from collect_data import DataPoint, RawDataPacket\n", "# from collect_data import DataPoint, RawDataPacket\n",
"from matplotlib import pyplot as plt\n", "from matplotlib import pyplot as plt\n",
"from scipy.signal import medfilt\n", "from scipy.signal import medfilt\n",
"\n", "\n",
......
from ml import LinearModel
from fake_cut import Fake_Cut
from objects import EndMill, Conditions
PARAMS = [858494934.9591976, -696.3150933941946, 858494934.9591976, -696.3150933941946]
# ERROR = [0.01, 0.01]
# NOISE = [0.1, 0.1]
ERROR = [0, 0]
NOISE = [0, 0]
CONDITIONS = Conditions(1e-3, 3.175e-3, 5e-3, 5000, EndMill(3, 3.175e-3, 3.175e-3, 10e-3, 10e-3))
model = LinearModel()
cut = Fake_Cut(PARAMS, ERROR, NOISE)
data = cut.cut(CONDITIONS)
model.ingest_datum(data)
print("{0:.20f}".format(model.params[1]))
\ No newline at end of file
...@@ -62,10 +62,11 @@ class Cut: ...@@ -62,10 +62,11 @@ class Cut:
self._logger.info("Layer prepared for clearing") self._logger.info("Layer prepared for clearing")
def cut(self, W, f_r, w): def cut(self, conditions):
""" """
Performs a stroke of facing. Returns a data blob. Performs a stroke of facing. Returns a data blob.
""" """
_, W, f_r, w, _ = conditions.unpack()
X_START = x_cut - self.endmill.r_c + W X_START = x_cut - self.endmill.r_c + W
if X_START > self.X_END: if X_START > self.X_END:
raise MachineCrash("Cutting too far in X direction: X = " + str(X_START)) raise MachineCrash("Cutting too far in X direction: X = " + str(X_START))
......
from models import T_lin, F_lin
from objects import Conditions, Data
import numpy as np
class Fake_Cut:
def __init__(self, params, error, noise):
"""
Args:
params: list of format [K_tc, K_te, K_rc, K_re]
error: list of standard deviations of format [o_T, o_Fy]. Simulates the sensor being "wrong" sometimes.
error: list of standard deviations of format [o_T, o_Fy]. Simulates the sensor being noisy.
"""
self.params = params
self.error = error
self.noise = noise
def cut(self, conditions : Conditions):
# use prediction as output
T = T_lin(conditions, *self.params[:2])
_, Fy = F_lin(conditions, *self.params)
# add sensor error
T_error = np.random.normal(T, self.error[0])
Fy_error = np.random.normal(Fy, self.error[1])
# add sensor noise
T_noisy = np.random.normal(T_error, self.noise[0], (100))
Fy_noisy = np.random.normal(Fy_error, self.noise[1], (100))
# generate fake times
t = np.linspace(0, 1, 100)
# return fake reading
return Data(*conditions.unpack(), np.array([t, T_noisy]), np.stack([t, Fy_noisy]))
\ No newline at end of file
...@@ -5,7 +5,7 @@ from sklearn import linear_model ...@@ -5,7 +5,7 @@ from sklearn import linear_model
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
from models import T_lin, F_lin, T_x_vector, Fy_x_vector from models import T_lin, F_lin, T_x_vector, Fy_x_vector
from objects import Data, Reading, EndMill, Prediction from objects import Data, Conditions, EndMill, Prediction
class Model(abc.ABC): class Model(abc.ABC):
""" """
...@@ -40,19 +40,21 @@ class LinearModel(Model): ...@@ -40,19 +40,21 @@ class LinearModel(Model):
self.training_T_y = list() self.training_T_y = list()
self.training_Fy_x = list() self.training_Fy_x = list()
self.training_Fy_y = list() self.training_Fy_y = list()
self.regressor_T = linear_model.Lasso(fit_intercept = False, warm_start=True) self.regressor_T = linear_model.LinearRegression(fit_intercept = False)
self.regressor_Fy = linear_model.Lasso(fit_intercept = False, warm_start=True) self.regressor_Fy = linear_model.LinearRegression(fit_intercept = False)
self.params = np.array([0,0,0,0]) self.params = np.array([0,0,0,0])
def ingest_datum(self, datum): def ingest_datum(self, datum):
# decompose # decompose
D, W, f_r, w, endmill, Ts, Fys = datum.D, datum.W, datum.f_r, datum.w, datum.endmill, datum.Ts, datum.Fys _, _, _, _, _, Ts, Fys = datum.unpack()
R, N = endmill.R, endmill, N T, Fy = np.median(Ts[1, :]), np.median(Fys[1, :])
T, Fy = np.median(Ts[:, 1]), np.median(Fys[:, 1])
# get linear coefficients # get linear coefficients
T_x = T_x_vector(D, N, R, W, f_r, w) T_x = T_x_vector(datum.conditions())
Fy_x = Fy_x_vector(D, N, R, W, f_r, w) Fy_x = Fy_x_vector(datum.conditions())
print("T", T)
print("coef times real K_tc", T_x[1] * 858494934.9591976)
# add to training set # add to training set
self.training_T_x.append(T_x) self.training_T_x.append(T_x)
...@@ -68,24 +70,25 @@ class LinearModel(Model): ...@@ -68,24 +70,25 @@ class LinearModel(Model):
# calculate best fit from data # calculate best fit from data
self.regressor_T.fit(self.training_T_x, self.training_T_y) self.regressor_T.fit(self.training_T_x, self.training_T_y)
K_tc, K_te = self.regressor.coef_ K_tc, K_te = self.regressor_T.coef_
print(K_tc, K_te)
self.params[0], self.params[1] = K_tc, K_te self.params[0], self.params[1] = K_tc, K_te
# transform Fy into a smaller linear problem and fit # transform Fy into a smaller linear problem and fit
intercepts = training_Fy_x @ np.array([K_tc, K_te, 0, 0])[np.newaxis].T intercepts = training_Fy_x @ np.array([K_tc, K_te, 0, 0])[np.newaxis].T
training_Fy_y_no_intercepts = training_Fy_y - intercepts training_Fy_y_no_intercepts = training_Fy_y - intercepts
self.regressor_Fy.fit(training_Fy_x[:, 2:], training_Fy_y_no_intercepts) self.regressor_Fy.fit(training_Fy_x[:, 2:], training_Fy_y_no_intercepts)
K_rc, K_re = self.regressor_Fy.coef_
self.params[0], self.params[1] = K_rc, K_re
def predict_one(self, conditions): def predict_one(self, conditions):
# decompose # decompose
D, W, f_r, w, endmill = conditions.D, conditions.W, conditions.f_r, conditions.w, conditions.endmill
R, N = endmill.R, endmill, N
# evaluate # evaluate
T = T_lin(D, N, R, W, f_r, w, self.params[0], self.params[1]) T = T_lin(conditions, *self.params[:2])
F = F_lin(D, N, R, W, f_r, w, *self.params) F = F_lin(conditions, *self.params)
# repack and return # repack and return
return Prediction(D, W, f_r, w, endmill, T, F) return Prediction(conditions, T, F)
import numpy as np import numpy as np
def calc_h_a(R, W, f_t): from objects import Conditions, Data, Prediction, MachineChar
def calc_f_t(conditions : Conditions):
D, W, f_r, w, endmill = conditions.unpack()
N = endmill.N
return (2 * np.pi * f_r) / (N * w)
def calc_h_a(conditions : Conditions):
D, W, f_r, w, endmill = conditions.unpack()
R = endmill.r_c
f_t = calc_f_t(conditions)
phi_st = np.pi - np.arccos(1 - W / R) phi_st = np.pi - np.arccos(1 - W / R)
phi_ex = np.pi phi_ex = np.pi
return -f_t * (np.cos(phi_ex) - np.cos(phi_st)) / (phi_ex - phi_st) return -f_t * (np.cos(phi_ex) - np.cos(phi_st)) / (phi_ex - phi_st)
def calc_f_t(N, f_r, w):
return (2 * np.pi * f_r) / (N * w)
# exponential models, account for strange decrease in cutting forces as chip thickness increases. # exponential models, account for strange decrease in cutting forces as chip thickness increases.
def T_exp_lin(D, N, R, W, f_r, w, K_TC, K_te, p): def T_exp_lin(conditions : Conditions, K_TC, K_te, p):
f_t = calc_f_t(N, f_r, w) D, W, f_r, w, endmill = conditions.unpack()
h_a = calc_h_a(R, W, f_t) N, R, _, _, _ = endmill.unpack()
f_t = calc_f_t(conditions)
h_a = calc_h_a(conditions)
K_tc = K_TC * h_a ** -p K_tc = K_TC * h_a ** -p
return ((D * N) * (K_te * R * np.arccos(1 - W/R) + K_tc * W * f_t)) / (2 * np.pi) return ((D * N) * (K_te * R * np.arccos(1 - W/R) + K_tc * W * f_t)) / (2 * np.pi)
def F_exp_lin(D, N, R, W, f_r, w, K_TC, K_te, K_RC, K_re, p, q): def F_exp_lin(conditions : Conditions, K_TC, K_te, K_RC, K_re, p, q):
f_t = calc_f_t(N, f_r, w) D, W, f_r, w, endmill = conditions.unpack()
h_a = calc_h_a(R, W, f_t) N, R, _, _, _ = endmill.unpack()
f_t = calc_f_t(conditions)
h_a = calc_h_a(conditions)
K_tc = K_TC * h_a ** -p K_tc = K_TC * h_a ** -p
K_rc = K_RC * h_a ** -q K_rc = K_RC * h_a ** -q
Fx = - ((D*N*(K_tc*W**2*f_t + K_rc*W**(3/2)*f_t*(2*R - W)**(1/2)))/4 - (D*N*R*(2*K_tc*W*f_t - 2*K_re*W + 2*K_te*W**(1/2)*(2*R - W)**(1/2) + K_rc*W**(1/2)*f_t*(2*R - W)**(1/2)))/4)/(R**2*np.pi) - (D*K_rc*N*f_t*np.arccos((R - W)/R))/(4*np.pi) Fx = - ((D*N*(K_tc*W**2*f_t + K_rc*W**(3/2)*f_t*(2*R - W)**(1/2)))/4 - (D*N*R*(2*K_tc*W*f_t - 2*K_re*W + 2*K_te*W**(1/2)*(2*R - W)**(1/2) + K_rc*W**(1/2)*f_t*(2*R - W)**(1/2)))/4)/(R**2*np.pi) - (D*K_rc*N*f_t*np.arccos((R - W)/R))/(4*np.pi)
...@@ -26,36 +38,42 @@ def F_exp_lin(D, N, R, W, f_r, w, K_TC, K_te, K_RC, K_re, p, q): ...@@ -26,36 +38,42 @@ def F_exp_lin(D, N, R, W, f_r, w, K_TC, K_te, K_RC, K_re, p, q):
# linear models, easier to fit and more simple # linear models, easier to fit and more simple
def T_lin(D, N, R, W, f_r, w, K_tc, K_te): def T_lin(conditions, K_tc, K_te):
f_t = calc_f_t(N, f_r, w) D, W, f_r, w, endmill = conditions.unpack()
N, R, _, _, _ = endmill.unpack()
f_t = calc_f_t(conditions)
return ((D * N) * (K_te * R * np.arccos(1 - W/R) + K_tc * W * f_t)) / (2 * np.pi) return ((D * N) * (K_te * R * np.arccos(1 - W/R) + K_tc * W * f_t)) / (2 * np.pi)
def F_lin(D, N, R, W, f_r, w, K_tc, K_te, K_rc, K_re): def F_lin(conditions, K_tc, K_te, K_rc, K_re):
f_t = calc_f_t(N, f_r, w) D, W, f_r, w, endmill = conditions.unpack()
N, R, _, _, _ = endmill.unpack()
f_t = calc_f_t(conditions)
Fx = - ((D*N*(K_tc*W**2*f_t + K_rc*W**(3/2)*f_t*(2*R - W)**(1/2)))/4 - (D*N*R*(2*K_tc*W*f_t - 2*K_re*W + 2*K_te*W**(1/2)*(2*R - W)**(1/2) + K_rc*W**(1/2)*f_t*(2*R - W)**(1/2)))/4)/(R**2*np.pi) - (D*K_rc*N*f_t*np.arccos((R - W)/R))/(4*np.pi) Fx = - ((D*N*(K_tc*W**2*f_t + K_rc*W**(3/2)*f_t*(2*R - W)**(1/2)))/4 - (D*N*R*(2*K_tc*W*f_t - 2*K_re*W + 2*K_te*W**(1/2)*(2*R - W)**(1/2) + K_rc*W**(1/2)*f_t*(2*R - W)**(1/2)))/4)/(R**2*np.pi) - (D*K_rc*N*f_t*np.arccos((R - W)/R))/(4*np.pi)
Fy = (D*K_tc*N*f_t*np.arccos((R - W)/R))/(4*np.pi) - ((D*N*(K_rc*W**2*f_t - K_tc*W**(3/2)*f_t*(2*R - W)**(1/2)))/4 - (D*N*R*(2*K_te*W + 2*K_rc*W*f_t + 2*K_re*W**(1/2)*(2*R - W)**(1/2) - K_tc*W**(1/2)*f_t*(2*R - W)**(1/2)))/4)/(R**2*np.pi) Fy = (D*K_tc*N*f_t*np.arccos((R - W)/R))/(4*np.pi) - ((D*N*(K_rc*W**2*f_t - K_tc*W**(3/2)*f_t*(2*R - W)**(1/2)))/4 - (D*N*R*(2*K_te*W + 2*K_rc*W*f_t + 2*K_re*W**(1/2)*(2*R - W)**(1/2) - K_tc*W**(1/2)*f_t*(2*R - W)**(1/2)))/4)/(R**2*np.pi)
return np.array([Fx, Fy]) return np.array([Fx, Fy])
# coefficient calculators for linear regression # coefficient calculators for linear regression
def T_x_vector(D, N, R, W, f_r, w): def T_x_vector(conditions : Conditions):
""" """
Outputs vector that corresponds to coefficients in order: Outputs vector that corresponds to coefficients in order:
K_tc, K_te K_tc, K_te
""" """
f_t = calc_f_t(N, f_r, w) D, W, f_r, w, endmill = conditions.unpack()
K_tc_C = (D * N * W * f_t) / (2 * np.pi) N, R, _, _, _ = endmill.unpack()
K_te_C = (D * N * R * np.arccos(1 - (W / R))) / (2 * np.pi) f_t = calc_f_t(conditions)
return [K_tc_C, K_te_C] return[(D * N * W * f_t) / (2 * np.pi), (D * N * R * np.arccos(1 - (W / R))) / (2 * np.pi)]
def Fy_x_vector(D, N, R, W, f_r, w): def Fy_x_vector(conditions : Conditions):
f_t = calc_f_t(N, f_r, w) D, W, f_r, w, endmill = conditions.unpack()
N, R, _, _, _ = endmill.unpack()
f_t = calc_f_t(conditions)
return [(D*N*f_t*(W**(3/2)*(2*R - W)**(1/2) + R**2*np.arccos((R - W)/R) - R*W**(1/2)*(2*R - W)**(1/2)))/(4*R**2*np.pi), (D*N*W)/(2*R*np.pi), (D*N*W*f_t*(2*R - W))/(4*R**2*np.pi), (D*N*W**(1/2)*(2*R - W)**(1/2))/(2*R*np.pi)] return [(D*N*f_t*(W**(3/2)*(2*R - W)**(1/2) + R**2*np.arccos((R - W)/R) - R*W**(1/2)*(2*R - W)**(1/2)))/(4*R**2*np.pi), (D*N*W)/(2*R*np.pi), (D*N*W*f_t*(2*R - W))/(4*R**2*np.pi), (D*N*W**(1/2)*(2*R - W)**(1/2))/(2*R*np.pi)]
def deflection_load(D_a, F, endmill, E_e = 650e9): def deflection_load(D_a, prediction : Prediction, E_e = 650e9):
""" """
Calculates ratio of tool deflection to allowed deflection. Calculates ratio of tool deflection to allowed deflection.
Uses FEA model described in doi:10.1016/j.ijmachtools.2005.09.009. Uses FEA model described in doi:10.1016/j.ijmachtools.2005.09.009.
...@@ -67,11 +85,10 @@ def deflection_load(D_a, F, endmill, E_e = 650e9): ...@@ -67,11 +85,10 @@ def deflection_load(D_a, F, endmill, E_e = 650e9):
Returns: Returns:
Ratio of tool deflection to allowed deflection Ratio of tool deflection to allowed deflection
""" """
r_c = endmill.r_c D, W, f_r, w, endmill, T, F = prediction.unpack()
r_s = endmill.r_s F = np.norm(F)
l_c = endmill.l_c N, r_c, r_s, l_c, l_s = endmill.unpack()
l_s = endmill.l_s
N = endmill.N
# prepare variables, this must be done since the FEA model has arbitrary constants defined for certain units # prepare variables, this must be done since the FEA model has arbitrary constants defined for certain units
d_1 = r_c * 2 * 1e3 # convert to diameter in mm d_1 = r_c * 2 * 1e3 # convert to diameter in mm
d_2 = r_s * 2 * 1e3 d_2 = r_s * 2 * 1e3
...@@ -98,7 +115,7 @@ def deflection_load(D_a, F, endmill, E_e = 650e9): ...@@ -98,7 +115,7 @@ def deflection_load(D_a, F, endmill, E_e = 650e9):
D_m = C * (F / E) * ((l_1 ** 3 / d_1 ** 4) + ((l_2 ** 3 - l_1 ** 3) / d_2 ** 4)) ** G * 1e-3 D_m = C * (F / E) * ((l_1 ** 3 / d_1 ** 4) + ((l_2 ** 3 - l_1 ** 3) / d_2 ** 4)) ** G * 1e-3
return D_m / D_a return D_m / D_a
def failure_prob_milling(F, T, endmill, D, roughing = False, m = 4, o = 1500e6, a_c = 0.8): def failure_prob_milling(prediction : Prediction, roughing = False, m = 4, o = 1500e6, a_c = 0.8):
""" """
Calculates failure probability according to Weibull distribution. Method adapted from https://doi.org/10.1016/S0007-8506(07)62072-1 Calculates failure probability according to Weibull distribution. Method adapted from https://doi.org/10.1016/S0007-8506(07)62072-1
Args: Args:
...@@ -113,11 +130,10 @@ def failure_prob_milling(F, T, endmill, D, roughing = False, m = 4, o = 1500e6, ...@@ -113,11 +130,10 @@ def failure_prob_milling(F, T, endmill, D, roughing = False, m = 4, o = 1500e6,
Returns: Returns:
Probability of failure Probability of failure
""" """
# establish base variables D, W, f_r, w, endmill, T, F = prediction.unpack()
r_c = endmill.r_c F = np.norm(F)
r_s = endmill.r_s N, r_c, r_s, l_c, l_s = endmill.unpack() # establish base variables
l_c = endmill.l_c
l_s = endmill.l_s
r_ceq = r_c * a_c # equivalent cutter radius r_ceq = r_c * a_c # equivalent cutter radius
I_ceq = np.pi / 4 * r_ceq ** 4 # equivalent cutter 2nd inertia I_ceq = np.pi / 4 * r_ceq ** 4 # equivalent cutter 2nd inertia
I_s = np.pi / 4 * r_s ** 4 # shank 2nd inertia I_s = np.pi / 4 * r_s ** 4 # shank 2nd inertia
...@@ -137,7 +153,7 @@ def failure_prob_milling(F, T, endmill, D, roughing = False, m = 4, o = 1500e6, ...@@ -137,7 +153,7 @@ def failure_prob_milling(F, T, endmill, D, roughing = False, m = 4, o = 1500e6,
return failure_prob return failure_prob
def motor_torque_load(T_m, w, K_T, R_w, V_max, I_max): def motor_torque_load(prediction : Prediction, machinechar : MachineChar):
""" """
Calculates ratio of current motor torque to max motor torque. Calculates ratio of current motor torque to max motor torque.
Args: Args:
...@@ -150,12 +166,16 @@ def motor_torque_load(T_m, w, K_T, R_w, V_max, I_max): ...@@ -150,12 +166,16 @@ def motor_torque_load(T_m, w, K_T, R_w, V_max, I_max):
Returns: Returns:
Ratio of current motor torque to max achievable torque Ratio of current motor torque to max achievable torque
""" """
_, _, _, w, _, T, _ = prediction.unpack()
r_e, K_T, R_w, V_max, I_max, T_nom, _ = machinechar.unpack()
w_m = w * r_e
T_m = (T + T_nom) / r_e
# store K_V for convenience # store K_V for convenience
K_V = 1 / K_T K_V = 1 / K_T
# max torque is either determined by max current that can be supplied or max current achievable given winding resistance and whatnot # max torque is either determined by max current that can be supplied or max current achievable given winding resistance and whatnot
return T_m / min(K_T * I_max, (V_max - K_V * w) / R_w) return T_m / min(K_T * I_max, (V_max - K_V * w_m) / R_w)
def motor_speed_load(T_m, w, K_T, R_w, V_max): def motor_speed_load(prediction : Prediction, machinechar : MachineChar):
""" """
Calculates ratio of Calculates ratio of
Args: Args:
...@@ -167,11 +187,16 @@ def motor_speed_load(T_m, w, K_T, R_w, V_max): ...@@ -167,11 +187,16 @@ def motor_speed_load(T_m, w, K_T, R_w, V_max):
Returns: Returns:
Ratio of current motor speed to max achievable speed Ratio of current motor speed to max achievable speed
""" """
_, _, _, w, _, T, _ = prediction.unpack()
r_e, K_T, R_w, V_max, I_max, T_nom, _ = machinechar.unpack()
w_m = w * r_e
T_m = (T + T_nom) / r_e
# store K_V for convenience # store K_V for convenience
K_V = 1 / K_T K_V = 1 / K_T
# max speed is affected by winding resistive voltage drop along with backemf # max speed is affected by winding resistive voltage drop along with backemf
return w / (K_V * (V_max - T_m * R_w / K_T)) return w_m / (K_V * (V_max - T_m * R_w / K_T))
def optimality(D, W, f_r): def optimality(conditions : Conditions):
D, W, f_r, _, _ = conditions.unpack()
# returns MMR in units of m^3 / s # returns MMR in units of m^3 / s
return D * W * f_r return D * W * f_r
...@@ -2,20 +2,47 @@ import numpy as np ...@@ -2,20 +2,47 @@ import numpy as np
class EndMill: class EndMill:
def __init__(self, N, r_c, r_s, l_c, l_s): def __init__(self, N, r_c, r_s, l_c, l_s):
self.R = R
self.N = N self.N = N
self.r_c = r_c self.r_c = r_c
self.r_s = r_s self.r_s = r_s
self.l_c = l_c self.l_c = l_c
self.l_s = l_s self.l_s = l_s
def unpack(self):
return [self.N, self.r_c, self.r_s, self.l_c, self.l_s]
def __str__(self):
return str(self.unpack())
class MachineChar:
def __init__(self, r_e, K_T, R_w, V_max, I_max, T_nom, f_r_max):
self.r_e = r_e
self.K_T = K_T
self.R_w = R_w
self.V_max = V_max
self.I_max = I_max
self.T_nom = T_nom
self.f_r_max = f_r_max
def unpack(self):
return [self.r_e, self.K_T, self.R_w, self.V_max, self.I_max, self.T_nom]
def __str__(self):
return str(self.unpack())
class Conditions: class Conditions:
def __init__(self, D : float, W : float, f_r : float, w : float, endmill : EndMill): def __init__(self, D : float, W : float, f_r : float, w : float, endmill : EndMill):
self.D = D self.D = D
self.W = W self.W = W
self.f_r = f_r self.f_r = f_r
self.w = w self.w = w
self.endmill = endmill self.endmill = endmill
def unpack(self):
return [self.D, self.W, self.f_r, self.w, self.endmill]
def __str__(self):
return str(self.unpack())
class Data(Conditions): class Data(Conditions):
def __init__(self, D : float, W : float, f_r : float, w : float, endmill : EndMill, Ts : np.ndarray, Fys : np.ndarray): def __init__(self, D : float, W : float, f_r : float, w : float, endmill : EndMill, Ts : np.ndarray, Fys : np.ndarray):
...@@ -23,8 +50,20 @@ class Data(Conditions): ...@@ -23,8 +50,20 @@ class Data(Conditions):
self.Ts = Ts self.Ts = Ts
self.Fys = Fys self.Fys = Fys
def unpack(self):
return super(Data, self).unpack() + [self.Ts, self.Fys]
def conditions(self):
return Conditions(*super(Data, self).unpack())