![]() |
FRC Paradigm Shift #1259
Documentation for the 2021 Robot
|
Public Member Functions | |
SwerveModule (int driveMotorChannel, int turningMotorChannel, GetPulseWidthCallback pulseWidthCallback, CANifier::PWMChannel pwmChannel, bool driveEncoderReversed, double offSet, const string &name) | |
void | Periodic () |
SwerveModuleState | GetState () |
void | SetDesiredState (SwerveModuleState &state) |
void | ResetEncoders () |
Resets the drive motor encoders to 0. More... | |
void | ResetRelativeToAbsolute () |
Resync the relative NEO turn encoder to the absolute encoder. More... | |
Private Types | |
using | radians_per_second_squared_t = compound_unit< radians, inverse< squared< second >>> |
Private Member Functions | |
double | CalcAbsoluteAngle () |
Calculate the absolute angle, in radians, based on the pulse widths from m_pulseWidthCallback. More... | |
double | MinTurnRads (double init, double final, bool &bOutputReverse) |
meters_per_second_t | CalcMetersPerSec () |
double | CalcTicksPer100Ms (meters_per_second_t speed) |
Private Attributes | |
double | m_offset |
The offset, in pulse widths, for syncing the relative encoder to the absolute encoder. More... | |
string | m_name |
String used to identify each pod, used for SmartDashboard prints. More... | |
TalonFX | m_driveMotor |
Falon 500 that drives the pod. More... | |
PIDLoaderFalcon | m_drivePIDLoader |
PID param loader for the TalonFX. More... | |
PIDLoaderNEO | m_turnPIDLoader |
PID param loader for the CANSparkMax. More... | |
GetPulseWidthCallback | m_pulseWidthCallback |
CANifier::PWMChannel | m_pwmChannel |
Timer | m_timer |
Timer used to sync absolute and relative encoders on robot turn on. More... | |
NEO that turns the pod, controls angle with relative encoder and PID | |
CANSparkMax | m_turningMotor |
CANEncoder | m_turnRelativeEncoder |
CANPIDController | m_turnPIDController = m_turningMotor.GetPIDController() |
Definition at line 51 of file SwerveModule.h.
|
private |
Definition at line 53 of file SwerveModule.h.
SwerveModule::SwerveModule | ( | int | driveMotorChannel, |
int | turningMotorChannel, | ||
GetPulseWidthCallback | pulseWidthCallback, | ||
CANifier::PWMChannel | pwmChannel, | ||
bool | driveEncoderReversed, | ||
double | offSet, | ||
const string & | name | ||
) |
Definition at line 11 of file SwerveModule.cpp.
References ModuleConstants::kMotorCurrentLimit, ModuleConstants::kTurnMotorRevsPerWheelRev, PIDLoaderFalcon::Load(), PIDLoaderNEO::Load(), m_driveMotor, m_drivePIDLoader, m_timer, m_turningMotor, m_turnPIDController, m_turnPIDLoader, and m_turnRelativeEncoder.
void SwerveModule::Periodic | ( | ) |
Definition at line 51 of file SwerveModule.cpp.
References CalcAbsoluteAngle(), m_name, m_timer, m_turnRelativeEncoder, and ResetRelativeToAbsolute().
SwerveModuleState SwerveModule::GetState | ( | ) |
Get the state for the swerve module pod
Why do we find the absolute angle here instead of the relative angle?
Definition at line 65 of file SwerveModule.cpp.
References CalcAbsoluteAngle(), and CalcMetersPerSec().
void SwerveModule::SetDesiredState | ( | SwerveModuleState & | state | ) |
Set the desired state for the swerve module pod
state | The state (vector with speed and angle) representing the desired module state |
Definition at line 71 of file SwerveModule.cpp.
References CalcTicksPer100Ms(), PIDLoaderFalcon::LoadFromNetworkTable(), PIDLoaderNEO::LoadFromNetworkTable(), m_driveMotor, m_drivePIDLoader, m_turnPIDController, m_turnPIDLoader, m_turnRelativeEncoder, and MinTurnRads().
void SwerveModule::ResetEncoders | ( | ) |
Resets the drive motor encoders to 0.
Definition at line 108 of file SwerveModule.cpp.
References m_driveMotor.
void SwerveModule::ResetRelativeToAbsolute | ( | ) |
Resync the relative NEO turn encoder to the absolute encoder.
Definition at line 123 of file SwerveModule.cpp.
References CalcAbsoluteAngle(), and m_turnRelativeEncoder.
|
private |
Calculate the absolute angle, in radians, based on the pulse widths from m_pulseWidthCallback.
Definition at line 113 of file SwerveModule.cpp.
References DriveConstants::kPulseWidthToRadians, m_offset, m_pulseWidthCallback, and m_pwmChannel.
|
private |
Determine the smallest magnitude delta angle that can be added to initial angle that will result in an angle equivalent (but not necessarily equal) to final angle. All angles in radians Currently final - init difference is always chosen regardless of angle
Definition at line 133 of file SwerveModule.cpp.
References Util::NegPiToPiRads(), and Util::ZeroTo2PiRads().
|
private |
Calculate the MPS of the drive motor based on its current encoder tick velocity
Definition at line 162 of file SwerveModule.cpp.
References ModuleConstants::kDriveEncoderMetersPerSec, and m_driveMotor.
|
private |
Calculate drive motor encoder ticks based on the MPS
speed | Meters per second |
Definition at line 168 of file SwerveModule.cpp.
References ModuleConstants::kDriveEncoderMetersPerSec.
|
private |
The offset, in pulse widths, for syncing the relative encoder to the absolute encoder.
Definition at line 96 of file SwerveModule.h.
|
private |
String used to identify each pod, used for SmartDashboard prints.
Definition at line 98 of file SwerveModule.h.
|
private |
Falon 500 that drives the pod.
Definition at line 101 of file SwerveModule.h.
|
private |
Definition at line 104 of file SwerveModule.h.
|
private |
Definition at line 105 of file SwerveModule.h.
|
private |
Definition at line 107 of file SwerveModule.h.
|
private |
PID param loader for the TalonFX.
Definition at line 111 of file SwerveModule.h.
|
private |
PID param loader for the CANSparkMax.
Definition at line 113 of file SwerveModule.h.
|
private |
Callback used to determine the pulse width
pwmChannel | Channel to decide which absolute encoder's pulse width values are retrieved |
Definition at line 117 of file SwerveModule.h.
|
private |
Definition at line 118 of file SwerveModule.h.
|
private |
Timer used to sync absolute and relative encoders on robot turn on.
Definition at line 121 of file SwerveModule.h.