5

I would like to insert the symbol of a mechanical spring in a node done with TikZ.

This is my code:

    \documentclass{article}

    \usepackage{tikz}
    \usetikzlibrary{shapes,arrows,calc,positioning}
    \tikzset{
     pinstyle/.style={pin edge={to-,thin,black}},
     block/.style = {draw, rectangle,
     minimum height=1cm,
     align = center
     %   minimum width=2cm
     },
     input/.style = {coordinate,node distance=1cm},
     output/.style = {coordinate,node distance=1cm},
      arrow/.style={draw, -latex,node distance=2cm},
      pinstyle/.style = {pin edge={latex-, black,node distance=2cm}},
        sum/.style = {draw, circle, node distance=1cm},
      gain/.style = {regular polygon, regular polygon sides=3,
      draw, fill=white, text width=1em,
      inner sep=0mm, outer sep=0mm,
      shape border rotate=-90}
      }


    \begin{document}
    \begin{figure}
    \begin{center}
    \begin{tikzpicture}[auto,>=latex',every node/.append style={font=\scriptsize}]

    %DEFINIZIONE BLOCCHI
    \node [input, name=input] {};
    \node [sum, right=of input] (speed_sum) {};
    \node [block, right=of speed_sum] (speed_controller) {$C_{\mathrm{vel}}(s)$};
    \node [gain, right=2cm of speed_controller] (Kt) {$K_{t}$};
    \node [block, right=of Kt] (gvm) {$G_{vM}(s)$};
     \node [block, right=of gvm] (elastico) {$\frac{s\Theta_{M}(s)}{s\Theta_{C}(s)}$};
    \node [output, right=of elastico] (output) {};

    %DEFINIZIONE COLLEGAMENTI IN CATENA DIRETTA
    \draw [->] (input) -- node {$\omega_{M}^{\mathrm{DES}}(s)$}(speed_sum);
    \draw [->] (speed_sum) -- node {$E_{v}(s)$}(speed_controller);
    \draw [->] (speed_controller) -- node {$I^{\mathrm{DES}}(s)=I(s)$}(Kt);
    \draw [->] (Kt) -- node {$C_{\mathrm{M}}(s)$}(gvm);
    \draw [->] (gvm) -- node [name=motor_speed] {$s\theta_{M}(s)$}(elastico);
    \draw [->] (elastico) -- node [name=motor_speed] {$s\theta_{C}(s)$}(output);

    %DEFINIZIONE COLLEGAMENTI FEEDBACK
    \draw [->] (motor_speed) -- ++ (0,-2) -| node [pos=0.99] {$-$} (speed_sum);

\end{tikzpicture}
\end{center}

\caption{Anello di controllo di velocit\`a nel caso co-locato}
\label{fig:speed_loop_colocato}
\end{figure}
\end{document}

The output now is as above (first loop in figure) but i want something as below (second loop in figure):

enter image description here

Exactly where I use

 \node [block, right=of gvm] (elastico) {$\frac{s\Theta_{M}(s)}{s\Theta_{C}(s)}$};

I am asking if there is some \textrm{SPRING_SYMBOL} to reproduce a mechanical spring or what would you do to do it?

  • what are the block,sum,input etc style definitions used? – Troy May 19 '17 at 9:10
  • You are right, sorry i totally forgot about it. I'm going to edit the post above. – iacopo May 19 '17 at 9:17
  • Circuitikz has a spring node – Scott Seidman May 19 '17 at 11:07
6

You can draw the spring symbol with TikZ. I wrapped it in a macro in case you need to draw the spring more than once, and also to make the TikZ code neater.

I also recommend using \centering instead of \begin{center}.

Note that there are a few options that you can change to modify the look of the spring. I've placed them each on a separate line in the code, and should be quite self explanatory on what they do. If not, just play around with the numbers yourself. These include: segment length, amplitude, pre length and post length. Of course the coordinates used for the zigzag line can be modified as well.

Code:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows,calc,positioning,decorations.pathmorphing} % <------- add new library
\newcommand*{\drawspring}{%
    \tikz \draw[decorate,decoration={
        zigzag,
        segment length=0.2cm,
        amplitude=2mm,
        pre length=.1cm, 
        post length=.1cm}] (0,0)--(1,0);} % <-------- define a macro to draw the spring (for conciseness)

\tikzset{
    pinstyle/.style={pin edge={to-,thin,black}},
    block/.style = {draw, rectangle,
        minimum height=1cm,
        align = center
        %   minimum width=2cm
    },
    input/.style = {coordinate,node distance=1cm},
    output/.style = {coordinate,node distance=1cm},
    arrow/.style={draw, -latex,node distance=2cm},
    pinstyle/.style = {pin edge={latex-, black,node distance=2cm}},
    sum/.style = {draw, circle, node distance=1cm},
    gain/.style = {regular polygon, regular polygon sides=3,
        draw, fill=white, text width=1em,
        inner sep=0mm, outer sep=0mm,
        shape border rotate=-90}
}

\begin{document}
    \begin{figure}
    \centering
    \begin{tikzpicture}[auto,>=latex',every node/.append style={font=\scriptsize}]

    %DEFINIZIONE BLOCCHI
    \node [input,name=input] {};
    \node [sum,right=of input] (speed_sum) {};
    \node [block,right=of speed_sum] (speed_controller) {$C_{\mathrm{vel}}(s)$};
    \node [gain, right=2cm of speed_controller] (Kt) {$K_{t}$};
    \node [block, right=of Kt] (gvm) {$G_{vM}(s)$};
    \node [block,right=of gvm] (elastico) {\drawspring}; % <--------- draw the spring here in the node
    \node [output, right=of elastico] (output) {};

    %DEFINIZIONE COLLEGAMENTI IN CATENA DIRETTA
    \draw [->] (input) -- node {$\omega_{M}^{\mathrm{DES}}(s)$}(speed_sum);
    \draw [->] (speed_sum) -- node {$E_{v}(s)$}(speed_controller);
    \draw [->] (speed_controller) -- node {$I^{\mathrm{DES}}(s)=I(s)$}(Kt);
    \draw [->] (Kt) -- node {$C_{\mathrm{M}}(s)$}(gvm);
    \draw [->] (gvm) -- node [name=motor_speed] {$s\theta_{M}(s)$}(elastico);
    \draw [->] (elastico) -- node [name=motor_speed] {$s\theta_{C}(s)$}(output);

    %DEFINIZIONE COLLEGAMENTI FEEDBACK
    \draw [->] (motor_speed) -- ++ (0,-2) -| node [pos=0.99] {$-$} (speed_sum);
    \end{tikzpicture}
    \caption{Anello di controllo di velocit\`a nel caso co-locato}
    \label{fig:speed_loop_colocato}
\end{figure}
\end{document}

Output

output image

3

For the coil symbol, see this answer: Draw mechanical springs in TikZ

If you want to repeat the symbol elsewhere, try drawing the symbol nicely somewhere and then reuse it with pics:

\tikzset{ coil/.pic={
\draw (0.1,0) -- (0.2,1) -- (0.4,-1) -- (0.6,1) -- (0.8,-1) --(0.9,0) % and so on
}
}

and then use that with \tikz (0,0) \draw pic{coil}. Works well if you don't need to resize it. From your question, it looks like that is what you want, just the symbol drawn in some way. You can call the pic{coil} at the node just like any other coordinate.

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.