current limit and namespace stuff

This commit is contained in:
Zynh Ludwig 2024-03-28 01:48:26 -07:00
parent ec14c8151e
commit bbd9e816bc
3 changed files with 12 additions and 3 deletions

View file

@ -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);
}

View file

@ -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;

View file

@ -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);
};