Transformations
Translation2d
פעולות על אובייקט Translation2d
מבצעות פעולות על הווקטור שמיוצג באותו אובייקט.
חיבור: חיבור בין שני אובייקטי
Translation2d
ניתן לבצע עםplus
ב-Java ועם האופרטור+
ב-C++. זה מחבר את שני הווקטורים.חיסור: חיסור בין שני אובייקטי
Translation2d
יכול להתבצע עםminus
ב-Java ועם האופרטור-
ב-C++. זה מחסיר בין שני הווקטורים.כפל: כפל של
Translation2d
בסקלר ניתן לבצע עםtimes
ב-Java ועם האופרטור*
ב-C++. זה מכפיל את הווקטור בסקלר.חילוק: חילוק של
Translation2d
בסקלר ניתן לבצע עםdiv
ב-Java ועם האופרטור/
ב-C++. זה מחלק את הווקטור בסקלר.Rotation: Rotation of a
Translation2d
by a counter-clockwise rotation \(\theta\) about the origin can be performed by usingrotateBy
. This is equivalent to multiplying the vector by the matrix \(\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++.
Rotation2d
פעולות על אובייקט Rotation2d
הם פשוט פעולות מתמטיות על הזווית שמיוצגת באותו אובייקט.
plus
(Java) or+
(C++): Adds the rotation component ofother
to thisRotation2d
’s rotation componentminus
(Java) or binary-
(C++): Subtracts the rotation component ofother
to thisRotation2d
’s rotation componentunaryMinus
(Java) or unary-
(C++): Multiplies the rotation component by a scalar of -1.times
(Java) or*
(C++) : Multiplies the rotation component by a scalar.
Transform2d ו-Twist2d
WPILib provides 2 classes, Transform2d
(Java, C++), which represents a transformation to a pose, and Twist2d
(Java, C++) which represents a movement along an arc. Transform2d
and Twist2d
all have x, y and \(\theta\) components.
Transform2d
represents a relative transformation. It has an translation and a rotation component. Transforming a Pose2d
by a Transform2d
rotates the translation component of the transform by the rotation of the pose, and then adds the rotated translation component and the rotation component to the pose. In other words, Pose2d.plus(Transform2d)
returns \(\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.
הערה
For nonholonomic drivetrains, the y component of a Twist2d
should always be 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.