Introduction to Kinematics and The ChassisSpeeds Class

Nota

Kinematics and odometry uses a common coordinate system. You may wish to reference the Coordinate System section for details.

¿Qué es la cinemática?

The kinematics suite contains classes for differential drive, swerve drive, and mecanum drive kinematics and odometry. The kinematics classes help convert between a universal ChassisSpeeds (Java, C++, Python)object, containing linear and angular velocities for a robot to usable speeds for each individual type of drivetrain i.e. left and right wheel speeds for a differential drive, four wheel speeds for a mecanum drive, or individual module states (speed and angle) for a swerve drive.

¿Qué es la odometría?

La odometría implica el uso de sensores en el robot para crear una estimación de la posición del robot en el campo. En FRC, estos sensores suelen ser varios codificadores (el número exacto depende del tipo de unidad) y un giroscopio para medir el ángulo del robot. Las clases de odometría utilizan las clases de cinemática junto con las entradas periódicas del usuario sobre velocidades (y ángulos en el caso de viraje) para crear una estimación de la ubicación del robot en el campo.

The ChassisSpeeds Class

El objeto ChassisSpeeds es esencial para la nueva suite de cinemática y odometría de WPILib. El objeto ChassisSpeeds representa las velocidades de un chasis de robot. Esta estructura tiene tres componentes:

  • vx: la velocidad del robot en la dirección x (hacia adelante).

  • vy: la velocidad del robot en la dirección y (lateral). (Los valores positivos significan que el robot se mueve hacia la izquierda).

  • omega: la velocidad angular del robot en radianes por segundo.

Nota

Un tren motriz no holonómico (es decir, un tren motriz que no se puede mover hacia los lados, por ejemplo, un accionamiento diferencial) tendrá un componente vy de cero debido a su incapacidad para moverse hacia los lados.

Construcción de un objeto ChassisSpeeds

The constructor for the ChassisSpeeds object is very straightforward, accepting three arguments for vx, vy, and omega. In Java and Python, vx and vy must be in meters per second. In C++, the units library may be used to provide a linear velocity using any linear velocity unit.

// The robot is moving at 3 meters per second forward, 2 meters
// per second to the right, and rotating at half a rotation per
// second counterclockwise.
var speeds = new ChassisSpeeds(3.0, -2.0, Math.PI);
// The robot is moving at 3 meters per second forward, 2 meters
// per second to the right, and rotating at half a rotation per
// second counterclockwise.
frc::ChassisSpeeds speeds{3.0_mps, -2.0_mps,
  units::radians_per_second_t(std::numbers::pi)};
import math
from wpimath.kinematics import ChassisSpeeds

# The robot is moving at 3 meters per second forward, 2 meters
# per second to the right, and rotating at half a rotation per
# second counterclockwise.
speeds = ChassisSpeeds(3.0, -2.0, math.pi)

Creación de un objeto ChassisSpeeds a partir de velocidades relativas al campo

También se puede crear un objeto ChassisSpeeds a partir de un conjunto de velocidades relativas al campo cuando se proporciona el ángulo del robot. Esto convierte un conjunto de velocidades deseadas relativas al campo (por ejemplo, hacia la estación de alianza opuesta y hacia el límite del campo derecho) en un objeto ChassisSpeeds que representa velocidades relativas al marco del robot. Esto es útil para implementar controles orientados al campo para un robot de accionamiento giratorio o mecanum.

The static ChassisSpeeds.fromFieldRelativeSpeeds (Java / Python) / ChassisSpeeds::FromFieldRelativeSpeeds (C++) method can be used to generate the ChassisSpeeds object from field-relative speeds. This method accepts the vx (relative to the field), vy (relative to the field), omega, and the robot angle.

// The desired field relative speed here is 2 meters per second
// toward the opponent's alliance station wall, and 2 meters per
// second toward the left field boundary. The desired rotation
// is a quarter of a rotation per second counterclockwise. The current
// robot angle is 45 degrees.
ChassisSpeeds speeds = ChassisSpeeds.fromFieldRelativeSpeeds(
  2.0, 2.0, Math.PI / 2.0, Rotation2d.fromDegrees(45.0));
// The desired field relative speed here is 2 meters per second
// toward the opponent's alliance station wall, and 2 meters per
// second toward the left field boundary. The desired rotation
// is a quarter of a rotation per second counterclockwise. The current
// robot angle is 45 degrees.
frc::ChassisSpeeds speeds = frc::ChassisSpeeds::FromFieldRelativeSpeeds(
  2_mps, 2_mps, units::radians_per_second_t(std::numbers::pi / 2.0), Rotation2d(45_deg));
import math
from wpimath.kinematics import ChassisSpeeds
from wpimath.geometry  import Rotation2d

# The desired field relative speed here is 2 meters per second
# toward the opponent's alliance station wall, and 2 meters per
# second toward the left field boundary. The desired rotation
# is a quarter of a rotation per second counterclockwise. The current
# robot angle is 45 degrees.
speeds = ChassisSpeeds.fromFieldRelativeSpeeds(
  2.0, 2.0, math.pi / 2.0, Rotation2d.fromDegrees(45.0))

Nota

No se establece explícitamente que la velocidad angular sea «relativa al campo» porque la velocidad angular es la misma que se mide desde una perspectiva de campo o una perspectiva de robot.