encoder and pid loops
parent
cbd86a7a67
commit
09310a745f
|
@ -2,11 +2,16 @@
|
||||||
// Open Source Software; you can modify and/or share it under the terms of
|
// 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.
|
// the WPILib BSD license file in the root directory of this project.
|
||||||
|
|
||||||
|
#include "Constants.h"
|
||||||
#include "rev/CANSparkMax.h"
|
#include "rev/CANSparkMax.h"
|
||||||
|
|
||||||
#include "cowlib/SwerveModule.h"
|
#include "cowlib/SwerveModule.h"
|
||||||
|
|
||||||
|
using namespace SwerveConstants;
|
||||||
|
|
||||||
|
using MotorType = rev::CANSparkMax::MotorType;
|
||||||
|
|
||||||
SwerveModule::SwerveModule(int driveMotorId, int steerMotorId, int encoderId)
|
SwerveModule::SwerveModule(int driveMotorId, int steerMotorId, int encoderId)
|
||||||
: 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} {}
|
encoder{encoderId}, pid{SwervePID::p, SwervePID::i, SwervePID::d} {}
|
||||||
|
|
|
@ -16,6 +16,18 @@
|
||||||
|
|
||||||
namespace OperatorConstants {
|
namespace OperatorConstants {
|
||||||
|
|
||||||
inline constexpr int kDriverControllerPort = 0;
|
inline constexpr int driveControllerPort = 0;
|
||||||
|
|
||||||
} // namespace OperatorConstants
|
} // 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
|
||||||
|
|
|
@ -26,7 +26,7 @@ public:
|
||||||
private:
|
private:
|
||||||
// Replace with CommandPS4Controller or CommandJoystick if needed
|
// Replace with CommandPS4Controller or CommandJoystick if needed
|
||||||
frc2::CommandXboxController m_driverController{
|
frc2::CommandXboxController m_driverController{
|
||||||
OperatorConstants::kDriverControllerPort};
|
OperatorConstants::driveControllerPort};
|
||||||
|
|
||||||
// The robot's subsystems are defined here...
|
// The robot's subsystems are defined here...
|
||||||
ExampleSubsystem m_subsystem;
|
ExampleSubsystem m_subsystem;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ctre/phoenix6/CANcoder.hpp>
|
#include <ctre/phoenix6/CANcoder.hpp>
|
||||||
|
#include <frc/controller/PIDController.h>
|
||||||
#include <rev/CANSparkMax.h>
|
#include <rev/CANSparkMax.h>
|
||||||
|
|
||||||
class SwerveModule {
|
class SwerveModule {
|
||||||
|
@ -12,6 +13,7 @@ private:
|
||||||
rev::CANSparkMax driveMotor;
|
rev::CANSparkMax driveMotor;
|
||||||
rev::CANSparkMax steerMotor;
|
rev::CANSparkMax steerMotor;
|
||||||
ctre::phoenix6::hardware::CANcoder encoder;
|
ctre::phoenix6::hardware::CANcoder encoder;
|
||||||
|
frc::PIDController pid;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SwerveModule(int driveMotorId, int steerMotorId, int encoderId);
|
SwerveModule(int driveMotorId, int steerMotorId, int encoderId);
|
||||||
|
|
Loading…
Reference in New Issue