# Example: Annotated manipulator

Published 2006-11-14 | Author: Kjell Magne Fauske

This example shows how you can annotate a technical drawing. The three link manipulator is the same as another example in the gallery. I've used macros extensively to avoid duplicating code.

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de. En français: TeXnique.fr.

\documentclass{article}

\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\pagestyle{empty}

% Note. This illustration was originally made with PSTricks. Conversion to
% PGF/TikZ was straightforward. However, I could probably have made it more
% elegant.

% Define a variable as a length
% Input:
%   #1 Variable name
%   #2 Value
%
% Example:
%   \nvar{\varx}{2cm}
\newcommand{\nvar}[2]{%
\newlength{#1}
\setlength{#1}{#2}
}

% Define a few constants for drawing
\nvar{\dg}{0.3cm}
\def\dw{0.25}\def\dh{0.5}
\nvar{\ddx}{1.5cm}

% Define commands for links, joints and such
\def\link{\draw [double distance=1.5mm, very thick] (0,0)--}
\def\joint{%
\filldraw [fill=white] (0,0) circle (5pt);
\fill[black] circle (2pt);
}
\def\grip{%
\draw[ultra thick](0cm,\dg)--(0cm,-\dg);
\fill (0cm, 0.5\dg)+(0cm,1.5pt) -- +(0.6\dg,0cm) -- +(0pt,-1.5pt);
\fill (0cm, -0.5\dg)+(0cm,1.5pt) -- +(0.6\dg,0cm) -- +(0pt,-1.5pt);
}
\def\robotbase{%
\draw[rounded corners=8pt] (-\dw,-\dh)-- (-\dw, 0) --
(0,\dh)--(\dw,0)--(\dw,-\dh);
\draw (-0.5,-\dh)-- (0.5,-\dh);
\fill[pattern=north east lines] (-0.5,-1) rectangle (0.5,-\dh);
}

% Draw an angle annotation
% Input:
%   #1 Angle
%   #2 Label
% Example:
%   \angann{30}{$\theta_1$}
\newcommand{\angann}[2]{%
\begin{scope}[red]
\draw [dashed, red] (0,0) -- (1.2\ddx,0pt);
\draw [->, shorten >=3.5pt] (\ddx,0pt) arc (0:#1:\ddx);
% Unfortunately automatic node placement on an arc is not supported yet.
% We therefore have to compute an appropriate coordinate ourselves.
\node at (#1/2-2:\ddx+8pt) {#2};
\end{scope}
}

% Draw line annotation
% Input:
%   #1 Line offset (optional)
%   #2 Line angle
%   #3 Line length
%   #5 Line label
% Example:
%   \lineann[1]{30}{2}{$L_1$}
\newcommand{\lineann}[4][0.5]{%
\begin{scope}[rotate=#2, blue,inner sep=2pt]
\draw[dashed, blue!40] (0,0) -- +(0,#1)
node [coordinate, near end] (a) {};
\draw[dashed, blue!40] (#3,0) -- +(0,#1)
node [coordinate, near end] (b) {};
\draw[|<->|] (a) -- node[fill=white] {#4} (b);
\end{scope}
}

% Define the kinematic parameters of the three link manipulator.
\def\thetaone{30}
\def\Lone{2}
\def\thetatwo{30}
\def\Ltwo{2}
\def\thetathree{30}
\def\Lthree{1}

\begin{tikzpicture}
\robotbase
\angann{\thetaone}{$\theta_1$}
\lineann[0.7]{\thetaone}{\Lone}{$L_1$}
\joint
\begin{scope}[shift=(\thetaone:\Lone), rotate=\thetaone]
\angann{\thetatwo}{$\theta_2$}
\lineann[-1.5]{\thetatwo}{\Ltwo}{$L_2$}
\joint
\begin{scope}[shift=(\thetatwo:\Ltwo), rotate=\thetatwo]
\angann{\thetathree}{$\theta_3$}
\lineann[0.7]{\thetathree}{\Lthree}{$L_3$}
\draw [dashed, red,rotate=\thetathree] (0,0) -- (1.2\ddx,0pt);
\joint
\begin{scope}[shift=(\thetathree:\Lthree), rotate=\thetathree]
\grip
\end{scope}
\end{scope}
\end{scope}
\end{tikzpicture}

\end{document}


• #1 Lukas Doktor, April 28, 2009 at 10:19 p.m.

Hi, is it possible to define other angles then only X-axe? I have a robot which have 4 X-axe angles and 2 Z-axe angles.

Some examples how it should look like are here:

http://www.societyofrobots.com/robot_arm_tutorial.shtml

• #2 Kjell Magne Fauske, April 29, 2009 at 8:07 a.m.

@Lukas: You want to draw a three-dimensional manipulator? TikZ is not well suited for this task. An alternative could be to use Sketch. Sketch is a simple system for producing line drawings of two- or three-dimensional solid objects and scenes. I once wrote a short introduction to Sketch. At the end of the article you will find a couple of examples related to robotics.

• #3 Lukas Doktor, April 29, 2009 at 9:39 a.m.

Hmm, I'll take a look on that. But I don't need to draw 3d manipulator, only it's scheme. Something like this:

http://www.societyofrobots.com/images/robot_arm_simple.gif

(for 3d I use povray)

• #4 Kjell Magne Fauske, April 29, 2009 at 10:38 a.m.

I see. You want to draw a 2D-version of a 3D-manipulator like in this example

http://www.societyofrobots.com/images/robot_arm_arm2DH.jpg

TikZ's 3D-support is very limited. If you want to do something like that I'm afraid that you have to do most of the math and transformations yourself. You can find some 3D-examples in the gallery that may be of some help.

Sketch is also useful for drawing non-solid objects, so you could use it for drawing the schemes.

• #5 Alex, August 17, 2012 at 1:32 p.m.

Hello,

the sketch mentioned above is exactly what I've been lookin four. Just one little question.

Is it possible to reduce the arc radius of the annotations? That would be very useful for me.

Thanks!