差动驱动运动学

``DifferentialDriveKinematics``类是一个有用的工具,它可以在``ChassisSpeeds``对象和``DifferentialDriveWheelSpeeds``对象之间进行转换,其中包含差动驱动机器人左右两侧的速度。

构造运动学对象

“DifferentialDriveKinematics”对象接受一个构造函数参数,即机器人的轨道宽度。这代表了差速器上两组轮子之间的距离。

备注

在Java中,磁道宽度必须以米为单位。在C ++中,单位库可用于以任何长度单位传递轨道宽度。

将底盘速度转换为车轮速度

toWheelSpeeds(ChassisSpeeds speeds)``(Java)/``ToWheelSpeeds(ChassisSpeeds speeds)``(C++)方法应该用于将``ChassisSpeeds``对象转换为``DifferentialDriveWheelSpeeds``对象。当你需要将线性速度(``vx)和角速度(omega)转换为左轮和右轮速度时,这个方法很有用。

// 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;

将车轮速度转换为底盘速度

我们还可以使用运动学对象将单个轮速(左和右)转换为一个单一的``ChassisSpeeds``对象。应该使用``toChassisSpeeds(DifferentialDriveWheelSpeeds speeds)``(Java)/``ToChassisSpeeds(DifferentialDriveWheelSpeeds speeds)``(C++)方法来实现。

// 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;