2

Tl;dr @Rmano's answer points out a major hint: Prependicular coordinates with predefined coordinates can significantly ease drawing electrical schematics.

Id like to draw something like the following. I just cannot figure out how to combine a text boxed, custom voltage buses, switches and (custom) converters more intuitively/clean so the wiring will fit and be straight. The MWE below apparently would work but has major flaws in close up listed below. Its a mockup of the objects I will be using, but its going to be a bit more complex in the end, which is why I would like to have versatile shapes and anchors.

Voltsage Buses

  • currently a line instead of a shape with specific anchors to attach wiring to other objects
  • currently position hard-coded whereas Id like to adjust in relation to any text-block's (or shapes) center
  • horizontal width has to be adjustable

Converters

  • DC/DC isnt used as a shape at all, no useful anchors
  • DC/AC isnt properly attached with in- and out-wiring

Also the wiring thickness of switch and converters seem to mismatch. Its a lot to ask, but I am struggling to put this together more intuitively so any help or hint is appreciated.

\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\usepackage{pgfplots}
    \pgfplotsset{compat=newest}
\usetikzlibrary{positioning, shapes, arrows, backgrounds, chains, fit, }

\begin{document}
\begin{circuitikz}[
block/.style = {rectangle, draw, text centered, inner sep=.2cm},
sdcdc/.style = {twoportsplit, t1={$=$}, t2={$=$}},
]
    % block
    \node [block] (pvgen) {PV-Generator};
    % bus
    \draw [ultra thick] (pvgen.south)++(-2,-1) node[anchor=south west](pvbus){PV} -- ++(4,0);
    \draw [ultra thick] (pvgen.south)++(-2,-8) node[anchor=south west](acbus){AC} -- ++(8,0);
    \draw [ultra thick] (pvgen.south)++(-2,-5) node[anchor=south west](dc1bus){DC1} -- ++(4,0);
    % switch
    \draw (pvbus.270)++(1.5,0) -- ++(0,-.5) node[spdt,anchor=in, rotate=270](spv) {};
    % labels
    \draw 
        (spv.in) node[right] {\texttt{S PV}}
        (spv.out 1) node[right] {\texttt{1}}
        (spv.out 2) node[left] {\texttt{0}};    
    % dcdc
    \draw (spv.out 1) to [sdcdc] ++(0,-2) node[](pvdcdc){};
    % dcac
    \draw (dc1bus.270)++(1.5,0) -- ++(0,-1) node[sdcacshape, anchor=north](pvdcac){};
    % lines
    \draw (acbus.270)++(1.6,0) -- (pvdcac.south);
    \draw (pvgen.south) -- ++(0,-1);
    \draw (dc1bus.270)++(1.72,0) -- (pvdcdc.center);
    \draw (dc1bus.270)++(1.1,0) -- (spv.out 2);
    
\end{circuitikz}
\end{document}

Latex Output as shown above

EDIT: This is one desired final schematics. The thick, grey marker line is not of much importance as of now. It is used to show different possible pathways later on if possible. But the actual schematic is more important. Hand sketch of one(!) final schematic.

4
  • 1
    it would be helpful to show what is the desired output also as a hand sketch
    – js bibra
    Apr 27 at 12:13
  • well basically this above. But Ill add my hand sketch as well, cheers.
    – Pratched
    Apr 27 at 12:26
  • Except for the rotary switch (pages 113-115) the sketch looks fairly straight forward. Apr 27 at 13:07
  • 1
    Yeah, I guess so. Im probably just not very used to work with tikz in general and got very confused by all the examples I found earlier. But @Rmano's answer seems very helpful, as it not only provides a solution but hints as to how to set something like this up in the future.
    – Pratched
    Apr 27 at 13:16
2

I would say: you use too many nodes and do not rely on perpendicular coordinate systems and named coordinates. I would rewrite your example like this in the following excerpt. Every object is positioned just by a fixed number, all the rest is computed by using perpendicular coordinates in the form (A -| B).

\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\usepackage{pgfplots}
    \pgfplotsset{compat=newest}
\usetikzlibrary{positioning, shapes, arrows, backgrounds, chains, fit, }

\begin{document}
\begin{circuitikz}[
    block/.style = {rectangle, draw, text centered, inner sep=.2cm},
    sdcdc/.style = {twoportsplit, t1={$=$}, t2={$=$}},
    ]
    % block
    \node [block] (pvgen) {PV-Generator};
    % bus
    % mark the coordinate where the PV bus starts
    \draw [ultra thick] (pvgen.south)++(-2,-1) coordinate(pvbus)
    node[anchor=south west]{PV} -- ++(4,0);
    % the other buses starts at the same place, going down
    \draw [ultra thick] (pvbus) ++(0,-8) coordinate (acbus)
    node[anchor=south west]{AC} -- ++(8,0);
    \draw [ultra thick] (pvbus) ++(0,-5) coordinate(dc1bus)
    node[anchor=south west]{DC1} -- ++(4,0);
    % connect pvgen to bus (the second coordinate means:
    % vertical of pvgen.south and horizontal of pvbus;
    \draw (pvgen.south) -- (pvgen.south|-pvbus);
    % switch, connected 1.5 right in the pvbus "rail"
    \draw (pvbus) ++(1.5,0) coordinate(switch1) -- ++(0,-0.5)
        node[spdt,anchor=in, rotate=270](spv) {};
    % labels
    \draw
    (spv.in) node[right] {\texttt{S PV}}
    (spv.out 1) node[right] {\texttt{1}}
    (spv.out 2) node[left] {\texttt{0}};
    % dcdc
    \draw (spv.out 1) to [sdcdc] ++(0,-2) -- (spv.out 1|-dc1bus);
    \draw (spv.out 2) -- (spv.out 2|-dc1bus);
    % dcac
    \draw (dc1bus)++(1.5,0) coordinate(my dcac 1)
        to[sdcac] (acbus-|my dcac 1);
\end{circuitikz}
\end{document}

enter image description here

For example, just changing the two ++(1.5,0) on DC and AC bus to ++(2,0) gives (no other change needed):

enter image description here

And naming all the coordinates on the go, the "path line" becomes trivial:

\draw[orange, opacity=0.3, line width=4mm, rounded corners]
    (pvgen.south) |- (switch1) -- (spv.in) -- 
    (spv.out 1) |- (my dcac 1) -- (my dcac 1|-acbus); 

enter image description here

Notice the |- and -| line commands: respectively, vertical then horizontal, horizontal then vertical.

I think that the perpendicular coordinate system is the most useful TikZ idiom for circuits.

2
  • 1
    This is very helpful! Thanks for the patience to go through my code. Didnt use the perpendicular coordinate system before at all, but this seems very useful indeed. I will check it out later in detail! The easy to integrate "path line" is a very nice benefit. Cheers!
    – Pratched
    Apr 27 at 13:14
  • 1
    Ah yeah, forgot about that. Done.
    – Pratched
    Apr 28 at 8:42

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.