Debian Codegraph @

texmf-dist/source/latex/robotarm/robotarm.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2021 by M.J.W. Snippe
4 % -----------------------------------
5 %
6 % This work may be distributed and/or modified under the
7 % conditions of the LaTeX Project Public License, either version 1.3
8 % of this license or (at your option) any later version.
9 % The latest version of this license is in
10 %
11 % http://www.latex-project.org/lppl.txt
12 %
13 % and version 1.3 or later is part of all distributions of LaTeX
14 % version 2005/12/01 or later.
15 %
16 % This work has the LPPL maintenance status `author-maintained'.
17 %
18 % This work consists of the files found at github.com/max-sn/robotarm.
19 %
20 % \fi
21 %
22 % \iffalse
23 %<*driver>
24 \documentclass{ltxdoc}
25 \input{robotarm.doc.settings.sty}
26 \EnableCrossrefs
27 \RecordChanges
28 \begin{document}
29 \DocInput{robotarm.dtx}
30 \end{document}
31 %</driver>
32 %
33 % \fi
34 %
35 % \iffalse
36 %
37 %<*robotarm-doc-settings>
38
39 \usepackage[utf8]{inputenc}
40 \usepackage{xspace}
41 \usepackage{multicol}
42 \usepackage{geometry}
43 \usepackage{mathpazo}
44 \usepackage{robotarm}
45 \usepackage{biblatex}
46 \usepackage{hypdoc}
47 \usepackage{tcolorbox}
48
49 \addbibresource{robotarm.doc.bib.bib}
50 \defbibheading{robotarmbibheading}[\bibname]{%
51 \clearpage\section*{#1}\addcontentsline{toc}{section}{#1}}
52
53 \geometry{pass}
54
55 \tcbuselibrary{documentation,breakable,minted}
56 \tcbset{
57 index german settings,
58 index colorize,
59 docexample/.append style={
60 before lower={\begin{center}\begin{tikzpicture}},
61 after lower={\end{tikzpicture}\end{center}},
62 documentation minted options={autogobble},
63 breakable,
64 }
65 }
66
67 \makeindex
68
69 \renewcommand{\MacroFont}{\color{black!70!blue}\small\ttfamily}
70
71 \def\robotarmpackage{\textsl{robotarm}\xspace}
72 \def\Tikz{{\normalfont Ti\textit{k}Z}\xspace}
73
74 %</robotarm-doc-settings>
75 %
76 %<*robotarm-doc-main>
77
78 \title{The \robotarmpackage package}
79 \author{Marcus J.W. Snippe \\
80 \normalsize\href{mailto:[email protected]}
81 {\texttt{maxsnippe[at]gmail.nl}}}
82 \date{\filedate\\[0.4em]\normalsize\fileversion}
83
84 \maketitle
85
86 \begin{abstract}
87 With the \robotarmpackage package, you can draw configurable planar robot arms with ease, using \Tikz. It defines the macro (\refCom{robotArm}) and a lot of ways to configure it. Additionally, you can use or redefine the macros used to draw the base link (\refCom{robotArmBaseLink}), a single link (\refCom{robotArmLink}), or the end effector (\refCom{robotArmEndEffector}).
88 \end{abstract}
89
90 \begin{multicols}{2}
91 \tableofcontents
92 \end{multicols}
93
94 \section{Macros}
95
96 \subsection{\texttt{robotArm}}
97
98 \begin{docCommand}{robotArm}{\oarg{key-value list}\marg{num}}
99 This is the main macro of the \robotarmpackage package. It is meant to be used in the \texttt{tikzpicture} environment\footnote{The first example still includes the \texttt{tikzpicture} environment, but for following examples,it will be omitted in the example code.}, from the \Tikz\cite{tantau:tikz_and_pgf} package,
100 and installs some styles for additional drawing, e.g. \refKey{/tikz/in link}.
101
102 \begin{dispExample*}{before lower={}, after lower={}}
103 \begin{tikzpicture}
104 \robotArm[config={q1=60,q2=-40,q3=-50}]{3}
105 \end{tikzpicture}
106 \end{dispExample*}
107
108 \meta{num} defines the number of links that will be drawn. For an $N$ link robot arm, the $N$\textsuperscript{th} link will be the end effector link.
109
110 The \meta{key-value list} values can consist of the keys listed below.
111
112
113
114 \begin{docKey}{geometry}{=\meta{key-value list}}{}
115
116 The \refKey{geometry} key can be used to set geometrical configuration options of the robot arm, e.g. link length and link width. The keys in \meta{key-value list} can be one or more of the following.
117
118 ^^A \begin{docKey}[][doc label=/geometry/a0]{a0}{=\meta{value}}{initially \texttt{0.0}}
119 ^^A Sets the height of the base link.
120
121 ^^A \begin{dispExample}
122 ^^A \robotArm[config={q1=60},geometry={a0=2}]{2}
123 ^^A \end{dispExample}
124 ^^A \end{docKey}
125
126 \begin{docKeys}
127 [
128 doc parameter={=\meta{value}},
129 ]
130 {
131 {
132 doc name=a,
133 doc label=/geometry/a,
134 doc description={initially \texttt{2}}
135 },
136 {
137 doc name=a\meta{num},
138 doc label=/geometry/anum,
139 doc description={initially the value of \refKey{/geometry/a}}
140 },
141 }
142
143 The \refKey{/geometry/a} key sets the default length for all links that are drawn in the \refCom{robotArm} command. For every link, this can be overruled by the dynamically created keys \refKey{/geometry/anum}, e.g. to set only the length of link 3 to 3, use \texttt{a3=3}.
144
145 \begin{dispExample}
146 \robotArm[config={q1=20,q2=-20,q3=-20},
147 geometry={a=3,a3=1}]{3}
148 \end{dispExample}
149 \end{docKeys}
150
151 \begin{docKeys}
152 [
153 doc parameter={=\meta{value}}
154 ]
155 {
156 {
157 doc name=r,
158 doc label=/geometry/r,
159 doc description={initially \texttt{0.25}}
160 },
161 {
162 doc name=r\meta{num},
163 doc label=/geometry/rnum,
164 doc description={initially the value of \refKey{/geometry/r}}
165 },
166 }
167 The \refKey{/geometry/r} key sets the default joint radius for all links drawn in the \refCom{robotArm} command. For every link this can be overruled by the dynamically created keys \refKey{/geometry/rnum}.
168
169 \begin{dispExample}
170 \robotArm[config={q1=20,q2=-20},
171 geometry={r=0.5,r1=0.3}]{2}
172 \end{dispExample}
173 \end{docKeys}
174
175 \begin{docKeys}
176 [
177 doc parameter={=\meta{value}}
178 ]
179 {
180 {
181 doc name=w,
182 doc label=/geometry/w,
183 doc description={initially \texttt{0.4}}
184 },
185 {
186 doc name=w\meta{num},
187 doc label=/geometry/wnum,
188 doc description={initially the value of \refKey{/geometry/w}}
189 },
190 }
191 The \refKey{/geometry/w} key sets the default link width for all links drawn in the \refCom{robotArm} command. For every link this can be overruled by the dynamically created keys \refKey{/geometry/wnum}.
192 \end{docKeys}
193
194 \end{docKey}
195
196 \begin{dispExample}
197 \tikzset{/robotarm/geometry={a=1}}
198 \robotArm{1}
199 \begin{scope}[xshift=3cm]
200 \robotArm{6}
201 \end{scope}
202 \end{dispExample}
203
204 \begin{docKey}[robotarm/styles]{link}{}{default \texttt{draw,fill=lightgray}}
205 \end{docKey}
206
207 \end{docCommand}
208
209 \subsection{\texttt{robotArmBaseLink}}
210
211 \begin{docCommand}{robotArmBaseLink}{\oarg{key-value list}}
212 This command is used in \refCom{robotArm} to draw the base link. It can also be used to draw your own base link. The default base link looks as follows:
213 \begin{dispExample}
214 \robotArmBaseLink
215 \end{dispExample}
216 The \meta{key-value list} can consist of the keys listed below.
217
218 \begin{docKeys}
219 [
220 doc keypath={robotarm/base link},
221 doc parameter={=\meta{value}},
222 ]
223 {
224 {
225 doc name=height,
226 doc description={initially \texttt{0.6}}
227 },
228 {
229 doc name=width,
230 doc description={initially \texttt{0.3}}
231 },
232 }
233 The width and height of the base link can be specified with these keys. The height is measured from the center of the half-circle at the top, to the base.
234 \begin{dispExample}
235 \robotArmBaseLink[width=1, height=0.6]
236 \end{dispExample}
237 \end{docKeys}
238
239 \begin{docKeys}
240 [
241 doc keypath={robotarm/base link},
242 doc parameter={=\meta{value}},
243 ]
244 {
245 {
246 doc name=world width,
247 doc description={initially \texttt{1.0}},
248 },
249 {
250 doc name=world height,
251 doc description={initially \texttt{0.3}},
252 }
253 }
254 The width and height of the `world' drawn below the base link can be specified with these keys.
255 \begin{dispExample}
256 \robotArmBaseLink[world width=5, world height=1]
257 \end{dispExample}
258 \end{docKeys}
259
260 \begin{docKeys}
261 [
262 doc keypath={robotarm/base link},
263 doc description={code executing key},
264 ]
265 {
266 {doc name=draw base link},
267 {doc name=draw world},
268 }
269 These keys are used to draw the `world' and the base link. If the configuration options above are insufficient, you can redefine these keys, as shown in the not-so-creative example below.
270 \begin{dispExample}
271 \robotArmBaseLink[
272 draw world/.code={
273 \filldraw[fill=brown] (-2,-1) rectangle (2, -0.3);
274 },
275 draw base link/.code={
276 \filldraw[fill=black!60] (-0.5, -0.3) rectangle
277 (0.5, 0.3);
278 }]
279 \end{dispExample}
280 To access the values of the keys listed above you can use the following macros in your redefinition:
281 \begin{itemize}
282 \item \docAuxCommand{RA@baselink@width},
283 \item \docAuxCommand{RA@baselink@height},
284 \item \docAuxCommand{RA@baselink@worldwidth}, and
285 \item \docAuxCommand{RA@baselink@worldheight}.
286 \end{itemize}
287 \end{docKeys}
288
289 \end{docCommand}
290
291
292 \subsection{\texttt{robotArmLink}}
293
294 \begin{docCommand}{robotArmLink}{\oarg{key-value list}}
295 This command is used in \refCom{robotArm} to draw the links in a \texttt{foreach} loop. It can also be used to draw your own link(s). The default link looks as follows:
296 \begin{dispExample}
297 \robotArmLink
298 \end{dispExample}
299 The \meta{key-value list} can consist of the keys listed below.
300
301 \begin{docKeys}
302 [
303 doc keypath={robotarm/link},
304 doc parameter={=\meta{value}},
305 ]{
306 {
307 doc name=width,
308 doc description={initially \texttt{0.4}},
309 },
310 {
311 doc name=length,
312 doc description={initially \texttt{2.0}},
313 },
314 {
315 doc name=joint radius,
316 doc description={initially \texttt{0.25}},
317 },
318 }
319 The geometrical properties of the links can be configured with these keys.
320 \begin{dispExample}
321 \robotArmLink[width=0.75,joint radius=0.4,length=5]
322 \end{dispExample}
323 \end{docKeys}
324
325 \begin{docKeys}
326 [
327 doc keypath={robotarm/link},
328 doc description={code executing key},
329 ]
330 {
331 {doc name=draw link},
332 {doc name=draw joint},
333 }
334 Same as for the base link, the actual drawing is done by calling these keys. These can also be redefined to change the drawing.
335 \begin{dispExample}
336 \robotArmLink[draw link/.code={
337 \draw[line cap=round, double=lightgray,
338 double distance=4mm]
339 (0,0) to[bend left] (2,0);}]
340 \end{dispExample}
341 Of course you can also do this globally so it applies to all links\footnote{For the end effector to change too, you have to redefine \refKey{/robotarm/end effector/draw joint} too.}.
342 \begin{dispExample}
343 \pgfkeys{/robotarm/link/draw joint/.code={
344 \path[link style] (-0.3,-0.3) rectangle ++(0.6,0.6);
345 \path[link style] (0,0) circle (0.2);}}
346 \robotArm[geometry={a=1.5},
347 config={q1=60,q2=-30,q3=-30}]{3}
348 \end{dispExample}
349 To access the values of the keys listed above you can use the following macros in your redefinition:
350 \begin{itemize}
351 \item \docAuxCommand{RA@link@width},
352 \item \docAuxCommand{RA@link@length}, and
353 \item \docAuxCommand{RA@link@jointradius}.
354 \end{itemize}
355 \end{docKeys}
356
357 \end{docCommand}
358
359 \subsection{\texttt{robotArmEndEffector}}
360
361 \begin{docCommand}{robotArmEndEffector}{\oarg{key-value list}}
362 This command is used in \refCom{robotArm} to draw the final link with the end effector attached. You can also use it outside that command to draw your own end effector.
363 \begin{dispExample}
364 \robotArmEndEffector
365 \end{dispExample}
366 The \meta{key-value list} can consist of the keys listed below.
367
368 \begin{docKeys}
369 [
370 doc keypath={robotarm/end effector},
371 doc parameter={=\meta{value}},
372 ]
373 {
374 {
375 doc name=width,
376 doc description={initially \texttt{0.4}},
377 },
378 {
379 doc name=length,
380 doc description={initially \texttt{2.0}},
381 },
382 {
383 doc name=joint radius,
384 doc description={initially \texttt{0.25}},
385 },
386 {
387 doc name=gripper radius,
388 doc description={initially \texttt{0.3}},
389 },
390 {
391 doc name=gripper opening angle,
392 doc description={initially \texttt{60}},
393 doc parameter={=\meta{angle}},
394 },
395 }
396 The geometrical properties of the final link and the end effector, which defaults to a gripper, can be tuned with these keys. Due to some trigonometric functions in the drawing code of \refKey{/robotarm/end effector/draw end effector}, \refKey{/robotarm/end effector/gripper radius} should not be smaller than half of \refKey{/robotarm/end effector/width}.
397
398 \end{docKeys}
399
400 \begin{docKeys}
401 [
402 doc keypath={robotarm/end effector},
403 doc description={code executing key},
404 ]
405 {
406 {doc name=draw link},
407 {doc name=draw joint},
408 {doc name=draw end effector},
409 }
410 Again the actual drawing is done by calling these keys. And these can also be redefined to change how the end effector will look, as shown in the example below.
411 \begin{dispExample}
412 \robotArm[
413 config={q1=100,q2=-100},
414 end effector/.cd,
415 draw link/.code={
416 \draw[line cap=round, double=lightgray,
417 double distance=4mm]
418 (0,0) to[bend left] (2, 0.8);},
419 draw end effector/.code={
420 \path[link style]
421 (1.8, 0.8) arc (180:0:0.2) -- (2.1, 0.4)
422 -- (1.9, 0.4) -- cycle;
423 \path[link style]
424 (2.05,0.4) rectangle (1.95,0.0);
425 \fill (2,0) circle (0.05);}]{2}
426 \end{dispExample}
427 To access the values of the keys listed above you can use the following macros in your redefinition:
428 \begin{itemize}
429 \item \docAuxCommand{RA@endeff@width},
430 \item \docAuxCommand{RA@endeff@length},
431 \item \docAuxCommand{RA@endeff@jointradius},
432 \item \docAuxCommand{RA@endeff@gripperradius}, and
433 \item \docAuxCommand{RA@endeff@gripperopeningangle}.
434 \end{itemize}
435 \end{docKeys}
436
437 \end{docCommand}
438
439 \section{\Tikz styles}
440
441 \begin{docKeys}
442 [
443 doc keypath=tikz,
444 doc description=style,
445 ]
446 {
447 {
448 doc name=in link,
449 doc parameter={=\meta{number}},
450 },
451 {
452 doc name=in base link,
453 },
454 {
455 doc name=in world,
456 },
457 {
458 doc name=in end effector,
459 }
460 }
461 Only installed after calling \refCom{robotArm} at least once (last called macro defines these styles, but within scope can be made unique).
462 \end{docKeys}
463
464 \begin{docKey}[tikz]{link style}{}{default \texttt{/robotarm/styles/link}}
465 Always installed, forwards to \refKey{/robotarm/styles/link}. Only works one way. To change link styles used in \refCom{robotArm}, change the appropriate \refKey{/robotarm/styles/link}.
466 \begin{dispExample}
467 \tikzset{link style/.style={draw=none, fill=red!50}}
468 \robotArm[config={q1=40},styles={
469 link 1/.style={fill=blue!50}}]{3}
470 \end{dispExample}
471 \end{docKey}
472
473
474 %^^A \section{\robotarmpackage keys}
475 %^^A \begin{docKeys}
476 %^^A [
477 %^^A doc keypath=robotarm/annotations/labels,
478 %^^A ]{
479 %^^A {
480 %^^A doc name=a,
481 %^^A doc description={no default, initially \texttt{a}},
482 %^^A },
483 %^^A {
484 %^^A doc name=q,
485 %^^A doc description={no default, initially \texttt{q}},
486 %^^A }
487 %^^A }
488 %^^A \begin{dispExample}
489 %^^A \robotArm[
490 %^^A config={q1=60,q2=-40,q3=40},
491 %^^A annotations/labels/a=l,
492 %^^A annotations/labels/q=\theta,
493 %^^A annotations/labels/q3=?]{3}
494 %^^A \end{dispExample}
495 %^^A \end{docKeys}
496
497 %^^A \section{\Tikz keys}
498
499
500 %^^A \begin{docKeys}
501 %^^A [
502 %^^A doc keypath=robotarm/frames,
503 %^^A doc description={style},
504 %^^A ]{
505 %^^A {doc name=in link 0},
506 %^^A {doc name=in link 1},
507 %^^A {doc name=in link 2},
508 %^^A {doc name=in link 3},
509 %^^A {doc name=in link 4},
510 %^^A {doc name=in link 5},
511 %^^A {doc name=in link 6}
512 %^^A }
513 %^^A \end{docKeys}
514
515
516 %</robotarm-doc-main>
517 %
518 %<*robotarm-doc-bib>
519 @manual{tantau:tikz_and_pgf,
520 author = {Till Tantau},
521 title = {The TikZ and PGF Packages},
522 subtitle = {Manual for version 3.1.8b},
523 url = {https://mirrors.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf},
524 date = {2021-03-19},
525 }
526 %</robotarm-doc-bib>
527 %
528 % \fi
529 %
530 % \CheckSum{286}
531 %
532 % \CharacterTable
533 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
534 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
535 % Digits \0\1\2\3\4\5\6\7\8\9
536 % Exclamation \! Double quote \" Hash (number) \#
537 % Dollar \$ Percent \% Ampersand \&
538 % Acute accent \' Left paren \( Right paren \)
539 % Asterisk \* Plus \+ Comma \,
540 % Minus \- Point \. Solidus \/
541 % Colon \: Semicolon \; Less than \<
542 % Equals \= Greater than \> Question mark \?
543 % Commercial at \@ Left bracket \[ Backslash \\
544 % Right bracket \] Circumflex \^ Underscore \_
545 % Grave accent \` Left brace \{ Vertical bar \|
546 % Right brace \} Tilde \~}
547 %
548 %
549 % \DoNotIndex{\angleannotationcase,\link@angleannotspacing,\begin,\begingroup,\DeclareDocumentCommand,\draw,\end,\endgroup,\fi,\foreach,\ifcase,\ifnum,\ifRA@robotarm@drawannotations,\lenghtannotationspacing,\link@lenght,\link@radius,\link@startangle,\link@width,\lengthannotationspacing,\link@length,\link@case}
550 %
551 % \changes{v0.1}{2022/03/08}{Initial version for publishing}
552 %
553 % \GetFileInfo{robotarm.sty}
554 %
555 % \input{robotarm.doc.main.tex}
556 %
557 % \StopEventually{\printbibliography[heading=robotarmbibheading]\printindex\PrintChanges}
558 %
559 % \section{Implementation}
560 % \begin{macrocode}
561 %<*robotarm-package>
562 \NeedsTeXFormat{LaTeX2e}
563 \ProvidesPackage{robotarm}
564 [2022/03/08 v0.1 Tikz commands to draw planar robot arms]
565
566 \RequirePackage{tikz}
567
568 \usetikzlibrary{patterns}
569
570 \makeatletter
571
572 \newif\ifRA@robotarm@drawannotations
573
574 \pgfkeys{
575 /robotarm/base link/.cd,
576 width/.code={\pgfmathsetmacro\RA@baselink@width{#1}},
577 width=0.6,
578 height/.code={\pgfmathsetmacro\RA@baselink@height{#1}},
579 height=0.3,
580 world width/.code={\pgfmathsetmacro\RA@baselink@worldwidth{#1}},
581 world width=1.0,
582 world height/.code={\pgfmathsetmacro\RA@baselink@worldheight{#1}},
583 world height=0.3,
584 draw base link/.code={%
585 \path[link style]
586 (-1/2*\RA@baselink@width,0)
587 arc (180:0:1/2*\RA@baselink@width)
588 -- ++ (0, -\RA@baselink@height)
589 -- ++ (-\RA@baselink@width, 0)
590 -- cycle;
591 },
592 draw world/.code={%
593 \path[world style]
594 (-1/2*\RA@baselink@worldwidth,-\RA@baselink@height)
595 arc (180:360:{1/2*\RA@baselink@worldwidth}
596 and {\RA@baselink@worldheight}) -- cycle;
597 \path[draw, world style]
598 (-1/2*\RA@baselink@worldwidth,-\RA@baselink@height)
599 -- ++(\RA@baselink@worldwidth,0);
600 },
601 /robotarm/link/.cd,
602 width/.code={\pgfmathsetmacro\RA@link@width{#1}},
603 width=0.4,
604 length/.code={\pgfmathsetmacro\RA@link@length{#1}},
605 length=2.0,
606 joint radius/.code={\pgfmathsetmacro\RA@link@jointradius{#1}},
607 joint radius=0.25,
608 draw link/.code={%
609 \path[link style]
610 (0,1/2*\RA@link@width)
611 -- ++ ( \RA@link@length, 0)
612 arc (90:-90:1/2*\RA@link@width)
613 -- ++ (-\RA@link@length, 0)
614 arc (270:90:1/2*\RA@link@width)
615 -- cycle;
616 },
617 draw joint/.code={%
618 \path[link style]
619 (0,0) circle (\RA@link@jointradius);
620 \path[link style]
621 (0,0) circle (1/3*\RA@link@jointradius);
622 },
623 /robotarm/end effector/.cd,
624 width/.code={\pgfmathsetmacro\RA@endeff@width{#1}},
625 width=0.4,
626 length/.code={\pgfmathsetmacro\RA@endeff@length{#1}},
627 length=2,
628 joint radius/.code={\pgfmathsetmacro\RA@endeff@jointradius{#1}},
629 joint radius=0.25,
630 gripper radius/.code={\pgfmathsetmacro\RA@endeff@gripperradius{#1}},
631 gripper radius=0.3,
632 gripper opening angle/.code={%
633 \pgfmathsetmacro\RA@endeff@gripperopeningangle{#1}},
634 gripper opening angle=60,
635 draw joint/.code={%
636 \path[link style]
637 (0,0) circle (\RA@endeff@jointradius);
638 \path[link style]
639 (0,0) circle (1/3*\RA@endeff@jointradius);
640 },
641 draw link/.code={%
642 \pgfmathsetmacro{\link@startangle}{%
643 180-asin(1/2*\RA@endeff@width/\RA@endeff@gripperradius)}
644 \pgfmathsetmacro{\link@endangle}{%
645 180+asin(1/2*\RA@endeff@width/\RA@endeff@gripperradius)}
646
647 \path[link style]
648 (\RA@endeff@length, 0)
649 ++ (\link@startangle:\RA@endeff@gripperradius)
650 arc (\link@startangle:\link@endangle:\RA@endeff@gripperradius)
651 -- (0,0|-0,-1/2*\RA@endeff@width)
652 arc (-90:90:1/2*\RA@endeff@width)
653 -- cycle;
654 },
655 draw end effector/.code={
656 \draw[link style]
657 (\RA@endeff@length, 0)
658 ++ (-1/2*\RA@endeff@gripperopeningangle:%
659 \RA@endeff@gripperradius)
660 arc [start angle=-1/2*\RA@endeff@gripperopeningangle,
661 delta angle=-360+\RA@endeff@gripperopeningangle,
662 radius=\RA@endeff@gripperradius]
663 -- ++(180+1/2*\RA@endeff@gripperopeningangle:%
664 0.4*\RA@endeff@gripperradius)
665 arc [start angle=1/2*\RA@endeff@gripperopeningangle,
666 delta angle=360-\RA@endeff@gripperopeningangle,
667 radius=0.6*\RA@endeff@gripperradius]
668 -- ++(-1/2*\RA@endeff@gripperopeningangle:%
669 0.4*\RA@endeff@gripperradius)
670 -- cycle;
671 },
672 /robotarm/.cd,
673 draw annotations/.is if=RA@robotarm@drawannotations,
674 draw annotations=true,
675 every annotation/.style={},
676 every length annotation/.style={},
677 every length annotation arrow/.style={draw,->},
678 every length annotation node/.style={circle,inner sep=0.5pt},
679 every length annotation help line/.style={draw,help lines},
680 every angle annotation/.style={},
681 every angle annotation arrow/.style={draw,->},
682 every angle annotation node/.style={},
683 every angle annotation help line/.style={draw,help lines},
684 base link/.code=\pgfkeys{/robotarm/base link/.cd,#1},
685 link/.code=\pgfkeys{/robotarm/link/.cd,#1},
686 end effector/.code=\pgfkeys{/robotarm/end effector/.cd,#1},
687 geometry/.code=\pgfkeys{/robotarm/geometry/.cd,#1},
688 config/.code=\pgfkeys{/robotarm/config/.cd,#1},
689 spacing/.code=\pgfkeys{/robotarm/annotations/spacing/.cd,#1},
690 labels/.code=\pgfkeys{/robotarm/annotations/labels/.cd,#1},
691 styles/.code=\pgfkeys{/robotarm/styles/.cd,#1},
692 /robotarm/geometry/.cd,
693 a0/.initial=0,
694 a/.initial=2,
695 r/.initial=0.25,
696 w/.initial=0.4,
697 /robotarm/config/q/.initial=0,
698 /robotarm/frames/.cd,
699 in link 0/.style={},
700 in end effector/.style={
701 /robotarm/frames/in link \RA@robotarm@numlinks,
702 shift={%
703 (\pgfkeysvalueof{/robotarm/geometry/a\RA@robotarm@numlinks},0)},
704 },
705 in world/.style={
706 shift={(0,-\RA@baselink@height)}
707 },
708 /robotarm/styles/.cd,
709 world/.style={pattern=north west lines},
710 link/.style={
711 draw,
712 fill=lightgray,
713 },
714 link 0/.style={/robotarm/styles/link},
715 /robotarm/annotations/.cd,
716 spacing/.cd,
717 a/.initial=3,
718 q/.initial=1/2,
719 /robotarm/annotations/.cd,
720 labels/.cd,
721 a/.initial=a,
722 q/.initial=q,
723 }
724 \tikzset{
725 link style/.style={/robotarm/styles/link},
726 world style/.style={/robotarm/styles/world},
727 }
728 % \end{macrocode}
729 % \begin{macro}{\robotarmset}
730 % \begin{macrocode}
731 \newcommand\robotarmset[1]{%
732 \pgfkeys{/robotarm/.cd,#1}%
733 }
734 % \end{macrocode}
735 % \end{macro}
736 % \begin{macro}{\robotArmLink}
737 % \begin{macrocode}
738 \newcommand\robotArmLink[1][]{
739 \begingroup
740 \pgfkeys{/robotarm/link/.cd,#1}
741
742 \pgfkeys{/robotarm/link/draw link}
743 \pgfkeys{/robotarm/link/draw joint}
744 \endgroup
745 }
746 % \end{macrocode}
747 % \end{macro}
748 % \begin{macro}{\robotArmEndEffector}
749 % \begin{macrocode}
750 \newcommand\robotArmEndEffector[1][]{
751 \begingroup
752 \pgfkeys{/robotarm/end effector/.cd,#1}
753
754 \pgfkeys{/robotarm/end effector/draw link}
755 \pgfkeys{/robotarm/end effector/draw joint}
756 \pgfkeys{/robotarm/end effector/draw end effector}
757
758 \endgroup
759 }
760 % \end{macrocode}
761 % \end{macro}
762 % \begin{macro}{\robotArmBaseLink}
763 % \begin{macrocode}
764 \newcommand\robotArmBaseLink[1][]{
765 \begingroup
766 \pgfkeys{/robotarm/base link/.cd,#1}
767
768 \pgfkeys{/robotarm/base link/draw world}
769 \pgfkeys{/robotarm/base link/draw base link}
770 \endgroup
771 }
772 % \end{macrocode}
773 % \end{macro}
774 % \begin{macro}{\robotArm}
775 % \begin{macrocode}
776 \newcommand\robotArm[2][]{
777 \pgfmathtruncatemacro\RA@robotarm@numlinks{#2}
778 \def\@tmpkeys{}
779 \foreach \@link [remember=\@link as \@prevlink (initially 0)] in %
780 {1,...,\RA@robotarm@numlinks}{
781 \xdef\@tmpkeys{\@tmpkeys%
782 /robotarm/geometry/a\@link/.initial=%
783 \pgfkeysvalueof{/robotarm/geometry/a},%
784 /robotarm/geometry/r\@link/.initial=%
785 \pgfkeysvalueof{/robotarm/geometry/r},%
786 /robotarm/geometry/w\@link/.initial=%
787 \pgfkeysvalueof{/robotarm/geometry/w},%
788 /robotarm/config/q\@link/.initial=%
789 \pgfkeysvalueof{/robotarm/config/q},%
790 /robotarm/styles/link \@link/.style={/robotarm/styles/link},%
791 /robotarm/annotations/labels/a\@link/.initial={%
792 $\pgfkeysvalueof{/robotarm/annotations/labels/a}_{\@link}$},%
793 /robotarm/annotations/labels/q\@link/.initial={%
794 $\pgfkeysvalueof{/robotarm/annotations/labels/q}_{\@link}$},%
795 /robotarm/annotations/spacing/a\@link/.initial={%
796 \pgfkeysvalueof{/robotarm/annotations/spacing/a}},%
797 /robotarm/annotations/spacing/q\@link/.initial={%
798 \pgfkeysvalueof{/robotarm/annotations/spacing/q}},%
799 }
800 }
801 \expandafter\pgfkeys\expandafter{\@tmpkeys}
802 \pgfkeys{/robotarm/.cd,#1}
803 \def\@tmpkeys{}
804 \foreach \@link [remember=\@link as \@prevlink (initially 0)] in %
805 {1,...,\RA@robotarm@numlinks}{
806 \xdef\@tmpkeys{\@tmpkeys%
807 /robotarm/frames/in link \@link/.style={%
808 /robotarm/frames/in link \@prevlink,
809 /tikz/shift={%
810 (\pgfkeysvalueof{/robotarm/geometry/a\@prevlink},0)},
811 /tikz/rotate={\pgfkeysvalueof{/robotarm/config/q\@link}},
812 },
813 }
814 }
815 \expandafter\pgfkeys\expandafter{\@tmpkeys}
816
817 \begin{scope}[/robotarm/frames/in link 0,
818 link style/.style={/robotarm/styles/link 0}]
819 \robotArmBaseLink
820 \end{scope}
821
822 \foreach\link@num in {1,...,\RA@robotarm@numlinks}{
823 \begin{scope}[/robotarm/frames/in link \link@num,
824 link style/.style={/robotarm/styles/link \link@num}]
825
826 \ifnum\link@num<\RA@robotarm@numlinks
827 \robotArmLink[
828 joint radius=\pgfkeysvalueof{/robotarm/geometry/r\link@num},
829 length=\pgfkeysvalueof{/robotarm/geometry/a\link@num},
830 width=\pgfkeysvalueof{/robotarm/geometry/w\link@num},
831 ]
832 \else
833 \robotArmEndEffector[
834 joint radius=\pgfkeysvalueof{/robotarm/geometry/r\link@num},
835 length=\pgfkeysvalueof{/robotarm/geometry/a\link@num},
836 width=\pgfkeysvalueof{/robotarm/geometry/w\link@num},
837 ]
838 \fi
839 \end{scope}
840 }
841 \foreach\link@num in {1,...,\RA@robotarm@numlinks}{
842 \begin{scope}[/robotarm/frames/in link \link@num]
843 \pgfmathsetmacro\link@length{\pgfkeysvalueof{%
844 /robotarm/geometry/a\link@num}}
845 \pgfmathsetmacro\link@angle{\pgfkeysvalueof{%
846 /robotarm/config/q\link@num}}
847
848 \ifRA@robotarm@drawannotations
849 \pgfmathsetmacro\link@lengthannotspacing{%
850 \pgfkeysvalueof{/robotarm/annotations/spacing/a\link@num}*
851 \pgfkeysvalueof{/robotarm/geometry/r\link@num}}
852 \pgfmathsetmacro\link@angleannotspacing{%
853 \pgfkeysvalueof{/robotarm/annotations/spacing/q\link@num}*
854 \link@length}
855
856 % Length annotation help lines
857 \path[/robotarm/every annotation,
858 /robotarm/every length annotation,
859 /robotarm/every length annotation help line]
860 (0,0) -- (\link@length,0);
861 \path[/robotarm/every annotation,
862 /robotarm/every length annotation,
863 /robotarm/every length annotation help line]
864 (0,0) -- ++ (0,{\link@lengthannotspacing +
865 0.1*sign(\link@lengthannotspacing)});
866 \path[/robotarm/every annotation,
867 /robotarm/every length annotation,
868 /robotarm/every length annotation help line]
869 (\link@length,0) -- ++ (0,{\link@lengthannotspacing +
870 0.1*sign(\link@lengthannotspacing)});
871 % \end{macrocode}
872 % Length annotation node
873 % \begin{macrocode}
874 \path (0,\link@lengthannotspacing)
875 -- coordinate[pos=0.5] (coor) ++ (\link@length,0);
876 \node[/robotarm/every annotation,
877 /robotarm/every length annotation,
878 /robotarm/every length annotation node]
879 at (coor) (tag)
880 {\pgfkeysvalueof{/robotarm/annotations/labels/a\link@num}};
881 % \end{macrocode}
882 % Length annotation arrows
883 % \begin{macrocode}
884 \path[/robotarm/every annotation,
885 /robotarm/every length annotation,
886 /robotarm/every length annotation arrow]
887 (tag) -- (0,\link@lengthannotspacing);
888 \path[/robotarm/every annotation,
889 /robotarm/every length annotation,
890 /robotarm/every length annotation arrow]
891 (tag) -- (\link@length,\link@lengthannotspacing);
892
893 \pgfmathsetmacro\angleannotationcase{%
894 ifthenelse(\link@angle==0.0, 0, 1)}
895 \ifnum\angleannotationcase>0
896 % Angle annotation help lines
897 \path[/robotarm/every annotation,
898 /robotarm/every angle annotation,
899 /robotarm/every angle annotation help line]
900 (0,0) -- ++(-\link@angle:{\link@angleannotspacing+0.1});
901 \path[/robotarm/every annotation,
902 /robotarm/every angle annotation,
903 /robotarm/every angle annotation help line]
904 (0,0) -- ++(0:{\link@angleannotspacing+0.1});
905
906 % Angle annotation arrow
907 \path[/robotarm/every annotation,
908 /robotarm/every angle annotation,
909 /robotarm/every angle annotation arrow]
910 (0,0) ++ (-\link@angle:\link@angleannotspacing)
911 arc (-\link@angle:0:\link@angleannotspacing);
912
913 % Angle annotation node
914 \node[/robotarm/every annotation,
915 /robotarm/every angle annotation,
916 /robotarm/every angle annotation node]
917 at (-\link@angle/2:\link@angleannotspacing+0.3)
918 {\pgfkeysvalueof{/robotarm/annotations/labels/q\link@num}};
919 \fi
920 \fi
921 \end{scope}
922 }
923 % \end{macrocode}
924 % Install \Tikz styles for coordinate transformations.
925 % \begin{macrocode}
926 \tikzset{
927 in link/.style={/robotarm/frames/in link #1},
928 in base link/.style={/robotarm/frames/in link 0},
929 in end effector/.style={/robotarm/frames/in end effector},
930 in world/.style={/robotarm/frames/in world},
931 }
932 }
933 % \end{macrocode}
934 % \end{macro}
935 % \begin{macrocode}
936 \makeatother
937 %</robotarm-package>
938 % \end{macrocode}
939 % \Finale
940 \endinput