se(2) twist
- class Twist2(arg=None, w=None, check=True)[source]
Bases:
BaseTwist2D twist class
A Twist2 object holds the parameters of a twist, a representation of a 2D rigid body transformation which is the unique elements of the Lie algebra se(2) of the corresponding SE(2) matrix. It is a 3-vector \([\vec{v}, \omega]\).
As for
Twist3it can be used as a displacement, whereexp(S)is the pose reached by following the motion, or as a velocity, whereexp(S * dt)is the pose change over a timedt. Properties that describe the axis, such aspole, are unchanged by scaling the twist.- classmethod Alloc(n=1)
Construct an instance with N default values (BasePoseList superclass method)
- Parameters:
n (
Optional[int]) – Number of values, defaults to 1- Return type:
Self- Returns:
pose instance with
ndefault values
X.Alloc(N)creates an instance of the pose classXwithNdefault values, ie.len(X)will beN.Xcan be considered a vector of pose objects, and those elements can be referencedX[i]or assigned toX[i] = ....Note
The default value depends on the pose class and is the result of the empty constructor. For
SO2,SE2,SO3,SE3it is an identity matrix, for a twist classTwist2orTwist3it is a zero vector, for aUnitQuaternionorQuaternionit is a zero vector.Example:
>>> x = X.Alloc(10) >>> len(x) 10
where
Xis any of the SMTB classes.
- classmethod Empty()
Construct an empty instance (BasePoseList superclass method)
- Return type:
Self- Returns:
pose instance with zero values
Example:
>>> x = X.Empty() >>> len(x) 0
where
Xis any of the SMTB classes.
- classmethod Tx(x)[source]
Create a new 2D twist for pure translation along the X-axis
- Parameters:
x (float) – translation distance along the X-axis
- Returns:
2D twist vector
- Return type:
Twist2 instance
Twist2.Tx(x)is an se(2) translation ofxalong the x-axisExample:
- Seealso:
transl2()- SymPy:
supported
- classmethod Ty(y)[source]
Create a new 2D twist for pure translation along the Y-axis
- Parameters:
y (float) – translation distance along the Y-axis
- Returns:
2D twist vector
- Return type:
Twist2 instance
Twist2.Ty(y)is an se(2) translation ofyalong the y-axisExample:
- Seealso:
transl2()- SymPy:
supported
- classmethod UnitPrismatic(a)[source]
Construct a new 2D primsmatic unit twist
- Parameters:
a (array-like(2)) – Displacment
- Returns:
2D prismatic twist
- Return type:
Twist2 instance
Twist2.UnitPrismatic(a)is a 2D Twist object representing 2D-translation in the directiona.
Example:
>>> from spatialmath import Twist2 >>> Twist2.UnitPrismatic([1, 2]) Twist2([0.44721, 0.89443, 0])
- Seealso:
- classmethod UnitRevolute(q)[source]
Construct a new 2D revolute unit twist
- Parameters:
q (array_like(2)) – Point on the line of action
- Returns:
2D revolute twist
- Return type:
Twist2 instance
Twist2.UnitRevolute(q)is a 2D Twist object representing rotation about the 2D pointq.
Example:
>>> from spatialmath import Twist2 >>> Twist2.UnitRevolute([0, 1]) Twist2([1, -0, 1])
- Seealso:
- static isvalid(v, check=True)[source]
Test if matrix is valid twist
- Parameters:
v (ndarray) – array to test
- Returns:
Whether the value is a 3-vector or a valid 3x3 se(2) element
- Return type:
bool
A twist can be represented by a 3-vector or a 3x3 augmented skew symmetric matrix, for example:
>>> from spatialmath import Twist2, base >>> import numpy as np >>> Twist2.isvalid([1, 2, 3]) True >>> a = base.skewa([1, 2, 3]) >>> a array([[ 0., -3., 1.], [ 3., 0., 2.], [ 0., 0., 0.]]) >>> Twist2.isvalid(a) True >>> Twist2.isvalid(np.random.rand(3,3)) False
- Ad()[source]
Adjoint of 2D twist
- Returns:
adjoint matrix
- Return type:
ndarray(3,3)
S.Ad()is the 3x3 adjoint matrix of the corresponding homogeneous transformation.For a twist representing motion from frame {B} to {A}, the adjoint will transform a twist relative to frame {A} to one relative to frame {B}.
Example:
Note
This method computes the equivalent SE(2) matrix, then the adjoint of that.
- Seealso:
- SE2(theta=1, unit='rad')[source]
Convert 2D twist to SE(2) matrix
- Returns:
an SE(2) representation
- Return type:
SE2 instance
S.SE2()is an SE2 object representing the homogeneous transformation equivalent to the Twist2. This is the exponentiation of the twist vector.Example:
>>> from spatialmath import Twist2 >>> S = Twist2.UnitPrismatic([1,2]) >>> S.SE2() SE2(array([[1. , 0. , 0.4472], [0. , 1. , 0.8944], [0. , 0. , 1. ]]))
- Seealso:
- __eq__(right)
Overloaded
==operator (superclass method)- Returns:
Equality of two operands
- Return type:
bool or list of bool
S1 == S2is True ifS1` is elementwise equal to ``S2.Example:
- Seealso:
- __init__(arg=None, w=None, check=True)[source]
Construct a new 2D Twist object
- return:
2D twist
- rtype:
Twist2 instance
Twist2(R)is a 2D Twist object representing the SO(2) rotation expressed as a 2x2 matrix.Twist2(T)is a 2D Twist object representing the SE(2) rigid-body motion expressed as a 3x3 matrix.Twist2(X)if X is an SO2 instance then create a 2D Twist object representing the SO(2) rotation, and if X is an SE2 instance then create a 2D Twist object representing the SE(2) motionTwist2(V)is a 2D Twist object specified directly by a 3-element array-like comprising the moment vector (2 elements) and direction vector (1 element).
- References:
Robotics, Vision & Control for Python, Section 2.2.2.4, P. Corke, Springer 2023.
Modern Robotics, Lynch & Park, Cambridge 2017
Note
Compared to Lynch & Park this module implements twist vectors with the translational components first, followed by rotational components, ie. \([\vec{v}, \omega]\).
- __mul__(right)[source]
Overloaded
*operator- Parameters:
left – left multiplicand
right – right multiplicand
- Returns:
product
- Raises:
ValueError
X * Ycompounds the twistsXandYX * sperforms elementwise multiplication of the elements ofXbyss * Xperforms elementwise multiplication of the elements ofXbys
Multiplicands
Product
left
right
type
operation
Twist2
Twist2
Twist2
product of exponentials
Twist2
scalar
Twist2
element-wise product
scalar
Twist2
Twist2
element-wise product
Twist2
SE2
Twist2
exponential x SE2
Note
scalar x Twist is handled by
__rmul__scalar multiplication is commutative but the result is not a group operation so the result will be a matrix
Any other input combinations result in a ValueError.
For pose composition the
leftandrightoperands may be a sequencelen(left)
len(right)
len
operation
1
1
1
prod = left * right1
M
M
prod[i] = left * right[i]N
1
M
prod[i] = left[i] * rightM
M
M
prod[i] = left[i] * right[i]
- __ne__(right)
Overloaded
!=operator (superclass method)- Return type:
bool
S1 == S2is True ifS1is not elementwise equal toS2.Example:
- Seealso:
- __truediv__(right)
- ad()[source]
Logarithm of adjoint of 2D twist
- Returns:
logarithm of adjoint matrix
- Return type:
ndarray(3,3), or list of ndarray if the twist is a sequence
S.ad()is the 3x3 matrix representation of the Lie bracket with the twistS, such that for twistsSandT\[\mathrm{ad}(S) \vec{T} = \vee \left( [S] [T] - [T] [S] \right)\]where \([S]\) is the augmented skew-symmetric matrix of the twist. For \(S = (v_x, v_y, \omega)\) it is
\[\begin{split}\begin{pmatrix} 0 & -\omega & v_y \\ \omega & 0 & -v_x \\ 0 & 0 & 0 \end{pmatrix}\end{split}\]Example:
Note
An alternative approach to computing the adjoint is to exponentiate this 3x3 matrix.
- Seealso:
- append(item)
Append a value to an instance (BasePoseList superclass method)
- Parameters:
x (Quaternion or UnitQuaternion instance) – the value to append
- Raises:
ValueError – incorrect type of appended object
- Return type:
None
Appends the argument to the object’s internal list of values.
Example:
>>> x = X.Alloc(10) >>> len(x) 10 >>> x.append(X()) # append to the list >>> len(x) 11
where
Xis any of the SMTB classes.
- clear() None -- remove all items from S
- exp(theta=1, unit='rad')[source]
Exponentiate a 2D twist
- Parameters:
theta (float, optional) – rotation magnitude, defaults to 1
unit (str, optional) – rotational units, defaults to ‘rad’
- Returns:
SE(2) matrix
- Return type:
SE2 instance
X.exp()is the homogeneous transformation equivalent to the twist, \(e^{[S]}\)X.exp(θ)as above but with a rotation ofθabout the twist axis, \(e^{\theta[S]}\)
Example:
Note
For the second form, the twist must, if rotational, have a unit rotational component.
- Seealso:
spatialmath.smb.trexp2()
- extend(iterable)
Extend sequence of values in an instance (BasePoseList superclass method)
- Parameters:
x (instance of same type) – the value to extend
- Raises:
ValueError – incorrect type of appended object
- Return type:
None
Appends the argument’s values to the object’s internal list of values.
Example:
>>> x = X.Alloc(10) >>> len(x) 10 >>> x.append(X.Alloc(5)) # extend the list >>> len(x) 15
where
Xis any of the SMTB classes.
- insert(i, item)
Insert a value to an instance (BasePoseList superclass method)
- Parameters:
i (
int) – element to insert value beforeitem (
BasePoseList) – the value to insert
- Raises:
ValueError – incorrect type of inserted value
- Return type:
None
Inserts the argument into the object’s internal list of values.
Example:
>>> x = X.Alloc(10) >>> len(x) 10 >>> x.insert(0, X()) # insert at start of list >>> len(x) 11 >>> x.insert(10, X()) # append to the list >>> len(x) 11
where
Xis any of the SMTB classes.Note
If
iis beyond the end of the list, the item is appended to the list
- inv()
Inverse of Twist (superclass method)
- Returns:
inverse
- Return type:
Twist instance
Compute the inverse of each of the values within the twist instance. The inverse is the negative of the twist vector.
Example:
- pop(i=-1)
Pop value from an instance (BasePoseList superclass method)
- Parameters:
i (
Optional[int]) – item in the list to pop, default is last- Returns:
the popped value
- Return type:
Self- Raises:
IndexError – if there are no values to pop
Removes a value from the value list and returns it. The original instance is modified.
Example:
>>> x = X.Alloc(10) >>> len(x) 10 >>> y = x.pop() # pop the last value x[9] >>> len(x) 9 >>> y = x.pop(0) # pop the first value x[0] >>> len(x) 8
where
Xis any of the SMTB classes.
- prod()
Product of twists (superclass method)
For a twist instance with N values return the matrix product of those elements \(\prod_i=0^{N-1} S_i\).
Example:
- reverse()
S.reverse() – reverse IN PLACE
- skewa()[source]
Convert 2D twist to se(2)
- Returns:
An se(2) matrix
- Return type:
ndarray(3,3)
X.skewa()is the twist as a 3x3 augmented skew-symmetric matrix belonging to the group se(2). This is the Lie algebra of the corresponding SE(2) element.Example:
>>> from spatialmath import Twist2, base >>> S = Twist2([1,2,3]) >>> se = S.skewa() >>> se array([[ 0., -3., 1.], [ 3., 0., 2.], [ 0., 0., 0.]]) >>> base.trexp2(se) array([[-0.99 , -0.1411, -1.2796], [ 0.1411, -0.99 , 0.7574], [ 0. , 0. , 1. ]])
- unit()[source]
Unit twist
S.unit()is a Twist2 object representing a unit twist aligned with the TwistS.
Example:
- property A: Union[List[NDArray], NDArray]
Array value of an instance (BasePoseList superclass method)
- Returns:
NumPy array value of this instance
- Return type:
ndarray
X.Ais a NumPy array that represents the value of this instance, and has a shape given byX.shape.
Note
This assumes that
len(X)== 1, ie. it is a single-valued instance.
- property N
Dimension of the object’s group
- Returns:
dimension
- Return type:
int
Dimension of the group is 2 for
Twist2and corresponds to the dimension of the space (2D in this case) to which these rigid-body motions apply.Example:
- property S
Twist as a vector (superclass property)
- Returns:
Twist vector
- Return type:
ndarray(N)
X.Sis a 3-vector if X is aTwist2instance, and a 6-vector if X is aTwist3instance.
Note
the vector is the unique elements of the se(N) representation.
the vector is sometimes referred to as the twist coordinate vector.
if
len(X)> 1 then return a list of vectors.
- property isprismatic
Test for prismatic twist (superclass property)
- Returns:
Whether twist is purely prismatic
- Return type:
bool
A prismatic twist has \(\vec{\omega} = 0\).
Example:
>>> from spatialmath import Twist3 >>> x = Twist3.UnitPrismatic([1,2,3]) >>> x.isprismatic True >>> x = Twist3.UnitRevolute([1,2,3], [4,5,6]) >>> x.isprismatic False
- property isrevolute
Test for revolute twist (superclass property)
- Returns:
Whether twist is purely revolute
- Return type:
bool
A revolute twist has \(\vec{v} = 0\).
Example:
>>> from spatialmath import Twist3 >>> x = Twist3.UnitPrismatic([1,2,3]) >>> x.isrevolute False >>> x = Twist3.UnitRevolute([1,2,3], [0,0,0]) >>> x.isrevolute True
- property isunit
Test for unit twist (superclass property)
- Returns:
Whether twist is a unit-twist
- Return type:
bool
A unit twist is one with a norm of 1, ie. \(\| S \| = 1\).
Example:
>>> from spatialmath import Twist3 >>> S = Twist3([1,2,3,4,5,6]) >>> S.isunit False >>> S = Twist3.UnitRevolute([1,2,3], [4,5,6]) >>> S.isunit False
- property pole
Pole of a 2D twist
- Returns:
the pole of the twist
- Return type:
ndarray(2)
X.poleis a point on the twist axis. For a pure translation this point is at infinity.Example:
- property shape
Shape of the object’s interal array representation
- Returns:
(3,)
- Return type:
tuple
- property theta
Twist angle (superclass method)
- Returns:
magnitude of rotation (1x1) about the twist axis in radians
- Return type:
float
- property v
Moment vector of twist
- Returns:
Moment vector
- Return type:
ndarray(2)
X.vis a 2-vector representing the moment vector of the twist.Example:
- property w
Direction vector of twist
- Returns:
Direction vector
- Return type:
float
X.wis a scalar representing the direction “vector” of the twist.Example: