2

I'm using an example I found online: https://texample.net/tikz/examples/control-system-principles/, to draw this diagram: enter image description here

so far I have:

\documentclass{article}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{lscape}
\usepackage{tocbibind}
\usepackage{listings}
\usepackage{tikz} 
\usepackage{amsmath}
\usetikzlibrary{shapes, arrows.meta, arrows, positioning}

\begin{document}

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

\begin{tikzpicture}[auto, node distance=3cm,>=latex']
   
    \node [input, name=input] {};
    \node [block, right of=input] (controller) {{$\dot x = Ax(t) + Bu(t)$}};
        \draw [draw,->] (input) -- node {$u$} (controller);
    \node [block, right of=controller,
            node distance=4cm] (system) {C};
    \node [output, right of=system] (output) {};
        \draw [->] (system) -- node [name=y] {$y$}(output);  
    \node [block, below of=controller] (new controller)  {{$\dot{\hat{x}} = \hat{A}\hat{x}(t) + \hat{B}u(t)$}};
    \node [block, right of=new controller,
            node distance=4cm] (new system) {$\hat{C}$};
    \node [output, right of=new system] (new output) {};
    
    \node[sum, right of =new output] (sum) {};
    
    \draw [->] (new system) -- node [name=y] {$\hat{y}$}(new output);
    
    \node [block, below of=new system] (observer) {{$L$}};   

    \draw [->] (controller) -- node[name=u] {$x$} (system);
    \draw [->] (new controller) -- node[name=u] {$\hat{x}$} (new system);
    
\end{tikzpicture}

\end{document}

and I'm stuck with getting the circle/sum node at the end or edge of y hat. It is too far out. any help with drawing this diagram would be appreciated, as I've been stuck with the sum node position for a while. many thanks!

edit 1: edited and included packages and such as it wasn't included before, apologies! (I've included other packages as this is a part of a greater file and is just a section). Would also appreciate if possible if L had an arrow going into xhat(t)=... as shown in the diagram please!

edit 2: thank you to Rushi and Zarko for their help. it helped me improve mine, and I used things I learnt from both codes to produce: enter image description here

the code being:

\documentclass{article}
\usepackage{tikz} 
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usetikzlibrary{shapes, arrows.meta,arrows, positioning,chains, quotes}

\begin{document}

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

