Cinemática de direção diferencial

The DifferentialDriveKinematics class is a useful tool that converts between a ChassisSpeeds object and a DifferentialDriveWheelSpeeds object, which contains velocities for the left and right sides of a differential drive robot.

Construindo o objeto cinemático

The DifferentialDriveKinematics object accepts one constructor argument, which is the track width of the robot. This represents the distance between the two sets of wheels on a differential drive.

Nota

In Java, the track width must be in meters. In C++, the units library can be used to pass in the track width using any length unit.

Convertendo Speeds Do Chassi Em Speeds Das Rodas

O método toWheelSpeeds(ChassisSpeeds speeds) (Java) / ToWheelSpeeds(ChassisSpeeds speeds) (C++) deve ser utilizado para converter o objeto ChassisSpeeds para o objeto DifferentialDriveWheelSpeeds. Isso é útil em situações onde você deve converter uma velocity linear («vx») e uma velocity angular («omega») para as velocities esquerda e direita das rodas.

// Creating my kinematics object: track width of 27 inches
DifferentialDriveKinematics kinematics =
  new DifferentialDriveKinematics(Units.inchesToMeters(27.0));

// Example chassis speeds: 2 meters per second linear velocity,
// 1 radian per second angular velocity.
var chassisSpeeds = new ChassisSpeeds(2.0, 0, 1.0);

// Convert to wheel speeds
DifferentialDriveWheelSpeeds wheelSpeeds = kinematics.toWheelSpeeds(chassisSpeeds);

// Left velocity
double leftVelocity = wheelSpeeds.leftMetersPerSecond;

// Right velocity
double rightVelocity = wheelSpeeds.rightMetersPerSecond;

Convertendo Speeds Das Rodas para Speeds Do Chassi

Também é possível utilizar o objeto cinemático para converter as speeds das rodas individualmente (esquerda e direita) para um único objeto ChassisSpeeds. O método toChassisSpeeds(DifferentialDriveWheelSpeeds speeds) (Java) / ToChassisSpeeds(DifferentialDriveWheelSpeeds speeds) (C++) deve ser utilizado para alcançar isso.

// Creating my kinematics object: track width of 27 inches
DifferentialDriveKinematics kinematics =
  new DifferentialDriveKinematics(Units.inchesToMeters(27.0));

// Example differential drive wheel speeds: 2 meters per second
// for the left side, 3 meters per second for the right side.
var wheelSpeeds = new DifferentialDriveWheelSpeeds(2.0, 3.0);

// Convert to chassis speeds.
ChassisSpeeds chassisSpeeds = kinematics.toChassisSpeeds(wheelSpeeds);

// Linear velocity
double linearVelocity = chassisSpeeds.vxMetersPerSecond;

// Angular velocity
double angularVelocity = chassisSpeeds.omegaRadiansPerSecond;