使用 Tikz 创建箭头和路径时出现问题

使用 Tikz 创建箭头和路径时出现问题

现在我尝试使用 Tikz 创建下图:

在此处输入图片描述

但我在不同节点之间创建箭头时遇到了问题,尤其是节点 amcl、传感器变换和测距源之间的箭头,箭头“/tf”,从上面描述的箭头指向节点 move_base。最后一个箭头,我遇到了问题,从传感器源指向本地代价地图和全局代价地图之间的箭头。

有人能帮我画这幅图吗?

提前非常感谢您!

我现在的代码如下所示:

\begin{tikzpicture}
    \node[draw, minimum height=1cm, minimum width=3.7cm, scale=0.75](amcl) at (0,1.6){amcl};
    \node[draw, minimum height=1cm, minimum width=3.7cm, scale=0.75](sensor transforms) at (0, 0){sensor transforms};
    \node[draw, minimum height=1cm, minimum width=3.7cm, scale=0.75](odometry source) at (0, -1.6){odometry source};

    \node[draw, minimum height=1cm, minimum width=3.7cm, scale=0.75](map server) at (14, 1.6){map server};
    \node[draw, minimum height=1cm, minimum width=3.7cm, scale=0.75](sensor sources) at (14, 0.0){sensor sources};

    \node[draw, minimum height=6cm, minimum width=7cm](move base) at(7,0){};
    \node[draw, ellipse, text width=1.5cm, scale=0.75](global planner) at(5.3,1.6){global planner};
    \node[draw, ellipse, text width=1.5cm, scale=0.75](global costmap) at(8.8,1.6){global costmap};
    \node[draw, ellipse, text width=2.4cm, scale=0.75](local planner) at(5.3, -1.6){local planner};
    \node[draw, ellipse, text width=2.5cm, scale=0.75](local costmap) at(8.8, -1.6){local costmap};
    \node[draw, ellipse, text width=1.75cm, scale=0.75](recovery behaviors) at(7.05, 0.0){recovery behaviors};

    \node[draw, minimum height=1cm, minimum width=3.7cm, scale=0.75](base controller) at (5.3, -4.0){base controller};


    \draw[->](map server) -- (global costmap);
    \draw[->](global costmap) -- (global planner);
    \draw[->](global planner) -- (local planner);
    \draw[->](local costmap) -- (recovery behaviors);
    \draw[->](local costmap) -- (local planner);
    \draw[->](global costmap) -- (recovery behaviors);
    \draw[<->](global costmap) -- (local costmap);
    \draw[->](local planner) -- (base controller);
    \draw[->](odometry source) -- (local planner);
\end{tikzpicture}

答案1

这是添加箭头的一种方法。我还切换到相对定位,使用同名的库,并添加了其他几个功能,例如copy shadows,本地边界框和fit。重复的 pgf 键集合会被样式所吸收。您必须完成边缘文本。(不,我不认为这个quotes库会让这里的事情变得简单得多。;-)

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{shapes.geometric,fit,positioning,shadows}
\begin{document}
\begin{tikzpicture}[box/.style={draw, minimum height=1cm, minimum
        width=3.7cm, scale=0.75},
  elli/.style={draw, ellipse, text width=1.5cm, scale=0.75,align=center},
  Blue/.style={fill=blue!20},Gray/.style={fill=gray!20},
  bullet/.style={circle,fill,inner sep=1pt},
  >=stealth,font=\sffamily,node distance=2.5em]
  %
    \begin{scope}[local bounding box=left]
     \node[box,Gray](amcl){amcl};
     \node[box,below=of amcl,double copy shadow={shadow xshift=-.5ex},Blue](sensor transforms) {sensor transforms}; 
     \node[box,below=of sensor transforms,Blue](odometry source){odometry source};
    \end{scope} 
    %
    \begin{scope}[local bounding box=ellipses,anchor=center,nodes=elli]
     \node[right=3.8cm of odometry source, text width=2.4cm](local planner){local planner};
     \path (local planner.center) 
        ++ (0,3) node(global planner) {global planner}
        ++ (4,0) node(global costmap){global costmap}
        ++ (0,-3)   node[text width=2.5cm](local costmap){local costmap};
     \path  (local planner.center) --  (global costmap.center)
      node[text width=1.75cm,midway](recovery behaviors) {recovery behaviors};
    \end{scope} 
    \node[draw, fit=(ellipses),inner sep=5mm,
        label={[anchor=north west,scale=0.6]north west:move\_base}](move base){};
    %
    \node[box,above right=0em and 3.8cm of global costmap,Gray](map server) {map\_server};
    \node[box,below=4em of map server,double copy shadow={shadow xshift=-.5ex},Blue](sensor sources) {sensor sources};
    %
    \node[box,below=2cm of local planner,Blue](base controller){base controller};
    %
    \node[right=1ex of sensor transforms,bullet] (p){};
    \node[bullet] at (sensor sources-|local costmap)(q){};
    \begin{scope}[semithick,nodes={scale=0.6,align=center}]
    \draw (amcl) -| (p) (odometry source) -| (p) (sensor transforms) -- (p);
    \draw[->](amcl) -- (sensor transforms);
    \draw[->](sensor transforms)-- (odometry source);
    \draw[->] (p) -- node {"tf"\\[1ex] tf/tMessage} (p-|move base.west);
    \draw[<->](local costmap)-- (global costmap);
    \draw[->](map server) -| 
        node[pos=0.15] {"/map"\\[1ex] nav\_get...} (global costmap);
    \draw[->](global costmap) -- (global planner);
    \draw[->](global planner) -- (local planner);
    \draw[->](local costmap) -- (recovery behaviors);
    \draw[->](local costmap) -- (local planner);
    \draw[->](global costmap) -- (recovery behaviors);
    \draw[<->](global costmap) -- (local costmap);
    \draw[->](local planner) -- node[pos=0.7,left]{"cmd\_vel"}
         node[pos=0.7,right]{"geometry\_message/Twist"} (base controller);
    \draw[->](odometry source) --  node {"odom"\\[1ex] nav\_mess/Odometry} (local planner);
    \draw[->](sensor sources)-- node[above,pos=0.3]{bla} node[below,pos=0.3]{blub}(q);
    \end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容