\input{ccs_gyak_defs}
\author{Lecture 6}

\tikzstyle{block} = [draw, rectangle, minimum height=1em, minimum width=1em]
\tikzstyle{sum} = [draw, circle, node distance=1cm]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]


\begin{document}
\maketitle

\section[Block diagram algebra]{Block diagram algebra \color{blue} (Hatásvázlat algebra)}


\textbf{Resultant\footnote{ha valakinek van az ``eredő'' szóra értelmesebb fordítása, kérem írjon: \url{ppolcz@gmail.com}} transfer function computation \color{blue} (Eredő átviteli függvény számolása)}
\begin{cexamplew}{}\label{}

\begin{minipage}{0.60\textwidth}
    1. What is the resulting transfer function $G(s) = ?$ of $\longrightarrow$ \\
    {\color{blue} Mi az eredő átviteli függvény: $G(s)=$?} \\
\end{minipage}
\begin{minipage}{0.39\textwidth}
    \centering
    \begin{tikzpicture}[auto, node distance=1cm,>=latex']
        % We start by placing the blocks
        \node [coordinate, name=input] {};

        \node [sum, right of=input] (sum) {};
        %\node [sum2, right of=sum] (sum2) {};

        \node [block, right of=sum, node distance=1cm] (system1) {$\frac{1}{s+1}$};
        \node [coordinate, right of=system1] (bp1){};
        \node [block, right of=bp1, node distance=1cm] (system2) {$\frac{s+2}{s}$};

        \node [output, right of=system2] (output) {};

        \node [block, below of=system1] (system3) {$\frac{1}{s}$};


        % Once the nodes are placed, connecting them is easy.
        \draw [draw,->] (input) -- node {$u$} (sum);
        %\draw [draw,->] (sum) -- node{} (sum2);
        \draw [->] (sum) -- node {} (system1);
        \draw [->] (system2) -- node [name=y] {$y$}(output);
        \draw [->] (bp1) |- (system3);
        \draw [->] (bp1)|- (system2);
        \draw [-] (system1) |- (bp1);
        \draw [->] (system3) -| node[pos=0.99]{-}(sum);
    \end{tikzpicture}
\end{minipage}

\begin{pcb}{}
\begin{minipage}{0.3\textwidth}
    \centering
    THE RULE:
\end{minipage}
\begin{minipage}{0.23\textwidth}
    \centering
    \begin{tikzpicture}[auto, node distance=1cm,>=latex']
        % We start by placing the blocks
        \node [coordinate, name=input] {};

        \node [sum, right of=input] (sum) {};
        %\node [sum2, right of=sum] (sum2) {};

        \node [block, right of=sum, node distance=1cm] (system1) {$G_1(s)$};
        \node [coordinate, right of=system1] (bp1){};
        % \node [block, right of=bp1, node distance=1cm] (system2) {$\frac{s+2}{s}$};

        \node [output, right of=system1,node distance=1.5cm] (output) {};

        \node [block, below of=system1] (system3) {$G_2(s)$};

        % Once the nodes are placed, connecting them is easy.
        \draw [draw,->] (input) -- node {$u$} (sum);
        %\draw [draw,->] (sum) -- node{} (sum2);
        \draw [->] (sum) -- node {} (system1);
        \draw [->] (system1) -- node [name=y] {$y$}(output);
        \draw [->] (bp1) |- (system3);
        % \draw [->] (bp1)|- (system2);
        \draw [-] (system1) |- (bp1);
        \draw [->] (system3) -| node[pos=0.99]{-}(sum);
    \end{tikzpicture}
\end{minipage}\hfill
\begin{minipage}{0.43\textwidth}
    \begin{align}
        \begin{aligned}
            G_e(s)=\frac{G_1(s)}{1+G_1(s)\, G_2(s)}
        \end{aligned}
    \end{align}
\end{minipage}
\end{pcb}
$$G(s)=\frac{\frac{1}{s+1}\cdot \frac{s+2}{s}}{1+\frac{1}{s} \cdot \frac{1}{s+1}}=\frac{\frac{1}{s+1}}{\frac{s^2+s+1}{s(s+1)}} \cdot \frac{s+2}{s}=\frac{1}{s+1} \cdot \frac{s(s+1)}{s^2+s+1} \cdot \frac{s+2}{s}=\frac{s+2}{s^2+s+1}$$

2. Give a possible state space realization for this transfer function! \\
Controller form:
\begin{align}
    &G(s) = \frac{b_1 s + b_2}{s^2 + a_1 s + a_2}
    ~~~~\overset{\text{Ctrb N.F.}}{\implies}~~~~
    \begin{aligned}
        & A_c =
        \begin{bmatrix}
        -a_1 & -a_2 \\
        1 & 0
        \end{bmatrix}
        =
        \begin{bmatrix}
        -1 & -1 \\
        1 & 0
        \end{bmatrix}, ~~~
        B_c=\begin{bmatrix}
        1 \\
        0
        \end{bmatrix} \\
        & C_c=\begin{bmatrix}
        b_1 & b_2
        \end{bmatrix}
        =
        \begin{bmatrix}
        1 & 2
        \end{bmatrix}
    \end{aligned}
    \shortintertext{Observer form:}
    &G(s) = \frac{b_1 s + b_2}{s^2 + a_1 s + a_2}
    ~~~~\overset{\text{Obsv N.F.}}{\implies}~~~~
    \begin{aligned}
        &A_o=
        \begin{bmatrix}
        -a_1 & 1 \\
        -a_2 & 0
        \end{bmatrix}
        =
        \begin{bmatrix}
        -1 & 1 \\
        -1 & 0
        \end{bmatrix}, ~~~
        B_o=\begin{bmatrix}
        b_1 \\
        b_2
        \end{bmatrix}
        =
        \begin{bmatrix}
        1 \\
        2
        \end{bmatrix} \\
        &C_o=\begin{bmatrix}
        1 & 0
        \end{bmatrix}
    \end{aligned}
\end{align}

\noindent The next figure illustrates the behaviour of the system in case of the unit step function and a sinusoid input function. \\
\centering
\includegraphics[scale=0.3]{fig/gyak5_doboz_res.png}
\end{cexamplew}

\begin{cexamplew}{}\label{}


\begin{center}
\begin{tikzpicture}[auto, node distance=1cm,>=latex']
    % We start by placing the blocks
    \node [coordinate, name=input] {};

    \node [sum, right of=input] (sum) {};
    \node [sum, right of=sum] (sum2) {};

    \node [block, right of=sum2, node distance=1cm] (system) {$\frac1s$};
    \node [output, right of=system] (output) {};

    \node [coordinate, below of=system] (bp1) {};
    \node [coordinate, below of=bp1, node distance=0.5cm] (bp2){};

    % Once the nodes are placed, connecting them is easy.
    \draw [draw,->] (input) -- node {$u$} (sum);
    \draw [draw,->] (sum) -- node{} (sum2);
    \draw [->] (sum2) -- node {} (system);
    \draw [->] (system) -- node [name=y] {$y$}(output);
    \draw [-] (y) |- (bp1);
    \draw [->] (bp1) -| node[pos=0.99]{-}(sum2);
    \draw [-] (y) |- (bp2);
    \draw [->] (bp2) -| node[pos=0.99]{-}(sum);
\end{tikzpicture}
\end{center}
$$H(s)=\frac{1}{s}$$
What is the resulting transfer function $G(s) = ?$
$$G_0(s)=\frac{\frac{1}{s}}{1+\frac{1}{s}} = \frac{1}{s+1}$$
$$G_1(s)=\frac{\frac{1}{s+1}}{1+\frac{1}{s+1}} = \frac{1}{s+2}$$
\end{cexamplew}

\begin{cexamplew}{}\label{}

\begin{center}

\begin{tikzpicture}[auto, node distance=1cm,>=latex']
    % We start by placing the blocks
    \node [coordinate, name=input] {};
    \node [sum, right of=input] (sum) {};

    \node [block, right of=sum, node distance=1.2cm] (system) {$\frac{s+2}{s+1}$};
    \node [coordinate, right of=system, node distance=1.5cm] (output) {};
    \node [block, below of=system] (K) {$\frac{1}{s}$};

    % Once the nodes are placed, connecting them is easy.
    \draw [draw,->] (input) -- node {$u$} (sum);
    \draw [->] (sum) -- node {} (system);
    \draw [->] (system) -- node [name=y] {$y$}(output);
    \draw [->] (y) |- (K);
    \draw [->] (K) -| node[pos=0.99] {-} (sum);
\end{tikzpicture}
\end{center}
% $$H_1(s)= \quad H_2(s)=$$
What is the resulting transfer function $G(s) = ?$
$$G(s)=\frac{\frac{s+2}{s+1}}{1+\frac{1}{s}\cdot \frac{s+2}{s+1}}=\frac{s(s+2)}{s(s+1)+s+2}=\frac{s^2+2s}{s^2+2s+2}$$
\end{cexamplew}

\begin{qboxr}
    \textbf{Theoretical questions} (minimal computational effort is needed here)
    \medbreak

    \begin{example}{}
        Given the following transfer function: $H(s) = \frac{5 s^3 + 2 s^2 - s + 1}{s^4 + 4 s^2 - s^2 + 2s + 1}$.
        Determine whether $H(s)$ is stable or not!
    \end{example}
    \medbreak

    \begin{example}{}
        Compute the DC-Gain of $H(s) = \frac{s + 2}{s^4 + 3 s^2 + 10 s + 5}$ in \textbf{dB}.
    \end{example}
\end{qboxr}

\begin{qboxr}
    \begin{example}[]{\textbf{Computational problem}}
        Determine the transfer function $H_{y \to y_3}(s)$ of the following feedback system:
        \begin{center}
            \begin{tikzpicture}[auto, node distance=1cm,>=latex']
                % We start by placing the blocks
                \draw
                    node [coordinate, name=input] (r) {}
                    node [sum, right=of input] (sum1) {}
                    node [block, right=of sum1] (G1) {$G_1(s)$}
                    node [sum, right=of G1] (sum2) {}
                    node [block, right=of sum2] (G2) {$G_2(s)$}
                    node [block, right=of G2, node distance=1.5cm] (G3) {$G_3(s)$}
                    node [coordinate, right=of G3, node distance=1.5cm] (y3) {}
                    node [coordinate, above of=G1] (tmpup) {}
                    node [coordinate, below of=G2] (tmpdown) {}
                    ;

                \draw[->] (r) -- node {$r$} (sum1);
                \draw[->] (sum1) -- node {$u_1$} (G1);
                \draw[->] (G1) -- node {$y_1$} (sum2);
                \draw[->] (sum2) -- node {$u_2$} (G2);
                \draw[->] (G2) -- node[below] (i1) {$y_2$} (G3);
                \draw[->] (G3) -- node (i2) {$y_3$} (y3);
                \draw[->] (i2) |- (tmpdown) -| node[pos=0.95] {-} (sum2);
                \draw[->] (i1) |- (tmpup) -| node[pos=0.95] {-} (sum1);
            \end{tikzpicture}
        \end{center}
    \end{example}
\end{qboxr}

\newpage
\begin{cexamplew}{Simple negative feedback}\label{}
\begin{center}
\begin{tikzpicture}[auto, node distance=1cm,>=latex']
    % We start by placing the blocks
    \node [coordinate, name=input] {};

    \node [sum, right of=input] (sum) {};


    \node [block, right of=sum, node distance=1.2cm] (system1) {$H(s)$};
    \node [coordinate, right of=system1] (bp1){};
    \node [coordinate, below of=system1] (bp2) {$\frac{s+2}{s}$};

    \node [coordinate, right of=bp1] (output) {};


    % Once the nodes are placed, connecting them is easy.
    \draw [draw,->] (input) -- node {$u$} (sum);
    %\draw [draw,->] (sum) -- node{} (sum2);
    \draw [->] (sum) -- node {} (system1);
    \draw [->] (bp1) -- node [name=y] {$y$}(output);
    \draw [-] (bp1) |- (bp2);
    %\draw [->] (bp1)|- (system2);
    \draw [-] (system1) |- (bp1);
    \draw [->] (bp2) -| node[pos=0.99]{-}(sum);
\end{tikzpicture}
\end{center}
Transfer function:
\begin{align*}
Y(s) &= H(s)(U(s)-Y(s)) \\
Y(s)+H(s)Y(s) &= H(s)U(s) \\
(1+H(S))Y(s) &= H(s)U(s) \\
Y(s) &= \frac{H(s)}{1+H(s)}U(s) ~~ \implies ~~ G(s)=\frac{H(s)}{1+H(s)}
\end{align*}

%U-ra vonatkozó átvitel:
%$$H(s)=\frac{1}{1+H(s)}$$

Using this simple negative feedback, determine whether the system is stabilizable or not, if
\begin{enumerate}
\item $H(s)=\frac{1}{s}$
$$G(s)=\frac{\frac{1}{s}}{1+\frac{1}{s}}=\frac{1}{s+1}$$
\\
Yes, the system is stabilizable, since the resultant transfer function is stable.
\item $H(s)=\frac{1}{s-2}$
$$G(s)=\frac{\frac{1}{s-2}}{1+\frac{1}{s-2}}=\frac{1}{s-1}$$
\\
No, the system is not stabilizable.
\end{enumerate}
\end{cexamplew}

\begin{cexamplew}{}\label{}
\begin{center}
\begin{tikzpicture}[auto, node distance=1cm,>=latex']
    % We start by placing the blocks
    \node [coordinate, name=input] {};
    \node [sum, right of=input] (sum) {};

    \node [block, right of=sum, node distance=1.2cm] (system) {$H(s)$};
    \node [output, right of=system, node distance=1.5cm] (output) {};
    \node [block, below of=system] (K) {K};

    % Once the nodes are placed, connecting them is easy.
    \draw [draw,->] (input) -- node {$u$} (sum);
    \draw [->] (sum) -- node {} (system);
    \draw [->] (system) -- node [name=y] {$y$}(output);
    \draw [->] (y) |- (K);
    \draw [->] (K) -| node[pos=0.99] {-} (sum);
\end{tikzpicture}
\end{center}

Resulting transfer function:
$$G(s)=\frac{H(s)}{1+KH(s)}$$
$$H(s)=\frac{b(s)}{a(s)} \rightarrow G(s)=\frac{\frac{b(s)}{a(s)}}{1+K\frac{b(s)}{a(s)}}=\frac{b(s)}{a(s)+Kb(s)}$$

Using this negative feedback with gain $K$, determine whether the system is stabilizable or not.
\begin{enumerate}
\item $H(s)=\frac{1}{s-3}$
$$G(s)=\frac{\frac{1}{s-3}}{1+K\frac{1}{s-3}}=\frac{1}{s-3+K}$$
Therefore, if $K>3$ the closed loop system is stable.
\\
\item $H(s)=\frac{1}{s-10}$
$$G(s)=\frac{\frac{1}{s-10}}{1+K\frac{1}{s-10}}=\frac{1}{s-10+K}$$
Therefore, if $K>10$, the closed loop system is again stable.
\\
\item $H(s)=\frac{1}{(s-3)(s-2)}$
$$G(s)=\frac{\frac{1}{(s-3)(s-2)}}{1+K\frac{1}{(s-3)(s-2)}}=\frac{1}{s^2-5s+6+K}$$
This system is not stabilizable.
\end{enumerate}
\end{cexamplew}

\section{Control loop}

\begin{figure}[!h]
\centering
    \begin{tikzpicture}[auto, node distance=1cm,>=latex']
        % We start by placing the blocks
        \node [coordinate, name=input] {};

        \node [sum, right of=input] (sum) {};
        %\node [sum2, right of=sum] (sum2) {};

        \node [block,minimum height=1cm, fill=green, right of=sum, node distance=2.5cm] (C) {Controller: $C(s)$};
        \node [sum, right of=C, node distance=3cm] (sum2) {};
        \node [block,minimum height=1cm, fill=yellow, right of=sum2, node distance=2.5cm] (G) {Plant: $G(s)$};
        \node [coordinate, right of=G, node distance=2.5cm] (bp1){};
        \node [output, right of=G, node distance=2.5cm] (output) {};
        \node [coordinate, below of=C] (tmp) {};
        \node [above of=sum2, node distance=1.2cm] (d) {$d(t)$};

        % Once the nodes are placed, connecting them is easy.
        \draw [draw,->] (input) -- node {$r(t)$} (sum);
        %\draw [draw,->] (sum) -- node{} (sum2);
        \draw [->] (sum) -- node {$e(t)$} (C);
        \draw [->] (G) -- node [name=y] {$y(t)$}(bp1);
        \draw [->] (y) |- (tmp) -| node[pos=0.95]{-}(sum);
        \draw [->] (C) -- node {$v(t)$} (sum2);
        \draw [->] (sum2) -- node {$u(t)$} (G);
        \draw [->] (d) -- (sum2);
    \end{tikzpicture}
% \includegraphics[scale=0.5]{fig/szab_kor.png}
\caption{}
\label{control_loop}
\end{figure}


\begin{itemize}
\item \textbf{Control goal 1. (reference tracking): } to eliminate the error signal $e(t) = r(t) - y(t)$, namely the output signal $y(t)$ converges exponentially to the reference signal $r(t)$. In other words, after a while the output and the reference signal be the same.
\item \textbf{Control goal 2. (input disturbance reduction): } To lower the transfer between the input disturbance (or actuator fault) $d(t)$ and the output of the error signal $e(t)$, namely: $\abs{\frac{E(j \omega)}{D(j \omega)}}$ be as smaller as possible.
\item Control (or manipulate) signal $v(t)$: the necessary input signal computed by the controller for reference tracking.
\item Actuator fault
\item The controlled system (Plant) receives the manipulate input $u(t)$ and generates the output signal $y(t)$
\item Physical example. Consider a DC motor. Let the input be the current intensity ({\color{blue} áramerősség}) given to the DC motor, and let the revolution of the motor ({\color{blue} fordulatszám}) be the output of the DC motor. Then, the error signal will be the difference between the reference revolution and the actual revolution of the DC motor.
\end{itemize}

\begin{qboxr}
    \begin{example}{}
        The control loop presented in Figure \ref{control_loop} can be consider as system with two inputs (reference signal $r(t)$ and input disturbance $d(t)$) and with a single output $y(t)$.
        \begin{enumerate}
            \item[(a)] Determine the transfer function $H_{d \to y} (s)$, which is the transfer of $d(t)$ to $y(t)$.
            \item[(b)] Determine the transfer function $H_{d \to e} (s)$, which is the transfer of $d(t)$ to $e(t)$.
        \end{enumerate}
    \end{example}
\end{qboxr}

% \begin{itemize}
% \item \textbf{Szabályozási cél:} a hibajel ($e(t)$) legyen nulla, azaz a referencia ($r(t)$) és a kimeneti jel ($y(t)$) egyezzen meg.
% \item Beavatkozási jel (u): a szabályzó (Controller) által kiszámolt beavatkozás
% \item Az irányítandó rendszer (Plant) a beavatkozó jel hatására kimeneti jelet generál.
% \item Példa: Motor fordulatszám, beavatkozó jel: áramerősség, kimenet: fordulatszám, hiba jel: referencia fordulatszám és a kimeneti fordulatszám különbsége
% \end{itemize}

\subsection{PID controller}
The objective of the PID controller is to eliminate the error signal $e(t) := r(t) - y(t)$, where $r(t)$ is the reference signal, $y(t)$ is the output of the system.
In order to do this, the PID controller uses the following signals:
\begin{itemize}
\item actual error signal $e(t)$.
\item integral of the error signal: $\int_0^t e(\tau) \diffd \tau$. This constitutes the historical informations of the error signal.
\item derivative of the error signal: $\dot e(t)$. This gives the actual trend of the error signal.
\end{itemize}
Therefore, the PID controller \emph{may} contain the following three dynamical components:
\begin{itemize}
\item proportional component (P - proportional): $u(t) = K_P \cdot e(t) \qquad H_p(s) = K_P$
\item integral component (I - integral): $u(t) = K_I \cdot \int_0^t e(\tau) d\tau  \qquad H_I(s)=\frac{K_I}{s}$
\item derivative component (D - derivative): $u(t) = K_D \cdot \dot e(t) \qquad H_D(s) = s\cdot K_D$
\end{itemize}

{\color{blue} Fontos megjegyezni, hogy a deriváló tag kauzális volta miatt valós rendszerekben a deriváló tagot egy közelítő taggal helyettesítjük.}

\begin{figure}[!h]
\centering
\includegraphics[scale=0.5]{fig/Pid.png}
\label{pid_schema}
\caption{}
\end{figure}

\begin{figure}
\center
% We need layers to draw the block diagram
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\tikzstyle{sum} = [draw, circle, node distance=1cm]
\tikzstyle{sum2} = [draw, circle, node distance=1cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{bp1} = [coordinate]
\tikzstyle{bp2} = [coordinate]
\tikzstyle{bp3} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]

\begin{tikzpicture}[auto, node distance=1cm,>=latex']
    % We start by placing the blocks
    \node [coordinate, name=input] {};

    \node [sum, right of=input] (sum) {};

    \node [coordinate, right of=sum, node distance=1cm] (bp3) {};
    \node [block, right of=bp3, node distance=1.2cm] (system1) {$H_P(s)$};
    \node [block, above of=system1, node distance=1cm] (K_I) {$H_I(s)$};
    \node [block, below of=system1, node distance=1cm] (K_D) {$H_D(s)$};
    \node [sum2, right of=system1, node distance=1.3cm] (sum2) {};
    \node [block, right of=sum2, node distance=1.3cm] (system2) {$H(s)$};
    \node [coordinate, right of=system2, node distance=1cm] (bp1){};
    \node [coordinate, below of=K_D, node distance=1cm] (bp2) {};

    \node [coordinate, right of=bp1] (output) {};


    % Once the nodes are placed, connecting them is easy.
    \draw [draw,->] (input) -- node {$r$} (sum);
    \draw [->] (sum) -- node {} (bp3);
    \draw [->] (bp3)  -- node {} (system1);
    \draw [->] (bp3)  |- node {} (K_I);
    \draw [->] (bp3)  |- node {} (K_D);
    \draw [->] (system1) -- node[pos=0.95]{+} (sum2);
    \draw [->] (sum2)  -- node {u} (system2);
    \draw [->] (bp1) -- node [name=y] {$y$}(output);
    \draw [-] (bp1) |- (bp2);
    \draw [->] (K_I)-| (sum2);
    \draw [->] (K_D)-| (sum2);
    \draw [-] (system2) |- (bp1);
    \draw [->] (bp2) -| node[pos=0.99]{-}(sum);

   \begin{pgfonlayer}{background}
        \path (bp3.west |- K_I.north)+(-0.5,0.3) node (a) {};
        \path (K_D.south -| sum2.east)+(+0.3,-0.2) node (b) {};
        \path[fill=gray!10,rounded corners, draw=black!50, dashed]
            (a) rectangle (b);
    \end{pgfonlayer}
\end{tikzpicture}
\caption{}
\label{PID}
\end{figure}

The transfer function of the subsystem (highlighted by the gray dashed box in Figure \ref{PID}) is the following:
$$H_{PID} (s) =  K_p + \frac{K_I}{s} + K_D s = \frac{sK_p+K_I+s^2K_D}{s}$$
If we use only the P and I components of the PID controller:
$$H_{PI} (s) =  K_p+\frac{K_I}{s} = \frac{sK_p+K_I}{s} $$

\begin{cexamplew}{}\label{}
\begin{minipage}{0.49\textwidth}
    Let us consider the DC motor model, which we mentioned previously:
    \begin{eqnarray}
    H(s) = \frac{1}{Ms^2+bs+k}
    \end{eqnarray}
    Let $M=1$, $b=10$ és $k=20$

    Analyse the response of the system for the unit step function (sse Figure \ref{crusing_step}).
    We can see, that the limit at $t \to \infty$ of the output $y(t)$ is much less than the reference signal. This error is called \emph{static error}.
    % Nézzük meg a rendszer válaszát az egységugrás függvényre (lásd: \ref{crusing_step}). Látszik, hogy a kimenet végértéke jelentősen elmarad a bementi jelszinttől, ezt hívják statikus hibának. (A kimenet végértékét DC gain-nek nevezik, jelenleg: $\frac{1}{20}=0.05$)

    We put into the control loop a proportional term in order to reduce the static error and to obtain a shorter transient (faster rise-time and settling-time). \\
    {\color{blue} Helyezzünk a szabályozási körbe egy arányos tagot, ezzel csökkentve a statikus hibát és csökkentve a felfutási időt.}

    \begin{center}
    \begin{tikzpicture}[auto, node distance=1cm,>=latex']
        % We start by placing the blocks
        \node [coordinate, name=input] {};

        \node [sum, right of=input] (sum) {};


        \node [block, right of=sum, node distance=1cm] (system1) {$K_P$};
        \node [block, right of=system1, node distance=1.5cm] (system2) {$H(s)$};
        \node [coordinate, right of=system2] (bp1){};
        \node [coordinate, below of=system1, node distance=1cm] (bp2) {};

        \node [coordinate, right of=bp1] (output) {};


        % Once the nodes are placed, connecting them is easy.
        \draw [draw,->] (input) -- node {$r$} (sum);
        %\draw [draw,->] (sum) -- node{} (sum2);
        \draw [->] (sum) -- node {} (system1);
        \draw [->] (system1) -- node {} (system2);
        \draw [->] (bp1) -- node [name=y] {$y$}(output);
        \draw [-] (bp1) |- (bp2);
        %\draw [->] (bp1)|- (system2);
        \draw [-] (system2) |- (bp1);
        \draw [->] (bp2) -| node[pos=0.99]{-}(sum);
    \end{tikzpicture} \\
    Figure \refstepcounter{figure}\thefigure. Block diagram of the $P$ controller.
    \label{P}
    \end{center}

    Transfer function of the resulting system:

    \begin{eqnarray}
    G(s) = \frac{K_p H(S)}{1 + K_P H(s)} = \frac{K_p}{Ms^2+bs+(k+K_p)}
    \end{eqnarray}
    The step response of the system is illustrated in Figure \ref{crusing_prop_step}.
\end{minipage}\hfill
\begin{minipage}{0.50\textwidth}
    \begin{center}
        \includegraphics[width=\textwidth]{fig/crusing_step.png} \\
        \refstepcounter{figure}\label{crusing_step}Figure \thefigure. Step response of the uncontrolled system.

        \includegraphics[width=\textwidth]{fig/crusing_prop_step.png} \\
        Figure \refstepcounter{figure}\thefigure. Step response with P controller: $K_p=300$.
        \label{crusing_prop_step}
    \end{center}
\end{minipage}
\medbreak

% \begin{minipage}{0.49\textwidth}
% \end{minipage}\hfill
% \begin{minipage}{0.50\textwidth}
% \end{minipage}
% \medbreak


We can see, that the transient time and the static error decreased significantly, however there appears a large overshoot in the step response (the output of the system rises up to 1.3). \\
{\color{blue} Látható, hogy a statikus hiba és a felfutási idő jelentősen csökkent, ugyanakkor jelentős túllövés lett a rendszerválaszban.}

\begin{minipage}{0.49\textwidth}
    \begin{center}
        \begin{tikzpicture}[auto, node distance=1cm,>=latex']
            % We start by placing the blocks
            \node [coordinate, name=input] {};

            \node [sum, right of=input] (sum) {};

            \node [coordinate, right of=sum, node distance=1cm] (bp3) {};
            \node [block, right of=bp3, node distance=1cm] (system1) {$H_P(s)$};
            %\node [block, above of=system1, node distance=1.5cm] (K_I) {$H_I(s)$};
            \node [block, below of=system1, node distance=1cm] (K_D) {$H_D(s)$};
            \node [sum, right of=system1, node distance=1.4cm] (sum2) {};
            \node [block, right of=sum2, node distance=1.3cm] (system2) {$H(s)$};
            \node [coordinate, right of=system2] (bp1){};
            \node [coordinate, below of=K_D, node distance=0.8cm] (bp2) {};

            \node [coordinate, right of=bp1] (output) {};


            % Once the nodes are placed, connecting them is easy.
            \draw [draw,->] (input) -- node {$r$} (sum);
            %\draw [draw,->] (sum) -- node{} (sum2);
            \draw [->] (sum) -- node {} (bp3);
            \draw [->] (bp3)  -- node {} (system1);
            %\draw [->] (bp3)  |- node {} (K_I);
            \draw [->] (bp3)  |- node {} (K_D);
            \draw [->] (system1) -- node[pos=0.95]{+} (sum2);
            \draw [->] (sum2)  -- node {u} (system2);
            \draw [->] (bp1) -- node [name=y] {$y$}(output);
            \draw [-] (bp1) |- (bp2);
            %\draw [->] (K_I)-| (sum2);
            \draw [->] (K_D)-| (sum2);
            \draw [-] (system2) |- (bp1);
            \draw [->] (bp2) -| node[pos=0.99]{-}(sum);


           % \begin{pgfonlayer}{background}
           %      % Compute a few helper coordinates
           %      \path (bp3.west |- K_I.north)+(-0.5,0.3) node (a) {};
           %      \path (K_D.south -| sum2.east)+(+0.3,-0.2) node (b) {};
           %      \path[fill=gray!10,rounded corners, draw=black!50, dashed]
           %          (a) rectangle (b);

           %  \end{pgfonlayer}
        \end{tikzpicture} \\
        Figure \refstepcounter{figure}\thefigure. Block diagram of a PD controller.

        \includegraphics[width=\textwidth]{fig/crusing_step_pd.png} \\
        Figure \refstepcounter{figure}\thefigure. PD controller with $K_p=30$, $K_i=70$
        \label{crusing_step_pdf}
    \end{center}
\end{minipage}\hfill
\begin{minipage}{0.49\textwidth}
    \begin{center}
        \begin{tikzpicture}[auto, node distance=1cm,>=latex']
            % We start by placing the blocks
            \node [coordinate, name=input] {};

            \node [sum, right of=input] (sum) {};

            \node [coordinate, right of=sum, node distance=1cm] (bp3) {};
            \node [block, right of=bp3, node distance=1cm] (system1) {$H_P(s)$};
            \node [block, above of=system1, node distance=1cm] (K_I) {$H_I(s)$};
            %\node [block, below of=system1, node distance=1.5cm] (K_D) {$H_D(s)$};
            \node [sum, right of=system1, node distance=1.4cm] (sum2) {};
            \node [block, right of=sum2, node distance=1.3cm] (system2) {$H(s)$};
            \node [coordinate, right of=system2] (bp1){};
            \node [coordinate, below of=system1, node distance=0.8cm] (bp2) {};

            \node [output, right of=bp1] (output) {};


            % Once the nodes are placed, connecting them is easy.
            \draw [draw,->] (input) -- node {$r$} (sum);
            %\draw [draw,->] (sum) -- node{} (sum2);
            \draw [->] (sum) -- node {} (bp3);
            \draw [->] (bp3)  -- node {} (system1);
            \draw [->] (bp3)  |- node {} (K_I);
            %\draw [->] (bp3)  |- node {} (K_D);
            \draw [->] (system1) -- node[pos=0.95]{+} (sum2);
            \draw [->] (sum2)  -- node {u} (system2);
            \draw [->] (bp1) -- node [name=y] {$y$}(output);
            \draw [-] (bp1) |- (bp2);
            \draw [->] (K_I)-| (sum2);
            %\draw [->] (K_D)-| (sum2);
            \draw [-] (system2) |- (bp1);
            \draw [->] (bp2) -| node[pos=0.99]{-}(sum);


           % \begin{pgfonlayer}{background}
           %      % Compute a few helper coordinates
           %      \path (bp3.west |- K_I.north)+(-0.5,0.3) node (a) {};
           %      \path (K_D.south -| sum2.east)+(+0.3,-0.2) node (b) {};
           %      \path[fill=gray!10,rounded corners, draw=black!50, dashed]
           %          (a) rectangle (b);

           %  \end{pgfonlayer}
        \end{tikzpicture} \\
        Figure \refstepcounter{figure}\thefigure. Block diagram of a PI controller.

        \includegraphics[width=\textwidth]{fig/crusing_step_pid.png}
        \label{crusing_step_pdf} \\
        Figure \refstepcounter{figure}\thefigure. PID controller with $K_p=350$, $K_d=50$, $K_i=300$
    \end{center}
\end{minipage}

Source: \url{http://www.engin.umich.edu/class/ctms/pid/pid.htm}
\end{cexamplew}

\section{További gyakorló feladatok (tipikus ZH feladatok)}
\begin{enumerate}

    \item
    Adott a következõ hatásvázlat:
    \begin{figure}[h!]
    \center
    \tikzstyle{block} = [draw, rectangle,
        minimum height=3em, minimum width=6em]
    \tikzstyle{smallblock} = [draw, rectangle,
        minimum height=1em, minimum width=2em]
    \tikzstyle{sum1} = [draw, circle, node distance=1cm]
    %\tikzstyle{sum2} = [draw, fill=blue!20, circle, node distance=1cm]
    \tikzstyle{input} = [coordinate]
    \tikzstyle{bp1} = [coordinate]
    \tikzstyle{bp2} = [coordinate]
    \tikzstyle{output} = [coordinate]
    \tikzstyle{pinstyle} = [pin edge={to-,thin,black}]

    \begin{tikzpicture}[auto, node distance=2cm,>=latex']
        % We start by placing the blocks
        \node [input, name=input] {};

        \node [sum1, right of=input] (sum1) {};


        \node [block, right of=sum1, node distance=3cm] (system1) {$H_1(s)$};
        \node [block, right of=system1, node distance=3cm] (system2) {$H_2(s)$};
        \node [bp1, right of=system2] (bp1){};
        \node [smallblock, below of=system1, node distance=1.5cm] (bp2) {$K$};

        \node [output, right of=bp1] (output) {};


        % Once the nodes are placed, connecting them is easy.
        \draw [draw,->] (input) -- node {$r$} (sum1);
        %\draw [draw,->] (sum1) -- node{} (sum2);
        \draw [->] (sum1) -- node {} (system1);
        \draw [->] (system1) -- node {} (system2);
        \draw [->] (bp1) -- node [name=y] {$y$}(output);
        \draw [-] (bp1) |- (bp2);
        %\draw [->] (bp1)|- (system2);
        \draw [-] (system2) |- (bp1);
        \draw [->] (bp2) -| node[pos=0.99]{-}(sum1);
    \end{tikzpicture}
    \end{figure}
    \begin{enumerate}
    \item $H_1(s)=\frac{s+2}{s^2+5s+6}$, $H_2(s)=\frac{1}{s+1}$, $K=1$, adja meg a $G(s)$ eredõ átviteli függvényt! (2p)
    \item $H_1(s)=\frac{s+1}{s-3}$, $H_2(s)=\frac{s+4}{s^2+3s+2}$, $K=-4$  vagy $K=2$ értékre lesz az eredõ átviteli függvény stabil? (3p)
    \item $H_1(s)=\frac{s+2}{s^2+5s+6}$, $H_2(s)=?$, $K=1$, adja meg $H_2(s)$-t, úgy hogy csak -tetszõleges- instabil pólusai legyenek az eredõ rendszernek! (5p)
    \end{enumerate}

    \item
    Tekintsük a következõ átviteli függvényt:
    \[
    H(s)=\frac{s+l_1}{s^3+l_2 s^2 + s +3},
    \]
    ahol $l_1$ és $l_2$ valós paraméterek. Létezik-e olyan véges erõsítésû lineáris kimenet-visszacsatolás (azaz $u=-ky$, ahol $|k|<\infty$), amely aszimptotikusan stabilizálja a rendszert, ha $l_1>0$ és $l_2<0$? Miért? (3p)

    \item
    Mennyi lesz az az erõsítése decibelben az alábbi átviteli függvénynek konstans bemenet esetén? (2p)
    \[
    H(s)=\frac{s+1}{s^2+10s+10}
    \]

    \item Minimumfázisú-e a következõ átviteli függvény (Miért)? (2p)
    \[
    H(s)=\frac{(s+1)(s+3)}{s^3-3s^2+2s+1}
    \]

    \item Adott a következõ lineáris rendszer:
    \begin{eqnarray*}
    A=\left[\begin{array}{cc}
    4 & 3.5\\
    2 & -2
    \end{array}\right] & \qquad & B=\left[\begin{array}{c}
    0\\
    1
    \end{array}\right]\\
    C=\left[\begin{array}{cc}
    1 & 0\end{array}\right] & \qquad & D=0
    \end{eqnarray*}


    \begin{enumerate}
    \item Adja meg a rendszer $H(s)$ átviteli függvényét! (3 pont)
    \item Adja meg a rendszer pólusait! (1 pont)
    \item Stabil-e a rendszer? Pontos indoklás! (1 pont)
    \item
    \begin{center}
      % Requires \usepackage{graphicx}
      \includegraphics[width=6cm]{fig/atv_fv_4.png}\\
    \end{center}

    Stabil lesz-e a visszacsatolt rendszer $A=0$ illetve $A=0.25$ értékek esetén (3p)?

\end{enumerate}

    \item
    Adott a következõ hatásvázlat:
    {
    \center
    \tikzstyle{block} = [draw, rectangle,
        minimum height=3em, minimum width=6em]
    \tikzstyle{smallblock} = [draw, rectangle,
        minimum height=1em, minimum width=2em]
    \tikzstyle{sum1} = [draw, circle, node distance=1cm]
    \tikzstyle{sum2} = [draw, circle, node distance=1cm]
    \tikzstyle{input} = [coordinate]
    \tikzstyle{bp1} = [coordinate]
    \tikzstyle{bp2} = [coordinate]
    \tikzstyle{bp3} = [coordinate]
    \tikzstyle{bp4} = [coordinate]

    \tikzstyle{output} = [coordinate]
    \tikzstyle{pinstyle} = [pin edge={to-,thin,black}]

    \begin{tikzpicture}[auto, node distance=2cm,>=latex']
        % We start by placing the blocks

        \node [input, name=input] {};

        \node [block, right of=input, node distance=2cm] (system0) {$H_1(s)$};

        \node [sum1, right of=system0, node distance=2cm] (sum1) {};

        \node [bp3, right of=sum1, node distance=1cm] (bp3) {};
        \node [block, right of=bp3, node distance=2cm] (system1) {$H_2(s)$};
        \node [block, above of=system1, node distance=1.5cm] (system3) {$H_3(s)$};

        \node [sum2, right of=system1, node distance=3cm] (sum2) {};

        \node [block, right of=sum2, node distance=2cm] (system2) {$H_4(s)$};


        \node [bp1, right of=system2] (bp1){};

        \node [smallblock, below of=system1, node distance=1.5cm] (bp2) {$K$};

        \node [output, right of=bp1] (output) {};


        % Once the nodes are placed, connecting them is easy.
        \draw [draw,->] (input) -- node {$r$} (system0);
        \draw [draw,->] (system0) -- node {} (sum1);
        %\draw [draw,->] (sum1) -- node{} (sum2);
        \draw [-] (sum1) -- node {} (bp3);
        \draw [->] (bp3) -- node {} (system1);
        \draw [->] (bp3) |- node {} (system3);
        \draw [->] (system1) -- node {} (sum2);
        \draw [->] (system3) -| node {} (sum2);
        \draw [->] (sum2) -- node {} (system2);
        \draw [-] (system2) -- node {} (bp1);
        \draw [->] (bp1) -- node [name=y] {$y$}(output);
        \draw [-] (bp1) |- (bp2);
        %\draw [->] (bp1)|- (system2);
        %\draw [-] (system2) |- (bp1);
        \draw [->] (bp2) -| node[pos=0.99]{-}(sum1);
    \end{tikzpicture}
    }

    Adja meg a rendszer eredõ átviteli függvényét $G(s)$-t, ha $H_1(s)=\frac{s+2}{s^2-7s+11}$, $H_2(s)=\frac{1}{s}$, $H_3(s)=\frac{s-3}{s+7}$, $H_4(s)=\frac{s+7}{s+1}$ (6 pont)\\
    (Segítség: a gyöktényezõs alak megtartása elõnyös a számolás során, illetve az egyes részrendszerek kiszámítása megkönnyíti a számolást.)

\end{enumerate}

\end{document}
