From ab69844906fc5ae8623c6efca233af3593ee1519 Mon Sep 17 00:00:00 2001 From: Zynh Ludwig Date: Thu, 28 Mar 2024 02:38:17 -0700 Subject: [PATCH] scaling factors --- src/main/cpp/cowlib/SwerveModule.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/cpp/cowlib/SwerveModule.cpp b/src/main/cpp/cowlib/SwerveModule.cpp index c06b39d..5171130 100644 --- a/src/main/cpp/cowlib/SwerveModule.cpp +++ b/src/main/cpp/cowlib/SwerveModule.cpp @@ -8,6 +8,7 @@ #include "frc/kinematics/SwerveModuleState.h" #include "rev/CANSparkMax.h" #include "units/angle.h" +#include "units/base.h" #include "units/voltage.h" #include "cowlib/SwerveModule.h" @@ -29,6 +30,15 @@ SwerveModule::SwerveModule(int driveMotorId, int steerMotorId, int encoderId, this->driveMotor.SetSmartCurrentLimit(SwerveConstants::currentLimit); this->steerMotor.SetSmartCurrentLimit(SwerveConstants::currentLimit); + + auto speedEncoder = this->driveMotor.GetEncoder(); + double driveReduction = 1.0 / 6.75; + double wheelDiameter = 0.1016; + double rotationsToDistance = + driveReduction * wheelDiameter * units::constants::detail::PI_VAL; + + speedEncoder.SetPositionConversionFactor(rotationsToDistance); + speedEncoder.SetVelocityConversionFactor(rotationsToDistance / 60); } void SwerveModule::drive(double speedMetersPerSecond, double angle) {