45 Swerve(std::string name, std::vector<std::pair<std::unique_ptr<BaseController>, std::unique_ptr<BaseController>>> modules,
46 std::shared_ptr<gyro::Gyro> gyro, units::meter_t module_radius, units::meter_t _wheelDiameter, std::vector<int> moduleCoordsX,
47 std::vector<int> moduleCoordsY, units::meter_t driveBaseRadius);
53 void SimulationPeriodic()
override;
80 double GetSkiddingRatio();
81 bool IsRobotSkidding();
83 constexpr std::vector<std::unique_ptr<SwerveModule>>& GetModules() {
return swerveModules; }
90 units::angular_acceleration::radians_per_second_squared_t GetSmoothedAngularAcceleration();
91 double RotationLerping(
double);
92 void FollowTrajectory(
const choreo::SwerveSample& sample);
94 constexpr units::meter_t GetDriveBaseRadius()
const {
return driveBaseRadius; };
96 constexpr const auto& GetState()
const {
return state; }
98 constexpr auto& GetState() {
return state; }
101 FrameWrapper<FieldFrame, frc::ChassisSpeeds> commandedSpeeds;
103 units::meters_per_second_t maxDriveSpeed;
104 units::radians_per_second_t maxRotationSpeed;
106 std::shared_ptr<gyro::Gyro> gyro;
107 std::unique_ptr<ctre::phoenix6::swerve::impl::SwerveDriveKinematics> kinematics;
108 util::Locked<std::unique_ptr<ctre::phoenix6::swerve::impl::SwerveDrivePoseEstimator>> rawEstimator;
109 util::Locked<std::unique_ptr<ctre::phoenix6::swerve::impl::SwerveDrivePoseEstimator>> calcEstimator;
113 void EnableCarpetGrain(
double grainMultiplier,
bool roughTowardsRed);
115 FrameWrapper<FieldFrame, frc::ChassisSpeeds> VectorLockedSpeeds(FrameWrapper<FieldFrame, frc::ChassisSpeeds> speeds,
116 FrameWrapper<FieldFrame, frc::Rotation2d> heading);
118 std::vector<std::unique_ptr<SwerveModule>> swerveModules;
120 void StartOdomThread(units::hertz_t freq);
121 void UpdateOdometry();
123 void SetRotationalLerpMap(wpi::interpolating_map<double, double> _interpolationMap);
125 static FrameWrapper<FieldFrame, frc::ChassisSpeeds> ReflectDriveSpeeds(FrameWrapper<FieldFrame, frc::ChassisSpeeds> unreflectedSpeeds) {
126 if (frc::DriverStation::GetAlliance().value_or(frc::DriverStation::Alliance::kBlue) == frc::DriverStation::Alliance::kRed) {
127 return frc::ChassisSpeeds{-unreflectedSpeeds->vx, -unreflectedSpeeds->vy, unreflectedSpeeds->omega};
129 return unreflectedSpeeds;
132 frc::Timer resetOdom;
135 std::deque<units::angular_acceleration::radians_per_second_squared_t> yawRateBuffer;
137 static constexpr size_t ACCEL_BUFFER_SIZE = 10;
138 units::angular_velocity::radians_per_second_t lastYawRate = 0_rad_per_s;
140 units::angular_acceleration::radians_per_second_squared_t angularAcceleration = 0_rad_per_s_sq;
143 double carpetGrainMultiplier;
144 bool roughTowardsRed;
145 void CalculateCarpetPose();
148 FrameWrapper<FieldFrame, frc::Pose2d> rawPose;
149 FrameWrapper<FieldFrame, frc::Pose2d> calculatedPose;
150 FrameWrapper<FieldFrame, frc::ChassisSpeeds> fieldSpeeds;
151 FrameWrapper<RobotFrame, frc::ChassisSpeeds> robotSpeeds;
153 std::vector<frc::SwerveModuleState> moduleStates;
155 frc::Rotation3d gyroRotation;
156 gyro::Gyro::AngularVelocity3d gyroVelocity;
159 units::meter_t driveBaseRadius;
161 frc::Notifier odometryThread{[
this] { UpdateOdometry(); }};
163 frc::PIDController xChoreoController{10.0, 0.0, 0.0};
164 frc::PIDController yChoreoController{10.0, 0.0, 0.0};
165 frc::PIDController headingChoreoController{7.5, 0.0, 0.0};
167 wpi::interpolating_map<double, double> rotationalLerpMap;