7

I currently have a control system block diagram id like to add to.. Currently I have

\documentclass[12pt]{article}
\usepackage{tikz}
\tikzstyle{block} = [draw, fill=blue!20, rectangle, 
    minimum height=3em, minimum width=6em]
\tikzstyle{sum} = [draw, fill=blue!20, circle, node distance=1cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
\usetikzlibrary{shapes,arrows}
\begin{document}
\begin{tikzpicture}[auto, node distance=2cm,>=latex']
    % We start by placing the blocks
    \node [input, name=input] {};
    \node [sum, right of=input] (sum) {};
    \node [block, right of=sum] (controller) {C(s)};
    \node [block, right of=controller, %pin={[pinstyle]above:},
            node distance=4cm] (system) {$G_p$};
    % We draw an edge between the controller and system block to 
    % calculate the coordinate u. We need it to place the measurement block. 
    \draw [->] (controller) -- node[name=u] {$u$} (system);
    \node [output, right of=system] (output) {};
    \node [output,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 [->] (measurements) -| node[pos=0.99] {$-$} 
        node [near end] {$y$} (sum);
\end{tikzpicture}
\end{document}

Which gives tikz block diagram

But I am trying to add this.. sampler after the block labeled $$G_p$$

  • I was not able to compile your example. What am I missing? – Yossi Gil Aug 17 '16 at 6:43
  • have a look at tex.stackexchange.com/questions/276294/… and other questions by searching for [tikz] switch on this site – percusse Aug 17 '16 at 6:48
  • JS60, please add the preamble as well: style definitions, libraries are missing. – Alenanno Aug 17 '16 at 9:38
  • My apologies, added the preamble – JS60 Aug 20 '16 at 1:29
5
+50

For switch I design special node. Maybe you like such solution :-)

Beside this, I use different TikZ libraries (arrows.meta, bending, positioning), introduce new command for shorter writing of switch and replace obsolete \tikzstyle with \tikzset as well as syntax for positioning of nodes. Also I done some changes in coordinate nodes style definition (it works with TikZ 3.1)

\documentclass[12pt,tikz,border=3mm]{standalone}
    \usetikzlibrary{arrows.meta,bending,positioning}
    \newcommand\ppbb{path picture bounding box}% added for shorter code of switch

\tikzset{% replace tikstyle
 block/.style = {draw, fill=blue!20, rectangle,
                 minimum height=3em, minimum width=6em},
   sum/.style = {circle, draw, fill=blue!20, node contents={}},
 input/.style = {coordinate,node contents={}},% changed
output/.style = {coordinate,node contents={}},%c changed
switch/.style = {minimum size=3em,% new style for switch
                 path picture={  \draw
                 ([xshift=-3mm]  \ppbb.center)  -- ++ (45:6mm);
                                 \draw[shorten >=3mm,-]
                 (\ppbb.west) edge (\ppbb.center)
                 (\ppbb.east)  --  (\ppbb.center);
                                 \draw[<->]
                 ([yshift=-2mm] \ppbb.center) arc[start angle=-15, end angle=75, radius=6mm];   
                            },% end of drawing in node
                 label={[yshift=-2mm] above:#1},
                 node contents={}},
%pinstyle/.style = {pin edge={to-,thin,black}]% not used in this image
        }
\begin{document}
\begin{tikzpicture}[auto, node distance=2cm,>={Latex[flex]}]
    % We start by placing the blocks
\node (input)       [input];
\node (sum)         [sum, right of=input];
\node (controller)  [block, right=1cm of sum]       {C(s)};
\node (system)      [block, right=of controller]    {$G_p$};
\node (switch)      [switch=$T$, right=0 cm of system]; % <-- added switch
\node (output)      [output, right=of switch];
    % We draw an edge between the controller and system block to
    % calculate the coordinate u. We need it to place the measurement block.
\draw [->]  (controller) -- node (u) {$u$} (system);
\node  (measurements) [output,below of=u] {};
\draw [->]  (input)  -- node {$r$} (sum);
\draw [->]  (sum)    -- node {$e$} (controller);
\draw [->]  (switch) -- node (y) {$y$} (output);
\draw       (y) |- (measurements);
\draw [->]  (measurements) -| node[pos=0.95] {$-$}
                              node[near end] {$y$} (sum);
\end{tikzpicture}
\end{document}

enter image description here

4

The code provided in the question did not produce the output shown for me, so I improvised a bit and tidied up somewhat.

Anyway, here's one ad hoc way:

\documentclass[border=10pt,multi,tikz]{standalone}
\usetikzlibrary{arrows.meta,positioning,calc,bending}
\begin{document}
\begin{tikzpicture}
  [
    auto,
    node distance=2cm,
    >=Latex,
    input/.style={},
    block/.style={draw, fill=blue!25},
    sum/.style={draw, circle, fill=blue!25},
    output/.style={},
  ]
    % We start by placing the blocks
    \node [input, name=input] {};
    \node [sum, right of=input] (sum) {};
    \node [block, right of=sum] (controller) {C(s)};
    \node [block, right=20mm of controller, %pin={[pinstyle]above:},
          ] (system) {$G_p$};
    % We draw an edge between the controller and system block to
    % calculate the coordinate u. We need it to place the measurement block.
    \draw [->] (controller) -- node[name=u] {$u$} (system);
    \node [output, right of=system] (output) {};
    \coordinate [below of=u] (measurements) ;
    \draw [draw,->] (input) -- node {$r$} (sum);
    \draw [->] (sum) -- node {$e$} (controller);
    \draw [->] (system) -- ++(5mm,0) coordinate (p) edge [-] +(45:5mm) +(5mm,0) -- node [name=y] {$y$}(output);
    \draw [{Latex[bend,scale=.5]}-{Latex[bend,scale=.5]}] ($(p)+(80:2.5mm)$) [out=0, in=90] to ($(p)+(10:2.5mm)$);
    \draw [-] (y) |- (measurements);
    \draw [->] (measurements) -| node[pos=0.99] {$-$} node [near end] {$y$} (sum);
\end{tikzpicture}
\end{document}

switch

Obviously, it would be better to use one of the specialised packages available for drawing circuits or whatever, if applicable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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