Debian Codegraph @

texmf-dist/tex/latex/robotarm/robotarm.sty

raw
1 %%
2 %% This is file `robotarm.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% robotarm.dtx (with options: `robotarm-package')
8 %%
9 %% This is a generated file.
10 %%
11 %% Copyright (C) 2021 by M.J.W. Snippe
12 %% -----------------------------------
13 %%
14 %% This file may be distributed and/or modified under the
15 %% conditions of the LaTeX Project Public License, either
16 %% version 1.3 of this license or (at your option) any later
17 %% version. The latest version of this license is in:
18 %%
19 %% http://www.latex-project.org/lppl.txt
20 %%
21 %% and version 1.3 or later is part of all distributions of
22 %% LaTeX version 2005/12/01 or later.
23 %%
24 %% This work has the LPPL maintenance status
25 %% `author-maintained'.
26 %%
27 %% This work consists of the files found at github.com/max-sn/robotarm.
28 %%
29 \NeedsTeXFormat{LaTeX2e}
30 \ProvidesPackage{robotarm}
31 [2022/03/08 v0.1 Tikz commands to draw planar robot arms]
32
33 \RequirePackage{tikz}
34
35 \usetikzlibrary{patterns}
36
37 \makeatletter
38
39 \newif\ifRA@robotarm@drawannotations
40
41 \pgfkeys{
42 /robotarm/base link/.cd,
43 width/.code={\pgfmathsetmacro\RA@baselink@width{#1}},
44 width=0.6,
45 height/.code={\pgfmathsetmacro\RA@baselink@height{#1}},
46 height=0.3,
47 world width/.code={\pgfmathsetmacro\RA@baselink@worldwidth{#1}},
48 world width=1.0,
49 world height/.code={\pgfmathsetmacro\RA@baselink@worldheight{#1}},
50 world height=0.3,
51 draw base link/.code={%
52 \path[link style]
53 (-1/2*\RA@baselink@width,0)
54 arc (180:0:1/2*\RA@baselink@width)
55 -- ++ (0, -\RA@baselink@height)
56 -- ++ (-\RA@baselink@width, 0)
57 -- cycle;
58 },
59 draw world/.code={%
60 \path[world style]
61 (-1/2*\RA@baselink@worldwidth,-\RA@baselink@height)
62 arc (180:360:{1/2*\RA@baselink@worldwidth}
63 and {\RA@baselink@worldheight}) -- cycle;
64 \path[draw, world style]
65 (-1/2*\RA@baselink@worldwidth,-\RA@baselink@height)
66 -- ++(\RA@baselink@worldwidth,0);
67 },
68 /robotarm/link/.cd,
69 width/.code={\pgfmathsetmacro\RA@link@width{#1}},
70 width=0.4,
71 length/.code={\pgfmathsetmacro\RA@link@length{#1}},
72 length=2.0,
73 joint radius/.code={\pgfmathsetmacro\RA@link@jointradius{#1}},
74 joint radius=0.25,
75 draw link/.code={%
76 \path[link style]
77 (0,1/2*\RA@link@width)
78 -- ++ ( \RA@link@length, 0)
79 arc (90:-90:1/2*\RA@link@width)
80 -- ++ (-\RA@link@length, 0)
81 arc (270:90:1/2*\RA@link@width)
82 -- cycle;
83 },
84 draw joint/.code={%
85 \path[link style]
86 (0,0) circle (\RA@link@jointradius);
87 \path[link style]
88 (0,0) circle (1/3*\RA@link@jointradius);
89 },
90 /robotarm/end effector/.cd,
91 width/.code={\pgfmathsetmacro\RA@endeff@width{#1}},
92 width=0.4,
93 length/.code={\pgfmathsetmacro\RA@endeff@length{#1}},
94 length=2,
95 joint radius/.code={\pgfmathsetmacro\RA@endeff@jointradius{#1}},
96 joint radius=0.25,
97 gripper radius/.code={\pgfmathsetmacro\RA@endeff@gripperradius{#1}},
98 gripper radius=0.3,
99 gripper opening angle/.code={%
100 \pgfmathsetmacro\RA@endeff@gripperopeningangle{#1}},
101 gripper opening angle=60,
102 draw joint/.code={%
103 \path[link style]
104 (0,0) circle (\RA@endeff@jointradius);
105 \path[link style]
106 (0,0) circle (1/3*\RA@endeff@jointradius);
107 },
108 draw link/.code={%
109 \pgfmathsetmacro{\link@startangle}{%
110 180-asin(1/2*\RA@endeff@width/\RA@endeff@gripperradius)}
111 \pgfmathsetmacro{\link@endangle}{%
112 180+asin(1/2*\RA@endeff@width/\RA@endeff@gripperradius)}
113
114 \path[link style]
115 (\RA@endeff@length, 0)
116 ++ (\link@startangle:\RA@endeff@gripperradius)
117 arc (\link@startangle:\link@endangle:\RA@endeff@gripperradius)
118 -- (0,0|-0,-1/2*\RA@endeff@width)
119 arc (-90:90:1/2*\RA@endeff@width)
120 -- cycle;
121 },
122 draw end effector/.code={
123 \draw[link style]
124 (\RA@endeff@length, 0)
125 ++ (-1/2*\RA@endeff@gripperopeningangle:%
126 \RA@endeff@gripperradius)
127 arc [start angle=-1/2*\RA@endeff@gripperopeningangle,
128 delta angle=-360+\RA@endeff@gripperopeningangle,
129 radius=\RA@endeff@gripperradius]
130 -- ++(180+1/2*\RA@endeff@gripperopeningangle:%
131 0.4*\RA@endeff@gripperradius)
132 arc [start angle=1/2*\RA@endeff@gripperopeningangle,
133 delta angle=360-\RA@endeff@gripperopeningangle,
134 radius=0.6*\RA@endeff@gripperradius]
135 -- ++(-1/2*\RA@endeff@gripperopeningangle:%
136 0.4*\RA@endeff@gripperradius)
137 -- cycle;
138 },
139 /robotarm/.cd,
140 draw annotations/.is if=RA@robotarm@drawannotations,
141 draw annotations=true,
142 every annotation/.style={},
143 every length annotation/.style={},
144 every length annotation arrow/.style={draw,->},
145 every length annotation node/.style={circle,inner sep=0.5pt},
146 every length annotation help line/.style={draw,help lines},
147 every angle annotation/.style={},
148 every angle annotation arrow/.style={draw,->},
149 every angle annotation node/.style={},
150 every angle annotation help line/.style={draw,help lines},
151 base link/.code=\pgfkeys{/robotarm/base link/.cd,#1},
152 link/.code=\pgfkeys{/robotarm/link/.cd,#1},
153 end effector/.code=\pgfkeys{/robotarm/end effector/.cd,#1},
154 geometry/.code=\pgfkeys{/robotarm/geometry/.cd,#1},
155 config/.code=\pgfkeys{/robotarm/config/.cd,#1},
156 spacing/.code=\pgfkeys{/robotarm/annotations/spacing/.cd,#1},
157 labels/.code=\pgfkeys{/robotarm/annotations/labels/.cd,#1},
158 styles/.code=\pgfkeys{/robotarm/styles/.cd,#1},
159 /robotarm/geometry/.cd,
160 a0/.initial=0,
161 a/.initial=2,
162 r/.initial=0.25,
163 w/.initial=0.4,
164 /robotarm/config/q/.initial=0,
165 /robotarm/frames/.cd,
166 in link 0/.style={},
167 in end effector/.style={
168 /robotarm/frames/in link \RA@robotarm@numlinks,
169 shift={%
170 (\pgfkeysvalueof{/robotarm/geometry/a\RA@robotarm@numlinks},0)},
171 },
172 in world/.style={
173 shift={(0,-\RA@baselink@height)}
174 },
175 /robotarm/styles/.cd,
176 world/.style={pattern=north west lines},
177 link/.style={
178 draw,
179 fill=lightgray,
180 },
181 link 0/.style={/robotarm/styles/link},
182 /robotarm/annotations/.cd,
183 spacing/.cd,
184 a/.initial=3,
185 q/.initial=1/2,
186 /robotarm/annotations/.cd,
187 labels/.cd,
188 a/.initial=a,
189 q/.initial=q,
190 }
191 \tikzset{
192 link style/.style={/robotarm/styles/link},
193 world style/.style={/robotarm/styles/world},
194 }
195 \newcommand\robotarmset[1]{%
196 \pgfkeys{/robotarm/.cd,#1}%
197 }
198 \newcommand\robotArmLink[1][]{
199 \begingroup
200 \pgfkeys{/robotarm/link/.cd,#1}
201
202 \pgfkeys{/robotarm/link/draw link}
203 \pgfkeys{/robotarm/link/draw joint}
204 \endgroup
205 }
206 \newcommand\robotArmEndEffector[1][]{
207 \begingroup
208 \pgfkeys{/robotarm/end effector/.cd,#1}
209
210 \pgfkeys{/robotarm/end effector/draw link}
211 \pgfkeys{/robotarm/end effector/draw joint}
212 \pgfkeys{/robotarm/end effector/draw end effector}
213
214 \endgroup
215 }
216 \newcommand\robotArmBaseLink[1][]{
217 \begingroup
218 \pgfkeys{/robotarm/base link/.cd,#1}
219
220 \pgfkeys{/robotarm/base link/draw world}
221 \pgfkeys{/robotarm/base link/draw base link}
222 \endgroup
223 }
224 \newcommand\robotArm[2][]{
225 \pgfmathtruncatemacro\RA@robotarm@numlinks{#2}
226 \def\@tmpkeys{}
227 \foreach \@link [remember=\@link as \@prevlink (initially 0)] in %
228 {1,...,\RA@robotarm@numlinks}{
229 \xdef\@tmpkeys{\@tmpkeys%
230 /robotarm/geometry/a\@link/.initial=%
231 \pgfkeysvalueof{/robotarm/geometry/a},%
232 /robotarm/geometry/r\@link/.initial=%
233 \pgfkeysvalueof{/robotarm/geometry/r},%
234 /robotarm/geometry/w\@link/.initial=%
235 \pgfkeysvalueof{/robotarm/geometry/w},%
236 /robotarm/config/q\@link/.initial=%
237 \pgfkeysvalueof{/robotarm/config/q},%
238 /robotarm/styles/link \@link/.style={/robotarm/styles/link},%
239 /robotarm/annotations/labels/a\@link/.initial={%
240 $\pgfkeysvalueof{/robotarm/annotations/labels/a}_{\@link}$},%
241 /robotarm/annotations/labels/q\@link/.initial={%
242 $\pgfkeysvalueof{/robotarm/annotations/labels/q}_{\@link}$},%
243 /robotarm/annotations/spacing/a\@link/.initial={%
244 \pgfkeysvalueof{/robotarm/annotations/spacing/a}},%
245 /robotarm/annotations/spacing/q\@link/.initial={%
246 \pgfkeysvalueof{/robotarm/annotations/spacing/q}},%
247 }
248 }
249 \expandafter\pgfkeys\expandafter{\@tmpkeys}
250 \pgfkeys{/robotarm/.cd,#1}
251 \def\@tmpkeys{}
252 \foreach \@link [remember=\@link as \@prevlink (initially 0)] in %
253 {1,...,\RA@robotarm@numlinks}{
254 \xdef\@tmpkeys{\@tmpkeys%
255 /robotarm/frames/in link \@link/.style={%
256 /robotarm/frames/in link \@prevlink,
257 /tikz/shift={%
258 (\pgfkeysvalueof{/robotarm/geometry/a\@prevlink},0)},
259 /tikz/rotate={\pgfkeysvalueof{/robotarm/config/q\@link}},
260 },
261 }
262 }
263 \expandafter\pgfkeys\expandafter{\@tmpkeys}
264
265 \begin{scope}[/robotarm/frames/in link 0,
266 link style/.style={/robotarm/styles/link 0}]
267 \robotArmBaseLink
268 \end{scope}
269
270 \foreach\link@num in {1,...,\RA@robotarm@numlinks}{
271 \begin{scope}[/robotarm/frames/in link \link@num,
272 link style/.style={/robotarm/styles/link \link@num}]
273
274 \ifnum\link@num<\RA@robotarm@numlinks
275 \robotArmLink[
276 joint radius=\pgfkeysvalueof{/robotarm/geometry/r\link@num},
277 length=\pgfkeysvalueof{/robotarm/geometry/a\link@num},
278 width=\pgfkeysvalueof{/robotarm/geometry/w\link@num},
279 ]
280 \else
281 \robotArmEndEffector[
282 joint radius=\pgfkeysvalueof{/robotarm/geometry/r\link@num},
283 length=\pgfkeysvalueof{/robotarm/geometry/a\link@num},
284 width=\pgfkeysvalueof{/robotarm/geometry/w\link@num},
285 ]
286 \fi
287 \end{scope}
288 }
289 \foreach\link@num in {1,...,\RA@robotarm@numlinks}{
290 \begin{scope}[/robotarm/frames/in link \link@num]
291 \pgfmathsetmacro\link@length{\pgfkeysvalueof{%
292 /robotarm/geometry/a\link@num}}
293 \pgfmathsetmacro\link@angle{\pgfkeysvalueof{%
294 /robotarm/config/q\link@num}}
295
296 \ifRA@robotarm@drawannotations
297 \pgfmathsetmacro\link@lengthannotspacing{%
298 \pgfkeysvalueof{/robotarm/annotations/spacing/a\link@num}*
299 \pgfkeysvalueof{/robotarm/geometry/r\link@num}}
300 \pgfmathsetmacro\link@angleannotspacing{%
301 \pgfkeysvalueof{/robotarm/annotations/spacing/q\link@num}*
302 \link@length}
303
304 % Length annotation help lines
305 \path[/robotarm/every annotation,
306 /robotarm/every length annotation,
307 /robotarm/every length annotation help line]
308 (0,0) -- (\link@length,0);
309 \path[/robotarm/every annotation,
310 /robotarm/every length annotation,
311 /robotarm/every length annotation help line]
312 (0,0) -- ++ (0,{\link@lengthannotspacing +
313 0.1*sign(\link@lengthannotspacing)});
314 \path[/robotarm/every annotation,
315 /robotarm/every length annotation,
316 /robotarm/every length annotation help line]
317 (\link@length,0) -- ++ (0,{\link@lengthannotspacing +
318 0.1*sign(\link@lengthannotspacing)});
319 \path (0,\link@lengthannotspacing)
320 -- coordinate[pos=0.5] (coor) ++ (\link@length,0);
321 \node[/robotarm/every annotation,
322 /robotarm/every length annotation,
323 /robotarm/every length annotation node]
324 at (coor) (tag)
325 {\pgfkeysvalueof{/robotarm/annotations/labels/a\link@num}};
326 \path[/robotarm/every annotation,
327 /robotarm/every length annotation,
328 /robotarm/every length annotation arrow]
329 (tag) -- (0,\link@lengthannotspacing);
330 \path[/robotarm/every annotation,
331 /robotarm/every length annotation,
332 /robotarm/every length annotation arrow]
333 (tag) -- (\link@length,\link@lengthannotspacing);
334
335 \pgfmathsetmacro\angleannotationcase{%
336 ifthenelse(\link@angle==0.0, 0, 1)}
337 \ifnum\angleannotationcase>0
338 % Angle annotation help lines
339 \path[/robotarm/every annotation,
340 /robotarm/every angle annotation,
341 /robotarm/every angle annotation help line]
342 (0,0) -- ++(-\link@angle:{\link@angleannotspacing+0.1});
343 \path[/robotarm/every annotation,
344 /robotarm/every angle annotation,
345 /robotarm/every angle annotation help line]
346 (0,0) -- ++(0:{\link@angleannotspacing+0.1});
347
348 % Angle annotation arrow
349 \path[/robotarm/every annotation,
350 /robotarm/every angle annotation,
351 /robotarm/every angle annotation arrow]
352 (0,0) ++ (-\link@angle:\link@angleannotspacing)
353 arc (-\link@angle:0:\link@angleannotspacing);
354
355 % Angle annotation node
356 \node[/robotarm/every annotation,
357 /robotarm/every angle annotation,
358 /robotarm/every angle annotation node]
359 at (-\link@angle/2:\link@angleannotspacing+0.3)
360 {\pgfkeysvalueof{/robotarm/annotations/labels/q\link@num}};
361 \fi
362 \fi
363 \end{scope}
364 }
365 \tikzset{
366 in link/.style={/robotarm/frames/in link #1},
367 in base link/.style={/robotarm/frames/in link 0},
368 in end effector/.style={/robotarm/frames/in end effector},
369 in world/.style={/robotarm/frames/in world},
370 }
371 }
372 \makeatother
373 \endinput
374 %%
375 %% End of file `robotarm.sty'.