Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to implement this Block Diagram: enter image description here

Forget about the math, I can do it. I just want to implement the diagram. I used the example here; it is nice, but whenever I remove the "measurement" block, the feedback path cannot be obtained unless directly (-180 deg). Also, I am still unable to get more than one box on top of each other.

enter image description here

MWE:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}

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

\begin{tikzpicture}[auto, node distance=2cm,>=latex']

    \node [input, name=input] {};
    \node [sum, right of=input] (sum) {};
    \node [block, right of=sum] (controller) {Controller};
    \node [block, right of=controller, pin={[pinstyle]above:D},
            node distance=3cm] (system) {System};

    \draw [->] (controller) -- node[name=u] {$u$} (system);
    \node [output, right of=system] (output) {};
    \node [block, below of=u] (measurements) {Measurements};

    \draw [draw,->] (input) -- node {$r$} (sum);
    \draw [->] (sum) -- node {$e$} (controller);
    \draw [->] (system) -- node [name=y] {$y$}(output);
    \draw [->] (y) |- (measurements);
    \draw [->] (measurements) -| node[pos=0.99] {$-$} 
        node [near end] {$y_m$} (sum);
\end{tikzpicture}
\end{document}
share|improve this question
3  
Look here for nodes above each other. tex.stackexchange.com/questions/168463/… –  dustin May 8 at 4:53
    
+1 for the very useful link! –  student1 May 8 at 4:57

2 Answers 2

up vote 5 down vote accepted

Would this be it?

To draw a block diagram,

(1) First define a style definition for each repeated blocks, input/output, summations, or pins; so that different property of each node is attributed. Use them properly in each node definition mentioned below.

(2) Use node command to place each node, it is convenient to allocate each node based on relative position (above, below, right, left =xx cm of < a node >) where positioning tikzlibrary is instrumental. For each node it is convenient to assigned an <internal name> for later reference, for example, when drawing lines.

(3) Use draw to complete the line connections, assigning labels along the line via node[<location>](<internal name>){<external name>} syntax.

enter image description here

Code

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

\begin{document}

\tikzset{
block/.style = {draw, fill=white, rectangle, minimum height=3em, minimum width=3em},
tmp/.style  = {coordinate}, 
sum/.style= {draw, fill=white, circle, node distance=1cm},
input/.style = {coordinate},
output/.style= {coordinate},
pinstyle/.style = {pin edge={to-,thin,black}
}
}



%\begin{figure}[!htb]
%\centering
\begin{tikzpicture}[auto, node distance=2cm,>=latex']
    \node [input, name=rinput] (rinput) {};
    \node [sum, right of=rinput] (sum1) {};
    \node [block, right of=sum1] (controller) {$k_{p\beta}$};
    \node [block, above of=controller,node distance=1.3cm] (up){$\frac{k_{i\beta}}{s}$};
    \node [block, below of=controller,node distance=1.3cm] (rate) {$sk_{d\beta}$};
    \node [sum, right of=controller,node distance=2cm] (sum2) {};
    \node [block, above = 2cm of sum2](extra){$\frac{1}{\alpha_{\beta2}}$};  %
    \node [block, right of=sum2,node distance=2cm] (system) 
{$\frac{a_{\beta 2}}{s+a_{\beta 1}}$};
    \node [output, right of=system, node distance=2cm] (output) {};
    \node [tmp, below of=controller] (tmp1){$H(s)$};
    \draw [->] (rinput) -- node{$R(s)$} (sum1);
    \draw [->] (sum1) --node[name=z,anchor=north]{$E(s)$} (controller);
    \draw [->] (controller) -- (sum2);
    \draw [->] (sum2) -- node{$U(s)$} (system);
    \draw [->] (system) -- node [name=y] {$Y(s)$}(output);
    \draw [->] (z) |- (rate);
    \draw [->] (rate) -| (sum2);
    \draw [->] (z) |- (up);
    \draw [->] (up) -| (sum2);
    \draw [->] (y) |- (tmp1)-| node[pos=0.99] {$-$} (sum1);
    \draw [->] (extra)--(sum2);
    \draw [->] ($(0,1.5cm)+(extra)$)node[above]{$d_{\beta 2}$} -- (extra);
    \end{tikzpicture}
%\caption{A PID Control System} \label{fig6_10}
%\end{figure}

\end{document}
share|improve this answer
1  
You make me feel regretful, as my intention was to ask people for hints not for full implementation. I cannot thank you enough, though. –  student1 May 8 at 6:03
    
You are wellcome. –  Jesse May 8 at 6:05
    
Quick question: the branching out for the below block does not exactly stem from the horizontal line, rather it has a small gap (If you remove E you'll see it more clearly). Can this gap be suppressed? –  student1 May 8 at 14:37
1  
@student1 -- the anchor=north causes that. Try node[coordinate](z){} instead should fill the gap. I have checked it. OK –  Jesse May 8 at 14:53
    
Excellent, thanks. –  student1 May 8 at 16:17

You can replace the measurements block with a \coordinate and use that as an intermediate point. Below I have commented out the changed lines so that you can see what was changed:

enter image description here

Code:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}

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

\begin{tikzpicture}[auto, node distance=2cm,>=latex']

    \node [input, name=input] {};
    \node [sum, right of=input] (sum) {};
    \node [block, right of=sum] (controller) {Controller};
    \node [block, right of=controller, pin={[pinstyle]above:D},
            node distance=3cm] (system) {System};

    \draw [->] (controller) -- node[name=u] {$u$} (system);
    \node [output, right of=system] (output) {};
    %\node [block, below of=u] (measurements) {Measurements};
    \coordinate [below of=u] (measurements) {};

    \draw [draw,->] (input) -- node {$r$} (sum);
    \draw [->] (sum) -- node {$e$} (controller);
    \draw [->] (system) -- node [name=y] {$y$}(output);
    %\draw [->] (y) |- (measurements);
    \draw [-] (y) |- (measurements);
    %\draw [->] (measurements) -| node[pos=0.99] {$-$} 
    \draw [->] (measurements) -| %node[pos=1.00] {$-$} 
        node [near end] {$y_m$} (sum);

    %\draw [->] 
\end{tikzpicture}
\end{document}
share|improve this answer
    
Great, thanks! I used \node [block, above of=controller] (TopBlock) {MyTopBlock}; to have the other block and it looks like working. If I solve it then will mark this as accepted answer :) –  student1 May 8 at 4:51
    
If you are using a \node instead of a \coordinate you might have to set inner sep=0pt, outer sep=0pt. That is why I went with \coordinate. –  Peter Grill May 8 at 5:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.