[wpimath] Replace Speeds with Velocities (#8479)

I left "free speed" alone since that's the technical term for it. In
general, velocity is a vector quantity, and speed is a magnitude (i.e.,
a strictly positive value).

This PR also replaces the speed verbiage in MotorController with duty
cycle.

Fixes #8423.
This commit is contained in:
Tyler Veness
2026-03-06 14:19:15 -08:00
committed by GitHub
parent 1e39f39128
commit 9bd9656871
594 changed files with 8073 additions and 7875 deletions

View File

@@ -2,7 +2,7 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "wpi/math/kinematics/struct/ChassisSpeedsStruct.hpp"
#include "wpi/math/kinematics/struct/ChassisVelocitiesStruct.hpp"
namespace {
constexpr size_t kVxOff = 0;
@@ -10,10 +10,10 @@ constexpr size_t kVyOff = kVxOff + 8;
constexpr size_t kOmegaOff = kVyOff + 8;
} // namespace
using StructType = wpi::util::Struct<wpi::math::ChassisSpeeds>;
using StructType = wpi::util::Struct<wpi::math::ChassisVelocities>;
wpi::math::ChassisSpeeds StructType::Unpack(std::span<const uint8_t> data) {
return wpi::math::ChassisSpeeds{
wpi::math::ChassisVelocities StructType::Unpack(std::span<const uint8_t> data) {
return wpi::math::ChassisVelocities{
wpi::units::meters_per_second_t{
wpi::util::UnpackStruct<double, kVxOff>(data)},
wpi::units::meters_per_second_t{
@@ -24,7 +24,7 @@ wpi::math::ChassisSpeeds StructType::Unpack(std::span<const uint8_t> data) {
}
void StructType::Pack(std::span<uint8_t> data,
const wpi::math::ChassisSpeeds& value) {
const wpi::math::ChassisVelocities& value) {
wpi::util::PackStruct<kVxOff>(data, value.vx.value());
wpi::util::PackStruct<kVyOff>(data, value.vy.value());
wpi::util::PackStruct<kOmegaOff>(data, value.omega.value());

View File

@@ -2,18 +2,19 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "wpi/math/kinematics/struct/DifferentialDriveWheelSpeedsStruct.hpp"
#include "wpi/math/kinematics/struct/DifferentialDriveWheelVelocitiesStruct.hpp"
namespace {
constexpr size_t kLeftOff = 0;
constexpr size_t kRightOff = kLeftOff + 8;
} // namespace
using StructType = wpi::util::Struct<wpi::math::DifferentialDriveWheelSpeeds>;
using StructType =
wpi::util::Struct<wpi::math::DifferentialDriveWheelVelocities>;
wpi::math::DifferentialDriveWheelSpeeds StructType::Unpack(
wpi::math::DifferentialDriveWheelVelocities StructType::Unpack(
std::span<const uint8_t> data) {
return wpi::math::DifferentialDriveWheelSpeeds{
return wpi::math::DifferentialDriveWheelVelocities{
wpi::units::meters_per_second_t{
wpi::util::UnpackStruct<double, kLeftOff>(data)},
wpi::units::meters_per_second_t{
@@ -21,8 +22,9 @@ wpi::math::DifferentialDriveWheelSpeeds StructType::Unpack(
};
}
void StructType::Pack(std::span<uint8_t> data,
const wpi::math::DifferentialDriveWheelSpeeds& value) {
void StructType::Pack(
std::span<uint8_t> data,
const wpi::math::DifferentialDriveWheelVelocities& value) {
wpi::util::PackStruct<kLeftOff>(data, value.left.value());
wpi::util::PackStruct<kRightOff>(data, value.right.value());
}

View File

@@ -2,7 +2,7 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "wpi/math/kinematics/struct/MecanumDriveWheelSpeedsStruct.hpp"
#include "wpi/math/kinematics/struct/MecanumDriveWheelVelocitiesStruct.hpp"
namespace {
constexpr size_t kFrontLeftOff = 0;
@@ -11,11 +11,11 @@ constexpr size_t kRearLeftOff = kFrontRightOff + 8;
constexpr size_t kRearRightOff = kRearLeftOff + 8;
} // namespace
using StructType = wpi::util::Struct<wpi::math::MecanumDriveWheelSpeeds>;
using StructType = wpi::util::Struct<wpi::math::MecanumDriveWheelVelocities>;
wpi::math::MecanumDriveWheelSpeeds StructType::Unpack(
wpi::math::MecanumDriveWheelVelocities StructType::Unpack(
std::span<const uint8_t> data) {
return wpi::math::MecanumDriveWheelSpeeds{
return wpi::math::MecanumDriveWheelVelocities{
wpi::units::meters_per_second_t{
wpi::util::UnpackStruct<double, kFrontLeftOff>(data)},
wpi::units::meters_per_second_t{
@@ -28,7 +28,7 @@ wpi::math::MecanumDriveWheelSpeeds StructType::Unpack(
}
void StructType::Pack(std::span<uint8_t> data,
const wpi::math::MecanumDriveWheelSpeeds& value) {
const wpi::math::MecanumDriveWheelVelocities& value) {
wpi::util::PackStruct<kFrontLeftOff>(data, value.frontLeft.value());
wpi::util::PackStruct<kFrontRightOff>(data, value.frontRight.value());
wpi::util::PackStruct<kRearLeftOff>(data, value.rearLeft.value());

View File

@@ -1,26 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "wpi/math/kinematics/struct/SwerveModuleStateStruct.hpp"
namespace {
constexpr size_t kSpeedOff = 0;
constexpr size_t kAngleOff = kSpeedOff + 8;
} // namespace
using StructType = wpi::util::Struct<wpi::math::SwerveModuleState>;
wpi::math::SwerveModuleState StructType::Unpack(std::span<const uint8_t> data) {
return wpi::math::SwerveModuleState{
wpi::units::meters_per_second_t{
wpi::util::UnpackStruct<double, kSpeedOff>(data)},
wpi::util::UnpackStruct<wpi::math::Rotation2d, kAngleOff>(data),
};
}
void StructType::Pack(std::span<uint8_t> data,
const wpi::math::SwerveModuleState& value) {
wpi::util::PackStruct<kSpeedOff>(data, value.speed.value());
wpi::util::PackStruct<kAngleOff>(data, value.angle);
}

View File

@@ -0,0 +1,27 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "wpi/math/kinematics/struct/SwerveModuleVelocityStruct.hpp"
namespace {
constexpr size_t kVelocityOff = 0;
constexpr size_t kAngleOff = kVelocityOff + 8;
} // namespace
using StructType = wpi::util::Struct<wpi::math::SwerveModuleVelocity>;
wpi::math::SwerveModuleVelocity StructType::Unpack(
std::span<const uint8_t> data) {
return wpi::math::SwerveModuleVelocity{
wpi::units::meters_per_second_t{
wpi::util::UnpackStruct<double, kVelocityOff>(data)},
wpi::util::UnpackStruct<wpi::math::Rotation2d, kAngleOff>(data),
};
}
void StructType::Pack(std::span<uint8_t> data,
const wpi::math::SwerveModuleVelocity& value) {
wpi::util::PackStruct<kVelocityOff>(data, value.velocity.value());
wpi::util::PackStruct<kAngleOff>(data, value.angle);
}