Transformaciones

Translation2d

Las operaciones en un Translation2d llevan a cabo operaciones en el vector representado por Translation2d.

  • Addition: Addition between two Translation2d a and b can be performed using plus in Java, or the + operator in C++/Python. Addition adds the two vectors.

  • Subtraction: Subtraction between two Translation2d can be performed using minus 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 using times 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 using div in Java, or the / operator in C++/Python. This divides the vector by the scalar.

  • Rotación: La rotación de un Translation2d por una rotación contraria a las manecillas del reloj \(\theta\) sobre el origen puede ser logrado al usar rotateBy. Esto es equivalente a multiplicar el vector por la matriz \(\begin{bmatrix} cos\theta & -sin\theta \\ sin\theta & cos\theta \end{bmatrix}\)

  • Additionally, you can rotate a Translation2d by 180 degrees by using unaryMinus in Java, or the unary - operator in C++/Python.

Rotation2d

Las transformaciones para Rotation2d son solo operaciones aritméticas en la medida del ángulo representadas por Rotation2d.

  • plus (Java) or + (C++/Python): Adds the rotation component of other to this Rotation2d’s rotation component

  • minus (Java) or binary - (C++/Python): Subtracts the rotation component of other to this Rotation2d’s rotation component

  • unaryMinus (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 y 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 representa una transformación relativa. Tiene un componente de rotación y traslación. Transformar un Pose2d por un Transform2d rota el componente de traslación de la transformación por la rotación de la pose, y entonces suma el componente de traslación y el componente de rotación de la pose. En otras palabras, Pose2d.plus(Transform2d) regresa \(\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.

Nota

Para trenes motrices no holonómicos, el componente y de Twist2d debe siempre ser 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.