diff --git a/src/main/cpp/cowlib/SwerveModule.cpp b/src/main/cpp/cowlib/SwerveModule.cpp index 38b7d21..a6eac1e 100644 --- a/src/main/cpp/cowlib/SwerveModule.cpp +++ b/src/main/cpp/cowlib/SwerveModule.cpp @@ -12,11 +12,16 @@ using namespace SwerveConstants; using MotorType = rev::CANSparkMax::MotorType; SwerveModule::SwerveModule(int driveMotorId, int steerMotorId, int encoderId, - bool driveInverted) + bool driveInverted, double maxVelocity, + double maxVoltage) : driveMotor{driveMotorId, rev::CANSparkMax::MotorType::kBrushless}, steerMotor{steerMotorId, rev::CANSparkMax::MotorType::kBrushless}, - encoder{encoderId}, pid{SwervePID::p, SwervePID::i, SwervePID::d} { + encoder{encoderId}, pid{SwervePID::p, SwervePID::i, SwervePID::d}, + maxVelocity{maxVelocity}, maxVoltage{maxVoltage} { this->pid.EnableContinuousInput(-180, 180); this->driveMotor.SetInverted(driveInverted); + + this->driveMotor.SetSmartCurrentLimit(SwerveConstants::currentLimit); + this->steerMotor.SetSmartCurrentLimit(SwerveConstants::currentLimit); } diff --git a/src/main/include/Constants.h b/src/main/include/Constants.h index 542ea4e..d0885fe 100644 --- a/src/main/include/Constants.h +++ b/src/main/include/Constants.h @@ -22,6 +22,8 @@ inline constexpr int driveControllerPort = 0; namespace SwerveConstants { +inline constexpr unsigned int currentLimit = 40; + namespace SwervePID { inline constexpr double p = 0.12; diff --git a/src/main/include/cowlib/SwerveModule.h b/src/main/include/cowlib/SwerveModule.h index 8bdf28d..377a022 100644 --- a/src/main/include/cowlib/SwerveModule.h +++ b/src/main/include/cowlib/SwerveModule.h @@ -14,8 +14,10 @@ private: rev::CANSparkMax steerMotor; ctre::phoenix6::hardware::CANcoder encoder; frc::PIDController pid; + double maxVelocity; + double maxVoltage; public: SwerveModule(int driveMotorId, int steerMotorId, int encoderId, - bool driveInverted); + bool driveInverted, double maxVelocity, double maxVoltage); };