4

My code is:

%\documentclass{article}
\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage{verbatim}
\usepackage[utf8]{inputenc}

\begin{document}
    \tikzstyle{block} = [draw, fill=blue!20, rectangle,minimum height=3em, minimum width=4em]
    \tikzstyle{block2} = [draw, fill=white!20, rectangle,minimum height=3em, minimum width=4em]
    \tikzstyle{block3} = [draw, fill=green!20, rectangle,minimum height=3em, minimum width=4em]
    \tikzstyle{sum} = [draw, fill=white!20, circle, node distance=1.5cm]
    \tikzstyle{sum1} = [draw, fill=white!20, circle, node distance=1.5cm]
    \tikzstyle{input} = [coordinate]
    \tikzstyle{output} = [coordinate]
    \tikzstyle{pinstyle} = [pin edge={to-,thin,white}]


    % The block diagram code is probably more verbose than necessary
    \begin{tikzpicture}[auto,node distance=3.0cm,>=latex']


    % We start by placing the blocks
    \node [input, name=input]{};
    \node [sum, right of=input] (sum){$\Sigma$};
    \node [block, right of=sum,pin={[pinstyle]below:\scriptsize Controlador PI 1}, node distance = 2.5cm](controlador1){$K_{pv}+\frac{K_{iv}}{s}$};

    \node [sum1, right of=controlador1,node distance = 2.5cm] (sum1){$\Sigma$};

    \node [block, right of=controlador1,pin={[pinstyle]below:\scriptsize Controlador PI 2}, node distance = 5cm](controlador2){$K_{pi}+\frac{K_{ii}}{s}$};

    \node [block2, right of=controlador2,pin={[pinstyle]below:\scriptsize Planta de Corrente}, node distance = 3cm](planta1){$G_i(s)$};

    \node [block2, right of=planta1,pin={[pinstyle]below:\scriptsize Planta de Tensão}, node distance = 3cm](planta2){$G_v(s)$};



    % calculate the coordinate vpwm. We need it to place the ems block.
    \draw [->] (controlador2) -- node[name=vpwm] {$d$} (planta1);
    \node [output, right of=planta2,node distance=2.8cm] (output) {};
    \node [block3, below of=sum1,pin={[pinstyle]below:\scriptsize }] (ems) {$Energy\ Management\ System$};


    %connect the nodes
    \draw [draw, ->](input) -- node {$V_{ref}$}(sum);
    \path [->] (sum) edge node {$V_{err}$} (controlador1);
    \path [->] (controlador1) edge node {$I^*_{batt}$}(sum1);
    \path [->] (sum1) edge node {$I_{err}$}(controlador2);
    \path [->] (controlador2) edge node {}(planta1);
    \path [->] (planta1)edge node {$I_{bat}$}(planta2) node[pos=0.95]{$+$};
    \path [->] (planta2) edge node [name=theta] {$V_{DC}$}(output);
    \draw [->] (theta) |- (ems);
    \draw [->] (ems) -| node[pos=0.99] {$-$}
    node [near end] {$V_{med}$} (sum);
    \end{tikzpicture}
\end{document}

The result I desire is:

enter image description here

SrnLord
  • 307

3 Answers3

3

The vertical arrow you know how to do, that's just drawing a line from ems to sum1 with a couple of nodes. Nothing new.

For the other, you can give the I_{batt} node a name (I used ibatt), and then use

\draw [->] (ibatt) |- (ems.5);

to draw the arrow. You know the |- syntax, the .5 indicates an angle of 5 degrees, so you get the point that is on the border of the node, at an angle of 5. If you similarly use \draw [->] (theta) |- (ems.355); to draw the other arrow to ems, the two arrows will be equally distant from the east anchor of ems.

One other point (in addition to the same things as your previous question): Don't write $Energy\ Management\ System$. That's text, not math, so don't write it in math mode. Use just Energy Management System.

enter image description here

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
\usepackage{verbatim}
\usepackage[utf8]{inputenc}

\tikzset{
  block/.style={draw, fill=blue!20, rectangle,minimum height=3em, minimum width=4em},
  block2/.style={draw, fill=white!20, rectangle,minimum height=3em, minimum width=4em},
  block3/.style={draw, fill=green!20, rectangle,minimum height=3em, minimum width=4em},
  sum/.style={draw, fill=white!20, circle, node distance=1.5cm},
  sum1/.style={draw, fill=white!20, circle, node distance=1.5cm},
  input/.style={coordinate},
  output/.style={coordinate},
  pinstyle/.style={pin edge={to-,thin,white}}
}

\begin{document}



    % The block diagram code is probably more verbose than necessary
    \begin{tikzpicture}[auto,node distance=1.5cm,>=latex']


    % We start by placing the blocks
    \node [input, name=input]{};
    \node [sum, right=of input] (sum){$\Sigma$};
    \node [block, right=of sum,pin={[pinstyle]below:\scriptsize Controlador PI 1}](controlador1){$K_{pv}+\frac{K_{iv}}{s}$};

    \node [sum1, right=of controlador1] (sum1){$\Sigma$};

    \node [block, right=4cm of controlador1,pin={[pinstyle]below:\scriptsize Controlador PI 2}](controlador2){$K_{pi}+\frac{K_{ii}}{s}$};

    \node [block2, right=of controlador2,pin={[pinstyle]below:\scriptsize Planta de Corrente},](planta1){$G_i(s)$};

    \node [block2, right=of planta1,pin={[pinstyle]below:\scriptsize Planta de Tensão}](planta2){$G_v(s)$};



    % calculate the coordinate vpwm. We need it to place the ems block.
    \draw [->] (controlador2) -- node[name=vpwm] {$d$} (planta1);
    \node [output, right=of planta2,node distance=2.8cm] (output) {};
    \node [block3, below=of sum1,pin={[pinstyle]below:\scriptsize }] (ems) {Energy Management System};


    %connect the nodes

    \draw [->] (ems) -- (sum1) node[pos=0.8,swap] {$I_{\mathrm{foo}}$} node[swap,pos=0.99] {$-$};

    \draw [->](input) -- node {$V_{\mathrm{ref}}$}(sum);
    \path [->] (sum) edge node {$V_{\mathrm{err}}$} (controlador1);
    \path [->] (controlador1) edge node {$I^*_{\mathrm{batt}}$}(sum1);
    \path [->] (sum1) edge node {$I_{\mathrm{err}}$}(controlador2);
    \path [->] (controlador2) edge node {}(planta1);
    \path [->] (planta1)edge node (ibatt) {$I_{\mathrm{batt}}$}(planta2) node[pos=0.95]{$+$}; % added (ibatt) name to first node
    \path [->] (planta2) edge node [name=theta] {$V_{DC}$}(output);
    \draw [->] (theta) |- (ems.355); % use a specific anchor -- 355 indicates an angle
    \draw [->] (ems) -| node[pos=0.99] {$-$}  node [near end] {$V_{\mathrm{med}}$} (sum);

    \draw [->] (ibatt) |- (ems.5); % above we used 355, so here we use 5, which makes it symmetric
    \end{tikzpicture}
\end{document}
Torbjørn T.
  • 206,688
  • but is not centralized, how to make the two arrows stay centralized in the "Energy Management System"? – SrnLord Jun 29 '18 at 20:09
  • Instead of a manual adjustment, I would use the angular border anchors. This would allow you to put the incoming lines equally spaced: use (ems.355) and (ems.5) for the bottom and top lines respectively. – Alan Munn Jun 29 '18 at 20:10
  • @SrnLord You didn't say anything at about that in the question, and your drawing doesn't illustrate it. I can't read your mind, if you have specific demands, then you have to state those clearly in the question. Alan's suggestion makes sense in that case, I'll edit in a bit. – Torbjørn T. Jun 29 '18 at 20:14
  • @AlanMunn I went by the drawing, didn't think about any symmetry. But good idea, thanks. – Torbjørn T. Jun 29 '18 at 20:15
  • Sorry Torbjorn, I did not mean to sound rude – SrnLord Jun 29 '18 at 20:21
  • @SrnLord You didn't sound rude exactly (I probably sounded more rude), just remember to clearly explain what you want to do. – Torbjørn T. Jun 29 '18 at 20:25
  • @SrnLord Is my updated answer what you wanted, by the way? – Torbjørn T. Jun 29 '18 at 20:53
3

Just for fun, another option using nodes relating to shapes, for example for the arrows in the EMS (Energy management System) EMS.4 and EMS.-4, node which is the node that intercepts the edge of the shape with the written angle (see section 17.9 in visual tikz manual).

To name all the arrows I use the definitions of nodes in paths, which allows you to find and define a node at a certain distance according to a factor, you can see them in the visual tikz manual section 7.9.

The mixer node is given by circuitikz package, and the insertion of the signs is done by labels relative to nodes section 7.7 in the manual.

RESULT:

enter image description here

MWE:

% arara: pdflatex: {synctex: yes, action: nonstopmode}
% By J. Leon V. Share as Beerware philosophy
\documentclass[tikz, border=15pt]{standalone}
\usepackage{amsbsy}% Used to make bold text in math mode by macro \pmb
%\usepackage{xcolor}% This package is already loaded by tikz (Obs. thanks to: Torbjørn T)
\usepackage{tikz}
\usepackage{circuitikz}% Used for mixer node.
\usetikzlibrary{
    arrows.meta,%increase options for arrows personalization
    shapes, % include nodes relative to the shape.
    positioning % Allows positioning relative to nodes.
    } 

\begin{document}
    \begin{tikzpicture}[
        %Environment Configuration
        %None global cfg
        %Styles
        Block/.style = {% Style for block systems
            rectangle, 
            draw,
            minimum height=3em, 
        },
        Sign/.style = {% Style for signs in mixer 
            font=\tiny,
            label distance=-1.5pt
        },
        Name/.style = {% Style for arrow labels
            font=\small,
            label distance=5pt
        },
        MyArrow/.style = {% Style for arrows
            line width=0.75pt,
            -{Stealth[inset=0pt]}, % It causes tokenExeptions in TikzEdt, but compiles normally.
        },
    ]
    % Start drawing "the thing..." 
    \node (Input)[%Initial node
    ]{};
    \node (Sum1)[%first Mixer
        mixer, % From Circuitikz
        scale=0.6,
        right=1.2cm of Input, % Position declaration for positioning lib.
        label={[Sign]180:$\pmb{+}$},
        label={[Sign]-90:$\pmb{-}$},
    ]{};
    \node(PI-1)[%First block system
        Block,
        right=1.5cm of Sum1,
        fill=blue!30,
        label={[Name]-90:Controlador PI 1},
    ]{$K_{pv}+\frac{K_{iv}}{s}$};
    \node (Sum2)[%Second mixer
        mixer, % From Circuitikz
        scale=0.6,
        right=1.2cm of PI-1, % Position declaration for positioning lib.
        label={[Sign]180:$\pmb{+}$},
        label={[Sign]-90:$\pmb{-}$},
    ]{};
    \node(PI-2)[%Second block system
        Block,
        right=1.5cm of Sum2,
        fill=blue!30,
        label={[Name]-90:Controlador PI 2},
    ]{$K_{pi}+\frac{K_{ii}}{s}$};
    \node(Gi)[
        Block,
        right=1.5cm of PI-2,
        %fill=blue!30,
        minimum width=1.5cm,
        label={[Name]-90:Planta de corriente},
    ]{$G_i(S)$};
    \node(Gv)[
        Block,
        right=2.5cm of Gi,
        %fill=blue!30,
        minimum width=1.5cm,
        label={[Name]-90:Planta de Tensão},
    ]{$G_v(s)$};
    \node (Output)[
        right=2.5cm of Gv,
    ]{};
    \node (EMS)[
        Block,
        inner xsep=5pt,
        fill=green!20,
        below=2cm of Sum2,
        minimum height=2.5em
    ]{\it Energy Management System};

    \draw[MyArrow] (Input) -- (Sum1.west) node[midway,above]{$V_{ref}$};
    \draw[MyArrow] (Sum1.east) -- (PI-1) node[midway,above]{$V_{err}$};
    \draw[MyArrow] (PI-1) -- (Sum2.west) node[midway,above]{$V^*_{batt}$};
    \draw[MyArrow] (Sum2.east) -- (PI-2) node[midway,above]{$I_{err}$};
    \draw[MyArrow] (PI-2) -- (Gi) node[midway,above]{$d$};
    \draw[MyArrow] (Gi) -- (Gv) node[ sloped,midway,](loop2){} node[midway,above]{$I_{bat}$};
    \draw[MyArrow] (Gv) -- (Output) node[sloped,midway](loop1){} node[midway,above]{$V_{DC}$};

    \draw[fill](loop1.center) circle (1.5pt); 
    \draw[MyArrow] (loop1.center) |- (EMS.-4); 
    \draw[fill](loop2.center) circle (1.5pt); 
    \draw[MyArrow] (loop2.center) |- (EMS.4);
    \draw[MyArrow] (EMS) -- (Sum2.south) node[midway, anchor=west]{$I_{med}$};
    \draw[MyArrow] (EMS) -| (Sum1.south) node[pos=0.77, anchor=east]{$V_{med}$};

     \end{tikzpicture}
\end{document}
J Leon V.
  • 11,533
  • 16
  • 47
  • 1
    Minor detail: xcolor (which by the way is already loaded by TikZ) is used, in for example blue!30. The ! syntax is from xcolor. – Torbjørn T. Jun 30 '18 at 07:19
  • Just for that reason I thought it was a default syntax, I'll clarify that topic. – J Leon V. Jun 30 '18 at 16:15
  • one m0re minor detail: with option tikz document class standalone, load the packagetikz. therefore\usepackage{tikz}` is not needed (but it will not harm). – Zarko Jun 30 '18 at 16:29
  • Those minimal details are really important, thank you. – J Leon V. Jun 30 '18 at 16:32
2

an alternative way how to draw this block scheme:

enter image description here

in code are used library chains for positioning of nodes, calc for calculate coordinates of branch point and quotes for edge labels. defined is one rectangle node type which color is defined locally. for block labels are used `label and its sintax:

\documentclass[tikz, border=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                calc, chains,
                positioning,
                quotes,
                shapes}

\tikzset{
     block/.style = {rectangle, draw, fill=#1, minimum height=3em, minimum width=4em,
                     on chain},
   block/.default = white,
       sum/.style = {circle, draw, minimum size=6mm, inner sep=0pt, outer sep=0pt,
                     node contents={\huge$+$},
                     on chain},
        }

\begin{document}
    \begin{tikzpicture}[auto,
    node distance = 1.5cm,
      start chain = going right,
every edge/.style = {draw, semithick, -Stealth},
every label/.append style = {label distance=1mm, font=\scriptsize}
                        ]
% We start by placing the blocks
\coordinate[label=$+$,on chain] (input);
\node (sum) [sum];
\node (controlador1) [block=blue!30, label=below:Controlador PI 1] {$K_{pv}+\frac{K_{iv}}{s}$};
\node (sum1) [sum];
\node (controlador2) [block=blue!30, label=below:Controlador PI 2] {$K_{pi}+\frac{K_{ii}}{s}$};
\node (planta1) [block, label=below:Planta de Corrente] {$G_i(s)$};
\node (planta2) [block, label=below:Planta de Tensão] {$G_v(s)$};
\coordinate[on chain2] (output);
% Energy Management System + additional coordinates
\node(ems)  [block=green!30, below=of sum1] {Energy Management System};
\coordinate[above=2mm of ems.east] (ems1);
\coordinate[below=2mm of ems.east] (ems2);
%connect the nodes
\path   (input)         edge ["$V_{\mathrm{ref}}$"]     (sum)
        (sum)           edge ["$V_{\mathrm{err}}$"]     (controlador1)
        (controlador1)  edge ["$I^*_{\mathrm{batt}}$"]  (sum1)
        (sum1)          edge ["$I_{\mathrm{err}}$"]     (controlador2)
        (controlador2)  edge                            (planta1)
        (planta1)       edge ["$I_{\mathrm{batt}}$"]    (planta2)
        (planta2)       edge ["$V_{DC}$"]               (output)
        (ems)           edge ["$I_{\mathrm{foo}}$"] node[pos=0.95] {$-$}     (sum1);
%
    \begin{scope}[semithick, -Stealth]
\draw   (ems) -| node [near end] {$V_{\mathrm{med}}$} node[pos=0.95] {$-$}  (sum);
%
\draw   ($(planta2)!0.5!(planta1)$) |- (ems1);
\draw   ($(planta2.east)!0.5!(output)$) |- (ems2);
        \end{scope}
    \end{tikzpicture}
\end{document}
Zarko
  • 296,517