\begin{tikzpicture}[auto,>=latex']

    \node [input, name=input] {};
    \node [block, right=1cm of input] (system) {{$\dot x = Ax(t) + Bu(t)$}};
    \node [block, right=1cm of system] (C) {C};
    \node [output, right=2cm of C] (output) {};
    \node [block, below=1cm of system] (observer) {{$\dot{\hat{x}} = \hat{A}\hat{x}(t) + \hat{B}u(t)$}};
    \node [block, right=1cm of observer] (CHat) {$\hat{C}$};
    \node [output, right=1cm of CHat] (new output) {};
    \node [sum] at (output |- CHat) (sum) {};
    \node [block, below=1cm of CHat] (L) {{$L$}};

    \draw [-] (input) -- ++(-1,0);
    \draw [->] (input) -- node {$u$} (system);
    \draw [-] (C) -- node [name=y] {$y$} (output);
    \draw [->] (output) -- ++(1,0);
    \draw [->] (CHat) -- node [name=y] {$\hat{y}$} node [below,at end] {$-$} (sum);
    \draw [->] (system) -- node [name=x] {$x$} (C);
    \draw [->] (observer) -- node [name=xHat] {$\hat{x}$} (CHat);
    \draw [->] (output) -- (sum);
    \draw [->] (sum) |- node[name=u] [right, near start] {$e$} (L);
    \draw [->] (input) |- (observer);
    %\draw [->] (L) -| (observer);
    \draw [->] (L) -- (input |- L) |- ([yshift=-1ex] observer.west);
    \draw [->] (xHat) -- ++(0,-4);
\end{tikzpicture}

\end{document}
1
  • Please always post a MWE (your code cannot be compiled as-is). It is easier for people to help you if the code you supplied can be compiled.
    – Rushi
    Dec 15, 2021 at 0:25

2 Answers 2

8

One solution using the positioning library:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
\begin{document}
\tikzstyle{block} = [draw, rectangle, minimum height=3em, minimum width=6em]
\tikzstyle{sum} = [draw, circle, node distance=1.5cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]

\begin{tikzpicture}[auto,>=latex']
% Start by placing nodes
    \node [input, name=input] {};
    \node [block, right=1cm of input] (system) {{$\dot x = Ax(t) + Bu(t)$}};
    \node [block, right=1cm of system] (C) {C};
    \node [output, right=1cm of C] (output) {};
    \node [block, below=1cm of system] (observer) {{$\dot{\hat{x}} = \hat{A}\hat{x}(t) + \hat{B}u(t)$}};
    \node [block, right=1cm of observer] (CHat) {$\hat{C}$};
    \node [output, right=1cm of CHat] (new output) {};
    \node [sum] at (output |- CHat) (sum) {};
    \node [block, below=1cm of CHat] (L) {{$L$}};
% Connect away!
    \draw [->] ([xshift=-1cm] input) -- (input) -- node {$u$} (system);
    \draw [->] (C) -- node [name=y] {$y$} (output) -- ([xshift=1cm] output);
    \draw [->] (CHat) -- node [name=y] {$\hat{y}$} node [below,near end] {$-$} (sum);
    \draw [->] (system) -- node [name=x] {$x$} (C);
    \draw [->] (observer) -- node [name=xHat] {$\hat{x}$} (CHat);
    \draw [->] (output) -- (sum);
    \draw [->] (sum) |- node[name=u] {$e$} (L);
    \draw [->] (input) |- ([yshift=0.25cm] observer);
    \draw [->] (L) -- (input |- L) |- ([yshift=-0.25cm] observer);
    \draw [->] (xHat) -- ++(0,-4);
\end{tikzpicture}
\end{document}

enter image description here

3
  • 1
    (+1) Curious to know as I am learning TikZ. Will it be possible to connect the 'L' block and the 'xhat=...' block in the way shown in the question?
    – Imran
    Dec 15, 2021 at 1:02
  • thank you so much! I'm new to using Tikz so it took a while, but it was a challenge! Dec 15, 2021 at 2:41
  • 1
    Yes, that is certainly possible, it is functionally the same, so I did not. See the updated code. I changed that line to \draw [->] (L) -- (input |- L) |- ([yshift=-0.25cm] observer); Draw a line from L to the corner you gat from drawing a vertical line | from input and a horizontal line - from L. From there, draw a |- line to observer shifted down a bit.
    – Rushi
    Dec 15, 2021 at 15:16
7

Another solution is use:

  • of packages arrows.meta, chains, positioning and `quotes
  • tikzpicture options for defining styles of image elements
  • draw main control branch as chain

Edit: in the first attempt I forgot on vertical line which start between block "observer" and "C". Starting point is determined by

\node (aux) at ($(n21.east)!0.5!(n22.west)$) [dot];

and than add arrows with

        (aux) ++ (0,-2)   % <---

The reason why I select this way how this point is selected, is to show possibility to use calc library.

Both changes in original code are in MWE below marked by % <---.

\documentclass[margin=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                calc, chains,  % <---
                positioning,
                quotes}

\begin{document}
    \begin{tikzpicture}[auto,
node distance = 4mm and 6mm,
  start chain = going right,
   box/.style = {draw, text width=#1, minimum height=5ex, align=center},
 box/.default = 2em,
  dot/.style = {circle, fill, inner sep=1pt, node contents={}},
  sum/.style = {circle, draw, node contents={}},
  arr/.style = {-Straight Barb},
every edge/.append style = {draw, arr}
                        ]
% nodes
    \begin{scope}[nodes={on chain}]
\coordinate (in);
\node (n11) [dot];
\node (n12) [box=9em] {$\dot x = Ax(t) + Bu(t)$};
\node (n13) [box]{$C$};
\node (n14) [dot];
\coordinate (out);
    \end{scope}
\node (n21) [box=9em, 
             below=of n12]  {$\dot{\hat{x}} = \hat{A}\hat{x}(t) + \hat{B}u(t)$};
\node (n22) [box, below=of n13]  {$\hat{C}$};
\node (n23) [sum, at={(n14 |- n22)}];
%
\node (n31) [box, below=of n22] {$L$};
% connections
\node (aux) at ($(n21.east)!0.5!(n22.west)$) [dot]; % <---
\path   (in)    edge [pos=0.75, "$u$"]   (n12)
        (n12)   edge ["$x$"]            (n13) 
        (n13)   edge [pos=0.2,"$y$"]    (out)
%
        (n21)   edge ["$\hat{x}$"]      (n22)
        (n22)   edge ["$\hat{y}$"]      (n23)
        (n22)   edge ["$-$" ',near end]  (n23)
        (aux)   edge ++ (0,-2)   % <---
        (n14)   edge (n23);
\draw[arr]  (n11) |- (n21);
\draw[arr]  (n23) |- (n31)  node[pos=0.75] {$e$};
\draw[arr]  (n31) -- (n11 |- n31) |- ([yshift=-1ex] n21.west);
    \end{tikzpicture}
\end{document}

enter image description here

Note: If you not like to have dots at branch splitting points, just replace this nodes by \coordinate. See image code fragment below:

    \begin{tikzpicture}[auto,
node distance = 4mm and 6mm,
  start chain = going right,
   box/.style = {draw, text width=#1, minimum height=5ex, align=center},
 box/.default = 2em,
  dot/.style = {circle, fill, inner sep=1pt, node contents={}},
  sum/.style = {circle, draw, node contents={}},
  arr/.style = {-Straight Barb},
every edge/.append style = {draw, arr}
                        ]
% nodes
    \begin{scope}[nodes={on chain}]
\coordinate (in);
\coordinate (n11);
\node (n12) [box=9em] {$\dot x = Ax(t) + Bu(t)$};
\node (n13) [box]{$C$};
\coordinate (n14);
\coordinate (out);
    \end{scope}
\node (n21) [box=9em,
             below=of n12]  {$\dot{\hat{x}} = \hat{A}\hat{x}(t) + \hat{B}u(t)$};
\node (n22) [box, below=of n13]  {$\hat{C}$};
\node (n23) [sum, at={(n14 |- n22)}];
%
\node (n31) [box, below=of n22] {$L$};
% connections
\coordinate (aux) at ($(n21.east)!0.5!(n22.west)$); % <---
\path   (in)    edge [pos=0.75, "$u$"]   (n12)
        (n12)   edge ["$x$"]            (n13)
        (n13)   edge [pos=0.2,"$y$"]    (out)
%
        (n21)   edge ["$\hat{x}$"]      (n22)
        (n22)   edge ["$\hat{y}$"]      (n23)
        (n22)   edge ["$-$" ',near end]  (n23)
        (aux)   edge ++ (0,-2)   % <---
        (n14)   edge (n23);
\draw[arr]  (n11) |- (n21);
\draw[arr]  (n23) |- (n31)  node[pos=0.75,'] {$e$};  % <---
\draw[arr]  (n31) -- (n11 |- n31) |- ([yshift=-1ex] n21.west);
    \end{tikzpicture}

enter image description here

Of course you can replace my nodes name as (n13) and (n21) with (controller) and (system) respectivelly, etc. I change names for convenience of shorter writing.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .