# Create a Controller for a Lathe by Approximating the Time Delays

#### The force on the cutting tool in a lathe depends on the cutting depth from the previous rotation of the work piece. This can be modeled as a internal delay in the system.

 In[1]:= Xlathe = StateSpaceModel[ 10. (x^\[Prime]\[Prime])[t] == -100 x[t] - Derivative[1][x][t] - 200 (f[t] + x[t] - x[t - 1]), {x[t], x'[t]}, {f[t]}, x[t], t]
 Out[1]=

#### The uncontrolled system is unstable.

 In[2]:= Xlathe = StateSpaceModel[ 10. (x^\[Prime]\[Prime])[t] == -100 x[t] - Derivative[1][x][t] - 200 (f[t] + x[t] - x[t - 1]), {x[t], x'[t]}, {f[t]}, x[t], t]; OutputResponse[lathe, DiracDelta[t - 1], {t, 0, 5}]; Plot[%, {t, 0, 5}]
 Out[2]=

#### Creating a delay-free approximation for a time-delay system allows for all of the standard controller design techniques.

 In[3]:= XlatheApprox = SystemsModelDelayApproximate[lathe, 3]
 Out[3]=

#### Design an estimator-regulator by moving the unstable open-loop poles.

 In[4]:= Xopenlooppoles = Eigenvalues[Normal[latheApprox][[1]]]; l = EstimatorGains[latheApprox, Join[Drop[Sort[openlooppoles], -2], {-4 + I, -4 - I}]]; k = StateFeedbackGains[latheApprox, Join[Drop[Sort[openlooppoles], -2], {-4 + I, -4 - I}]]; controller = EstimatorRegulator[latheApprox, {l, k}];

#### The closed-loop system response is stable.

 In[5]:= XclosedloopLathe = SystemsModelFeedbackConnect[lathe, controller];
 In[6]:= XclosedloopLathe = SystemsModelFeedbackConnect[lathe, controller];; OutputResponse[closedloopLathe, DiracDelta[t - 1], {t, 0, 20}]; Plot[%, {t, 0, 20}]
 Out[6]=