current limit and namespace stuff

main
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; using MotorType = rev::CANSparkMax::MotorType;
SwerveModule::SwerveModule(int driveMotorId, int steerMotorId, int encoderId, SwerveModule::SwerveModule(int driveMotorId, int steerMotorId, int encoderId,
bool driveInverted) bool driveInverted, double maxVelocity,
double maxVoltage)
: driveMotor{driveMotorId, rev::CANSparkMax::MotorType::kBrushless}, : driveMotor{driveMotorId, rev::CANSparkMax::MotorType::kBrushless},
steerMotor{steerMotorId, 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->pid.EnableContinuousInput(-180, 180);
this->driveMotor.SetInverted(driveInverted); 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 { namespace SwerveConstants {
inline constexpr unsigned int currentLimit = 40;
namespace SwervePID { namespace SwervePID {
inline constexpr double p = 0.12; inline constexpr double p = 0.12;

View File

@ -14,8 +14,10 @@ private:
rev::CANSparkMax steerMotor; rev::CANSparkMax steerMotor;
ctre::phoenix6::hardware::CANcoder encoder; ctre::phoenix6::hardware::CANcoder encoder;
frc::PIDController pid; frc::PIDController pid;
double maxVelocity;
double maxVoltage;
public: public:
SwerveModule(int driveMotorId, int steerMotorId, int encoderId, SwerveModule(int driveMotorId, int steerMotorId, int encoderId,
bool driveInverted); bool driveInverted, double maxVelocity, double maxVoltage);
}; };