Skip to content

Commit 9e6c00c

Browse files
docs: expand trchain runblock examples (#655)
docs: showcase trchain runblock examples
1 parent d07a90c commit 9e6c00c

1 file changed

Lines changed: 48 additions & 3 deletions

File tree

docs/source/arm_ets.rst

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,63 @@ Transform chains
7272
The :func:`~roboticstoolbox.tools.trchain.trchain` and
7373
:func:`~roboticstoolbox.tools.trchain.trchain2` functions provide the compact
7474
string notation used by the MATLAB Toolbox for one-off SE(3) and SE(2)
75-
transform chains. Joint variables are numbered from one, while named
75+
transform chains.
76+
77+
Three-dimensional chains contain rotations and translations about or along
78+
any Cartesian axis. Joint variables are numbered from one, and named
7679
constants are passed explicitly in ``variables``.
7780

7881
.. runblock:: pycon
7982

8083
>>> import roboticstoolbox as rtb
81-
>>> rtb.trchain("Rz(q1) Tx(a)", [0.3], variables={"a": 1})
82-
>>> rtb.trchain2("R(q1) Tx(a)", [0.3], variables={"a": 1})
84+
>>> q = [0.2, -0.3, 0.4]
85+
>>> rtb.trchain("Rx(q1) Ry(q2) Rz(q3) Tx(x) Ty(y) Tz(z)", q,
86+
... variables={"x": 0.5, "y": 0.2, "z": 0.1})
87+
88+
Arguments can use arithmetic, the names ``pi``, ``sin``, ``cos``, ``tan`` and
89+
``sqrt``, or functions supplied in ``variables``. The joint prefix and angle
90+
unit can also be changed.
91+
92+
.. runblock:: pycon
93+
94+
>>> import roboticstoolbox as rtb
95+
>>> rtb.trchain("Rz(pi / 2) Tx(sqrt(4)) Ty(sin(pi / 2) + cos(0) + tan(0))")
96+
>>> double = lambda value: 2 * value
97+
>>> rtb.trchain("Rz(theta1 - 45) Tx(double(a))", [90], unit="deg",
98+
... qvar="theta", variables={"a": 0.5, "double": double})
99+
100+
For planar motion, :func:`~roboticstoolbox.tools.trchain.trchain2` accepts
101+
``R`` (or ``Rz``), ``Tx`` and ``Ty`` transforms.
102+
103+
.. runblock:: pycon
104+
105+
>>> import numpy as np
106+
>>> import roboticstoolbox as rtb
107+
>>> rtb.trchain2("R(q1) Tx(L1) Rz(q2) Tx(L2) Ty(y)",
108+
... [np.pi / 2, -np.pi / 2],
109+
... variables={"L1": 1, "L2": 0.5, "y": 0.25})
83110

84111
Parsed tokens can also be returned and reused when evaluating the same chain
85112
for different joint values.
86113

114+
.. runblock:: pycon
115+
116+
>>> import roboticstoolbox as rtb
117+
>>> _, tokens = rtb.trchain("Rz(q1) Tx(a)", [0], variables={"a": 1},
118+
... return_tokens=True)
119+
>>> tokens
120+
>>> rtb.trchain(tokens, [0.5], variables={"a": 1})
121+
122+
Joint values and named constants can be symbolic.
123+
124+
.. runblock:: pycon
125+
126+
>>> import roboticstoolbox as rtb
127+
>>> import sympy
128+
>>> q, a = sympy.symbols("q a", real=True)
129+
>>> T = rtb.trchain("Rz(q1) Tx(a)", [q], variables={"a": a})
130+
>>> T[0, 0], T[0, 3], T[1, 3]
131+
87132
.. autofunction:: roboticstoolbox.tools.trchain.trchain
88133

89134
.. autofunction:: roboticstoolbox.tools.trchain.trchain2

0 commit comments

Comments
 (0)