positions and rotations?

main
Zynh Ludwig 2024-03-28 02:32:31 -07:00
parent c546e69ca7
commit dc0f99ad48
2 changed files with 15 additions and 0 deletions

View File

@ -4,6 +4,7 @@
#include "Constants.h"
#include "frc/geometry/Rotation2d.h"
#include "frc/kinematics/SwerveModulePosition.h"
#include "frc/kinematics/SwerveModuleState.h"
#include "rev/CANSparkMax.h"
#include "units/angle.h"
@ -48,3 +49,13 @@ void SwerveModule::drive(frc::SwerveModuleState state) {
units::turn_t SwerveModule::GetEncoder() {
return this->encoder.GetAbsolutePosition().GetValue();
}
frc::Rotation2d SwerveModule::GetRotation() {
return frc::Rotation2d(this->GetEncoder());
}
frc::SwerveModulePosition SwerveModule::GetPosition() {
return frc::SwerveModulePosition(
units::meter_t(this->driveMotor.GetEncoder().GetPosition()),
this->GetRotation());
}

View File

@ -4,9 +4,11 @@
#pragma once
#include "frc/geometry/Rotation2d.h"
#include "units/angle.h"
#include <ctre/phoenix6/CANcoder.hpp>
#include <frc/controller/PIDController.h>
#include <frc/kinematics/SwerveModulePosition.h>
#include <frc/kinematics/SwerveModuleState.h>
#include <rev/CANSparkMax.h>
@ -26,4 +28,6 @@ public:
void drive(double speedMetersPerSecond, double angle);
void drive(frc::SwerveModuleState state);
units::turn_t GetEncoder();
frc::Rotation2d GetRotation();
frc::SwerveModulePosition GetPosition();
};