[Tex/LaTex] Very simple feedback system diagram using Tikz

circuitsdiagramsgraphicstikz-arrowstikz-pgf

I have a working example of a feedback system diagram in Tikz

enter image description here

I have been playing around with the code a bit but when ever I do something I receive an error, and I have no idea how to use the |- and -|.

Can someone help me to perform the following:

  1. Stretch out the line between C(s) and G(s) some more (now it is too short)

  2. Place the 1 in the feedback loop right below the middle of the line connecting C(s) and G(s) (more symmetric)

  3. Remove the 1 all together and just have a loop without any block

    \documentclass[]{article}
    \usepackage{tikz}
    \usetikzlibrary{shapes,arrows}
    \usetikzlibrary{arrows,calc}
    
    \tikzset{
        block/.style = {draw, rectangle, 
            minimum height=1cm, 
            minimum width=2cm},
        input/.style = {coordinate,node distance=1cm},
        output/.style = {coordinate,node distance=4cm},
        arrow/.style={draw, -latex,node distance=2cm},
        pinstyle/.style = {pin edge={latex-, black,node distance=2cm}},
        sum/.style = {draw, circle, node distance=1cm}
    }
    
    \begin{document}
    
    
    \begin{figure}[ht]
        \begin{center}
            \begin{tikzpicture}[auto, node distance=2.5cm,>=latex']
            \node [input, name=input] {};
            \node [sum, right of=input] (sum) {};
            \node [block, right of=sum] (controller) {$C(s)$};
            \node [block, right of=controller] (plant) {$G(s)$};
            \node [output, right of=plant] (output) {};
            \node [block, below of=plant] (feedback) {$1$};
            \draw [draw,->] (input) -- node {$U(s)$} (sum);
            \draw [->] (sum) -- node {} (controller);
            \draw [->] (controller) -- node {} (plant);
            \draw [->] (plant) -- node [name=y] {$Y(s)$}(output);
            \draw [->] (y) |- node [above,pos=0.79] {} (feedback) ;
            \draw [->] (feedback) -| node[pos=0.99] {$-$} 
            node [near end] {} (sum);
            \end{tikzpicture}
        \end{center}
        \caption{TikzPicture}\label{fig}
    \end{figure}
    \end{document}
    

Best Answer

  1. You can use the tikzlibrary positioning to have the syntax [left=n of N] where n is the node distance and N is the node that should be positioned relative to.
  2. use the calc library as shown below.
  3. use relative coordinates to draw the edge in two steps.

The result

    \documentclass[]{article}
    \usepackage{tikz}
    \usetikzlibrary{shapes,arrows}
    \usetikzlibrary{arrows,calc,positioning}

    \tikzset{
        block/.style = {draw, rectangle,
            minimum height=1cm,
            minimum width=2cm},
        input/.style = {coordinate,node distance=1cm},
        output/.style = {coordinate,node distance=4cm},
        arrow/.style={draw, -latex,node distance=2cm},
        pinstyle/.style = {pin edge={latex-, black,node distance=2cm}},
        sum/.style = {draw, circle, node distance=1cm},
    }

    \begin{document}

    \begin{figure}[ht]
        \begin{center}
            \begin{tikzpicture}[auto, node distance=1cm,>=latex']
            \node [input, name=input] {};
            \node [sum, right=of input] (sum) {};
            \node [block, right=of sum] (controller) {$C(s)$};
            \node [block, right=2 of controller] (plant) {$G(s)$};
            \node [output, right=of plant] (output) {};
            \node at ($(controller)!0.5!(plant)+(0,-2)$) [block] (feedback) {$1$};
            \draw [draw,->] (input) -- node {$U(s)$} (sum);
            \draw [->] (sum) -- (controller);
            \draw [->] (controller) -- (plant);
            \draw [->] (plant) -- node [name=y] {$Y(s)$}(output);
            \draw [->] (y) |- (feedback) ;
            \draw [->] (feedback) -| node[pos=0.99] {$-$} (sum);
            \end{tikzpicture}    
            \begin{tikzpicture}[auto, node distance=1cm,>=latex']
            \node [input, name=input] {};
            \node [sum, right=of input] (sum) {};
            \node [block, right=of sum] (controller) {$C(s)$};
            \node [block, right=2 of controller] (plant) {$G(s)$};
            \node [output, right=of plant] (output) {};
            \draw [draw,->] (input) -- node {$U(s)$} (sum);
            \draw [->] (sum) -- node {} (controller);
            \draw [->] (controller) -- node {} (plant);
            \draw [->] (plant) -- node [name=y] {$Y(s)$}(output);
            \draw [->] (y) -- ++ (0,-2) -| node [pos=0.99] {$-$} (sum);
            \end{tikzpicture}
        \end{center}
        \caption{TikzPicture}\label{fig}
    \end{figure}
    \end{document}