encoder and pid loops

main
Zynh0722 2024-03-27 17:31:15 -07:00
parent cbd86a7a67
commit 09310a745f
4 changed files with 22 additions and 3 deletions

View File

@ -2,11 +2,16 @@
// 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.
#include "Constants.h"
#include "rev/CANSparkMax.h"
#include "cowlib/SwerveModule.h"
using namespace SwerveConstants;
using MotorType = rev::CANSparkMax::MotorType;
SwerveModule::SwerveModule(int driveMotorId, int steerMotorId, int encoderId)
: driveMotor{driveMotorId, rev::CANSparkMax::MotorType::kBrushless},
steerMotor{steerMotorId, rev::CANSparkMax::MotorType::kBrushless},
encoder{encoderId} {}
encoder{encoderId}, pid{SwervePID::p, SwervePID::i, SwervePID::d} {}

View File

@ -16,6 +16,18 @@
namespace OperatorConstants {
inline constexpr int kDriverControllerPort = 0;
inline constexpr int driveControllerPort = 0;
} // namespace OperatorConstants
namespace SwerveConstants {
namespace SwervePID {
inline constexpr double p = 0.12;
inline constexpr double i = 0;
inline constexpr double d = 0.0015;
}; // namespace SwervePID
} // namespace SwerveConstants

View File

@ -26,7 +26,7 @@ public:
private:
// Replace with CommandPS4Controller or CommandJoystick if needed
frc2::CommandXboxController m_driverController{
OperatorConstants::kDriverControllerPort};
OperatorConstants::driveControllerPort};
// The robot's subsystems are defined here...
ExampleSubsystem m_subsystem;

View File

@ -5,6 +5,7 @@
#pragma once
#include <ctre/phoenix6/CANcoder.hpp>
#include <frc/controller/PIDController.h>
#include <rev/CANSparkMax.h>
class SwerveModule {
@ -12,6 +13,7 @@ private:
rev::CANSparkMax driveMotor;
rev::CANSparkMax steerMotor;
ctre::phoenix6::hardware::CANcoder encoder;
frc::PIDController pid;
public:
SwerveModule(int driveMotorId, int steerMotorId, int encoderId);