2022-10-25 15:28:36 -04:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/math/geometry/Rotation2d.hpp"
|
|
|
|
|
#include "wpi/units/length.hpp"
|
|
|
|
|
#include "wpi/units/math.hpp"
|
2025-11-07 19:57:55 -05:00
|
|
|
#include "wpi/util/MathExtras.hpp"
|
|
|
|
|
#include "wpi/util/SymbolExports.hpp"
|
2022-10-25 15:28:36 -04:00
|
|
|
|
|
|
|
|
namespace frc {
|
|
|
|
|
/**
|
|
|
|
|
* Represents the position of one swerve module.
|
|
|
|
|
*/
|
|
|
|
|
struct WPILIB_DLLEXPORT SwerveModulePosition {
|
|
|
|
|
/**
|
|
|
|
|
* Distance the wheel of a module has traveled
|
|
|
|
|
*/
|
|
|
|
|
units::meter_t distance = 0_m;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Angle of the module.
|
|
|
|
|
*/
|
|
|
|
|
Rotation2d angle;
|
2023-01-08 17:29:35 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks equality between this SwerveModulePosition and another object.
|
|
|
|
|
*
|
|
|
|
|
* @param other The other object.
|
|
|
|
|
* @return Whether the two objects are equal.
|
|
|
|
|
*/
|
2024-10-22 06:58:06 -07:00
|
|
|
constexpr bool operator==(const SwerveModulePosition& other) const {
|
|
|
|
|
return units::math::abs(distance - other.distance) < 1E-9_m &&
|
|
|
|
|
angle == other.angle;
|
|
|
|
|
}
|
2023-06-19 17:10:39 -07:00
|
|
|
|
2024-10-22 06:58:06 -07:00
|
|
|
constexpr SwerveModulePosition Interpolate(
|
|
|
|
|
const SwerveModulePosition& endValue, double t) const {
|
2023-06-19 17:10:39 -07:00
|
|
|
return {wpi::Lerp(distance, endValue.distance, t),
|
|
|
|
|
wpi::Lerp(angle, endValue.angle, t)};
|
|
|
|
|
}
|
2022-10-25 15:28:36 -04:00
|
|
|
};
|
|
|
|
|
} // namespace frc
|
2023-11-21 13:14:06 -05:00
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/math/kinematics/proto/SwerveModulePositionProto.hpp"
|
|
|
|
|
#include "wpi/math/kinematics/struct/SwerveModulePositionStruct.hpp"
|