// Copyright (c) FIRST and other WPILib contributors. // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. #pragma once #include #include #include #include #include #include #include #include #include #include "Constants.h" class SwerveModule { public: SwerveModule(int driveMotorChannel, int turningMotorChannel, const int driveEncoderPorts[2], const int turningEncoderPorts[2], bool driveEncoderReversed, bool turningEncoderReversed); frc::SwerveModuleState GetState(); frc::SwerveModulePosition GetPosition(); void SetDesiredState(frc::SwerveModuleState& state); void ResetEncoders(); private: // We have to use meters here instead of radians due to the fact that // ProfiledPIDController's constraints only take in meters per second and // meters per second squared. static constexpr auto kModuleMaxAngularVelocity = units::radians_per_second_t{std::numbers::pi}; static constexpr auto kModuleMaxAngularAcceleration = units::radians_per_second_squared_t{std::numbers::pi * 2.0}; frc::Spark m_driveMotor; frc::Spark m_turningMotor; frc::Encoder m_driveEncoder; frc::Encoder m_turningEncoder; frc::PIDController m_drivePIDController{ ModuleConstants::kPModuleDriveController, 0, 0}; frc::ProfiledPIDController m_turningPIDController{ ModuleConstants::kPModuleTurningController, 0.0, 0.0, {kModuleMaxAngularVelocity, kModuleMaxAngularAcceleration}}; };