有限状态机 (FSM) 状态图与 LATEX

状态图是表示状态机的一种有用的方式。不幸的是,它们很难开发。通常需要相当多的时间来制作一个视觉上吸引人的草图。

一种解决方案是使用LATEX排版。在某些方面,LATEX就像你最喜欢的文字处理。不同之处在于格式是通过文本描述来控制的。此外,所有原始文档都以.txt或.tex文件完成。当它们完成后,一个tex“编译器”被用来生成成品,通常以.pdf文档的形式。在某些方面,它就像使用html开发网页。

LATEX的美妙之处在于它能够利用程序员可用的所有脚本和技巧将复杂的文档拼接在一起。关于底层纯文本文档的实用性和开放性也有一些要说的。

tikz这样的LATEX包使得呈现状态表的过程相对容易,结果具有代表性,如图1和图2所示。相关的代码附在本文的末尾。这些图像是使用TeXworks 渲染的。

技术贴士 :本技术论坛对LATEX的支持有限。这在显示数学方程式时特别有用。例如,欧姆定律被写成R= \dfrac{E}{I},然后把它放在两个$符号之间得到:

image

不幸的是,LATEX的学习曲线是陡峭的。因此,我们不会试图在这篇短文中描述这个过程。相反,用于生成图1和图2的代码被不加注释地附加到本说明中,希望对你有所帮助。
注:如果你对LATEX感兴趣,请查找在线教程。另外,一定要查找允许你看到渲染文本的在线页面。


1 :具有复位功能的简单CAM操作状态机的状态图。


2 :具有复杂状态转换的机器的状态图。

\documentclass{article}
 
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
 
	\usepackage{geometry}
 
	\geometry{
		letterpaper,
		% total={170mm,257mm},
		 left=0.5in,
		 right =0.5in,
		top=0.5in,
		bottom=0.75in
	 }
 
 
\begin{document}
 
 
\begin{tikzpicture} [state/.style=state with output, ->,>=stealth',shorten >=1pt,auto,node distance=5.0cm, semithick]
 
\tikzstyle{every state}=[fill=blue!20,draw=black,text=black]
 
	\node[initial,state]	(1) 						{$Idle$ \nodepart{lower} 	$0000001$};
	\node[state]			(2) [above right of = 1]	{$Alarm$ \nodepart{lower} 	$0010010$};
	\node[state]			(3) [right of = 2]			{$Forward$ \nodepart{lower} $1000110$};
	\node[state]			(4) [below right of = 3]	{$Delay$ \nodepart{lower} 	$0001010$};
	\node[state]			(5) [below left of = 4]		{$Alarm$ \nodepart{lower} 	$0010010$};
	\node[state]			(6) [left of = 5]			{$Reverse$ \nodepart{lower} $0100110$};
 
	\path	(1)	edge	[sloped, anchor=center, above, in=205, out= 65]			node {Cycle PB}		(2)
 
			(2) edge	[sloped, anchor=center, above, in=160, out= 20]			node {Done}			(3)
				edge	[sloped, anchor=center, below, in=20, out=-110]			node {$Reset$}		(1)
 
			(3) edge	[sloped, anchor=center, above, in=110, out=-20]			node {5 seconds}	(4)
				edge	[sloped, anchor=center, below, in=10, out=-135]			node {$Reset$}		(1)
 
			(4) edge	[sloped, anchor=center, below , in=20, out=-110]		node {$3 seconds$}	(5)
				edge	[sloped, anchor=center, below, in=-10, out=200]			node {$Reset$}		(1)
 
			(5) edge 	[sloped, anchor=center, below, in=-20, out=200]			node {Done}			(6)
				edge	[sloped, anchor=center, below, in=-20, out=160]			node {$Reset$}		(1)
 
			(6) edge 	[sloped, anchor=center, below, in=-70, out=155]			node {5 seconds}	(1)
				edge	[sloped, anchor=center, below, in=-30, out=110]			node {$Reset$}		(1)
 
		; % Don't forget this semicolon
 
\end{tikzpicture}
 
 
\newpage
 
 
\begin{tikzpicture} [state/.style=state with output, ->,>=stealth',shorten >=1pt,auto,node distance=5.0cm, semithick]
 
\tikzstyle{every state}=[fill=blue!20,draw=black,text=black]
 
	\node[initial,state]	(1) 						{$1$ \nodepart{lower} $Retracting$};
	\node[state]			(2) [above right of=1]		{$2$ \nodepart{lower} $Retracted$};
	\node[state]			(3) [below right of=2]		{$3$ \nodepart{lower} $Extending$};
	\node[state]			(4) [below left of=3]		{$4$ \nodepart{lower} $Extended$};
	\node[state]			(5) [below of=4]			{$5$ \nodepart{lower} $Fault$};
 
	\path	(1)	edge	[sloped, anchor=center, above]										node {xSenRet}				(2)
				edge	[sloped, anchor=center, below, in=200, out=-20]						node {$xEN$}				(3)
				edge	[sloped, anchor=center, below, bend right]							node {t $>$ timeMove}		(5)
 
			(2) edge	[sloped, anchor=center, above]										node {xEn}					(3)
				edge	[sloped, anchor=center, below, min distance=7cm, in=10, out=-10]	node {$\overline{xSenRet}$}	(5)
 
			(3) edge	[sloped, anchor=center, above]										node {xSenExt}				(4)
				edge	[sloped, anchor=center, above, in=20, out=160]						node {$\overline{xEN}$}		(1)
				edge	[sloped, anchor=center, below, bend left]							node {t $>$ timeMove}		(5)
 
			(4) edge	[sloped, anchor=center, above]										node {$\overline{xEN}$}		(1)
				edge	[sloped, anchor=center, below]										node {$\overline{xSenExt}$}	(5)
 
			(5) edge    [sloped, anchor=center, below, min distance=2.5cm, in=230, out=170]	node {xReset}				(1)
 
	; % Don't forget this semicolon
 
\end{tikzpicture}
 
 
\end{document}