%% ORR - lab 7 - Time-optimal control
% The topic of this' week seminar is time-optimal control and the associated implementation issues. Specifically, we will implement the time-optimal control law for the input constrained double integrator system. The goal is to get the double integrator system to the origin. Recall that the double integrator system is described by the following state-space model:
% \left\lbrack \begin{array}{c}
% \dot{y} \left(t\right)\\
% \dot{v} \left(t\right)
% \end{array}\right\rbrack =\left\lbrack \begin{array}{cc}
% 0 & 1\\
% 0 & 0
% \end{array}\right\rbrack \left\lbrack \begin{array}{c}
% y\left(t\right)\\
% v\left(t\right)
% \end{array}\right\rbrack +\left\lbrack \begin{array}{c}
% 0\\
% 1
% \end{array}\right\rbrack u\left(t\right),\;\;\;\;\;u\left(t\right)\in \left\lbrack -1,1\right\rbrack \ldotp
% As derived in the lecture notes, the time-optimal control law for this partcular case is
% u\left(t\right)=\mathrm{sgn}\left(-\frac{1}{2}v\left(t\right)|v\left(t\right)|-y\left(t\right)\right)\ldotp
% Your task for this seminar is to implement this optimal control law in Simulink and simulate the response of the closed loop. Answer the following questions:
% Does the naive implementation (meaning, without any hacks and heuristics) work? Why not?
% Can you come up with a solution? Try to somehow approximate the optimal switching law by something more realizable. If you want to right away use a more systematic approach, you can implement a so-called Proximate Time-Optimal Servomechanism (PTOS) method [1].
% You can use the attached Simulink model in which the double integrator system is already implemented.
%% Motivational side note
% The problem of getting the double integrator system to the origin may seem to be somewhat artificial and useless. Nevertheless, that would be a wrong impression. First of all, one can easily bring the double integrator system to a reference position r\left(t\right) simply by using y_r \left(t\right)=y\left(t\right)-r\left(t\right) in place of y\left(t\right) in the control law. Second, frictionless mechanical systems can often be described by the double integrator model. For instance, if you have a motor with a torque controller--you set a reference torque and the motor almost immediately generates it--then the dynamics of the load attached to the motor is described by the double integrator model (again, if the friction is negligible). In other words, getting the double integrator to the origin as quickly as possible may actually be the same problem as rotating a shaft of a motor to a given angle as quickly as possible.
% If you are still not impressed, check this video where the world record in solving the Rubik's cube is recorded. The robot solves the Rubik's cube under 400 ms. Such an amazing speed was possible only because the authors of the robot used time-optimal control. In fact, they used quite a similar approach to the one you are about to practice. You can find the details about the controller they used here.
%
%
% [1] WORKMAN, Michael L.; KOSUT, Robert L.; FRANKLIN, Gene F. Adaptive proximate time-optimal servomechanisms: Continuous time case. In: 1987 American Control Conference. IEEE, 1987. p. 589-594.