Introduction to Kinematics and The ChassisSpeeds Class

备注

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

什么是运动学?

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.

什么是测距法?

测距法涉及使用机器人上的传感器来估计机器人在场上的位置。在FRC中,这些传感器通常是几个编码器(具体数量取决于驱动类型)和一个陀螺仪来测量机器人的角度。运动学类利用运动学类和用户定期输入的速度(和转弯时的角度)来估计机器人在场上的位置。

The ChassisSpeeds Class

``ChassisSpeeds``对象对新的WPILib运动学和里程测量套件至关重要。``ChassisSpeeds``对象表示机器人底盘的速度。该结构有三个组成部分:

  • vx:机器人在x(前进)方向的速度。

  • vy:机器人在y(横向)方向的速度。(正值表示机器人向左移动)。

  • omega:机器人的角速度,单位为每秒弧度。

备注

非整体性传动系统(即不能横向移动的传动系统,例如:差速驱动)由于不能横向移动,其 “vy “分量为零。

构造一个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)

从相对场地速度创建ChassisSpeeds对象

当机器人角度给定时,还可以用一组场内相对速度创建一个``底盘速度``对象。这将一组相对于场域的期望速度(例如,朝向对面联盟站和朝向右场边界)转换为``ChassisSpeeds``对象,它表示相对于机器人框架的速度。这对于实现面向场地的控制,对转向或麦轮驱动机器人是有用的。

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))

备注

角速度没有明确说是 “相对于场”,因为从场角度或机器人角度测量的角速度是一样的。