Transformations
Translation2d
Les opérations sur un Translation2d
exécutent des opérations sur le vecteur representé par le Translation2d
.
Addition: Addition between two
Translation2d
a and b can be performed usingplus
in Java, or the+
operator in C++/Python. Addition adds the two vectors.Subtraction: Subtraction between two
Translation2d
can be performed usingminus
in Java, or the binary-
operator in C++/Python. Subtraction subtracts the two vectors.Multiplication: Multiplication of a
Translation2d
and a scalar can be performed usingtimes
in Java, or the*
operator in C++/Python. This multiplies the vector by the scalar.Division: Division of a
Translation2d
and a scalar can be performed usingdiv
in Java, or the/
operator in C++/Python. This divides the vector by the scalar.Rotation: Rotation d’un
Translation2d
de façon anti-horaire en utilisant un angle de rotation \(\theta\) autour de l’origine. Cela peut être exécuté en utilisantrotateBy
, et équivaut à multiplier le vecteur par la matrice \(\begin{bmatrix} cos\theta & -sin\theta \\ sin\theta & cos\theta \end{bmatrix}\)Additionally, you can rotate a
Translation2d
by 180 degrees by usingunaryMinus
in Java, or the unary-
operator in C++/Python.
Rotation2d
Transformations sur un Translation2d
sont juste des opérations arithmétiques sur la mesure d’angle representé par le Rotation2d
.
plus
(Java) or+
(C++/Python): Adds the rotation component ofother
to thisRotation2d
’s rotation componentminus
(Java) or binary-
(C++/Python): Subtracts the rotation component ofother
to thisRotation2d
’s rotation componentunaryMinus
(Java) or unary-
(C++/Python): Multiplies the rotation component by a scalar of -1.times
(Java) or*
(C++/Python) : Multiplies the rotation component by a scalar.
Transform2d et Twist2d
WPILib provides 2 classes, Transform2d
(Java, C++, Python
), which represents a transformation to a pose, and Twist2d
(Java, C++, Python
) which represents a movement along an arc. Transform2d
and Twist2d
all have x, y and \(\theta\) components.
Transform2d
représente une transformation relative. Elle a deux composantes: une de transfert et l’autre de rotation. La transformation d’un Pose2d
par un Transform2d
s’effectue en faisant pivoter le composant « translation » du transfert selon le paramètre de rotation de la pose, et ensuite on ajoute le composant transfert tourné et le composant de rotation de pose. En d’autre termes, Pose2d.plus(Transform2d)
revient \(\begin{bmatrix} x_p \\ y_p \\ \theta_p \end{bmatrix}+\begin{bmatrix} cos\theta_p & -sin\theta_p & 0 \\ sin\theta_p & cos\theta_p & 0 \\ 0 & 0 & 1 \end{bmatrix}\begin{bmatrix}x_t \\ y_t \\ \theta_t \end{bmatrix}\)
Twist2d
represents a change in distance along an arc. Usually, this class is used to represent the movement of a drivetrain, where the x component is the forward distance driven, the y component is the distance driven to the side (left positive), and the \(\theta\) component is the change in heading. The underlying math behind finding the pose exponential (new pose after moving the pose forward along the curvature of the twist) can be found here in chapter 10.
Note
Pour les entraînements non holonomiques (comme le mode Tank), le composant y d’un Twist2d
devrait toujours être 0.
Both classes can be used to estimate robot location. Twist2d is used in WPILib’s odometry classes to update the robot’s pose based on movement, while Transform2d can be used to estimate the robot’s global position from vision data.