我正在尝试创建一个由微控制器及其外围设备组成的电机控制器图表。
1)如何使用 circuitikz 在线上得到红点。2)在电阻器下方绘制电流箭头,右侧为 Im。
请看下图。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,shadows,backgrounds, calc, fit}
\usepackage{amsmath,bm,times}
\usepackage[european]{circuitikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
\begin{document}
\tikzstyle{peripheral} = [draw, fill=blue!10, rectangle, minimum height=3em,
text width=6em, align = flush center, rounded corners, thick, drop shadow]
\tikzstyle{micro} = [draw, fill=green!10, rectangle, minimum height=7em, minimum
width = 8em, rounded corners, thick, drop shadow]
\tikzstyle{motor} = [draw, fill=yellow!10, circle, radius=2cm, thick, drop shadow]
\tikzstyle{motorConnector} = [draw, fill=black, rectangle, draw=black, inner sep=1mm];
\tikzstyle{line1} = [draw, thick, ->, shorten >= 1pt, >=stealth']
\tikzstyle{line2} = [draw, thick, <->, shorten >= 1pt, shorten <=1pt, >=stealth']
\tikzstyle{line3} = [draw, thick, shorten >=1pt]
\tikzstyle{line4} = [draw, line width=5pt , shorten >=1pt]
%beginning tikz
\begin{tikzpicture} [auto, node distance = 1cm, >=latex', background
rectangle/.style= {fill=yellow!10, draw=blue!15, rounded corners=1ex}, show
background rectangle, circuitikz]
\matrix [column sep = 1cm, row sep = 0.5cm] at (0,0)
{
\node [peripheral] (timer) {Timers}; &
\node [peripheral] (rtc) {RTC}; &
\node [peripheral] (watchdog) {Watch Dog}; &\\
%row 2
\node [peripheral] (comm) {Serial \\Interface}; &
\node [micro] (cpu) {CPU}; &
\node [peripheral] (dac) {DAC}; &\\
%row 3
\node [peripheral] (pwm) {PWM Timer}; &
\node [peripheral] (adc) {ADC}; &
\node [peripheral] (qdec) {Quadrature \\ Decoder}; &\\
%row5
\node [peripheral, yshift=-1.5cm] {Motor Driver};&
\node {};&
\node {};&\\
%row6
\node {};&
\node [xshift = -1cm, motor] (motor) {Motor};&\\
\node {};&\\
};
\node [draw=black, inner sep= 0.75cm, fit={(timer) (qdec) (pwm)}, rounded
corners=1ex, thick, fill=black!20, opacity=0.1] (motorController) {};
\node [yshift = -0.30cm, thick] at (motorController.north) {\large$Motor Controller$};
\node [motorConnector] at (motor.north) (connector1) {};
\node [motorConnector] at (motor.south) (connector2) {};
\draw (connector2.south) to [R=$R_I$] +(0,-3)
[red, *-] {($(connector2.south) + (0,-0.5)$) -| (adc.south)} ;
\node [ground] at ($(connector2.south) + (0,-3)$) {};
\end{tikzpicture}
\end{document}
答案1
这是一个可能的解决方案,修改位于该代码末尾附近。
代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,shadows,backgrounds, calc, fit}
\usepackage{amsmath,bm,times}
\usepackage[european]{circuitikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
\begin{document}
\tikzstyle{peripheral} = [draw, fill=blue!10, rectangle, minimum height=3em,
text width=6em, align = flush center, rounded corners, thick, drop shadow]
\tikzstyle{micro} = [draw, fill=green!10, rectangle, minimum height=7em, minimum
width = 8em, rounded corners, thick, drop shadow]
\tikzstyle{motor} = [draw, fill=yellow!10, circle, radius=2cm, thick, drop shadow]
\tikzstyle{motorConnector} = [draw, fill=black, rectangle, draw=black, inner sep=1mm];
\tikzstyle{line1} = [draw, thick, ->, shorten >= 1pt, >=stealth']
\tikzstyle{line2} = [draw, thick, <->, shorten >= 1pt, shorten <=1pt, >=stealth']
\tikzstyle{line3} = [draw, thick, shorten >=1pt]
\tikzstyle{line4} = [draw, line width=5pt , shorten >=1pt]
%beginning tikz
\begin{tikzpicture} [auto, node distance = 1cm, >=latex', background
rectangle/.style= {fill=yellow!10, draw=blue!15, rounded corners=1ex}, show
background rectangle, circuitikz]
\matrix [column sep = 1cm, row sep = 0.5cm] at (0,0)
{
\node [peripheral] (timer) {Timers}; &
\node [peripheral] (rtc) {RTC}; &
\node [peripheral] (watchdog) {Watch Dog}; &\\
%row 2
\node [peripheral] (comm) {Serial \\Interface}; &
\node [micro] (cpu) {CPU}; &
\node [peripheral] (dac) {DAC}; &\\
%row 3
\node [peripheral] (pwm) {PWM Timer}; &
\node [peripheral] (adc) {ADC}; &
\node [peripheral] (qdec) {Quadrature \\ Decoder}; &\\
%row5
\node [peripheral, yshift=-1.5cm] {Motor Driver};&
\node {};&
\node {};&\\
%row6
\node {};&
\node [xshift = -1cm, motor] (motor) {Motor};&\\
\node {};&\\
};
\node [draw=black, inner sep= 0.75cm, fit={(timer) (qdec) (pwm)}, rounded
corners=1ex, thick, fill=black!20, opacity=0.1] (motorController) {};
\node [yshift = -0.30cm, thick] at (motorController.north) {\large$Motor Controller$};
\node [motorConnector] at (motor.north) (connector1) {};
\node [motorConnector] at (motor.south) (connector2) {};
%%%-- some modification starts here
\draw (connector2.south) to [R=$R_I$] +(0,-3)
{($(connector2.south) + (0,-0.5)$) -| (adc.south)}
[red,*-] {($(connector2.south) + (0,-0.46)$)}; %< -- the red node
\node [ground] at ($(connector2.south) + (0,-3)$) {};
\draw[red,->] ($(connector2.south)+(0,-2.2)$) to [] +(0,-0.5)node[right]{$I=1mA$}; %<--the current arrow
\end{tikzpicture}
\end{document}