7#include <frc/ADIS16448_IMU.h>
8#include <frc/controller/HolonomicDriveController.h>
9#include <frc/kinematics/ChassisSpeeds.h>
10#include <frc/kinematics/SwerveDriveKinematics.h>
11#include <frc/kinematics/SwerveDriveOdometry.h>
12#include <frc/kinematics/SwerveModuleState.h>
13#include <frc2/command/SubsystemBase.h>
19#include "ctre/Phoenix.h"
73 void SwerveDrive(
const double& fwVelocity,
const double& sideVelocity,
const double& rotVelocity);
86 void Home(
const units::degree_t& angle);
94 void FieldHome(units::degree_t homeAngle = 0_deg,
bool updateOdometry =
true);
234 frc::ProfiledPIDController<units::radians>
261 void HomeToFS(
const units::degree_t& angle);
Accesses swerve module home positions in a file saved on the RoboRIO.
Definition: file_system_homing_storage.h:13
Subsystem for controlling the swerve drivetrain of the robot.
Definition: swerve_drive_subsystem.h:50
void Home(const units::degree_t &angle)
Save homes to persistent storage and updates module motors.
Definition: swerve_drive_subsystem.cpp:419
frc::Pose2d GetContinuousOdometry()
Definition: swerve_drive_subsystem.cpp:464
frc::Pose2d GetPoseEstimate()
Get the latest pose estimate.
Definition: swerve_drive_subsystem.cpp:487
void Disable()
Handle the robot disabling.
Definition: swerve_drive_subsystem.cpp:158
void HomeToFS(const units::degree_t &angle)
Save homes to a file.
Definition: swerve_drive_subsystem.cpp:499
void FieldHome(units::degree_t homeAngle=0_deg, bool updateOdometry=true)
Tell the robot it's in it's correct field-oriented "Front".
Definition: swerve_drive_subsystem.cpp:432
void UpdateFollowerRotationalPIDParams(double kP, double kI, double kD)
Change PID parameters for rotational follower. These adjust velocities based on angle error from path...
Definition: swerve_drive_subsystem.cpp:560
SwerveModule m_backRight
Back right swerve module.
Definition: swerve_drive_subsystem.h:198
frc::HolonomicDriveController m_followerController
Controller to follow drive profile.
Definition: swerve_drive_subsystem.h:236
SwerveModule m_frontLeft
Front left swerve module.
Definition: swerve_drive_subsystem.h:196
void SwerveDrive(const double &fwVelocity, const double &sideVelocity, const double &rotVelocity)
Main drive function for the robot.
Definition: swerve_drive_subsystem.cpp:213
std::chrono::time_point< std::chrono::steady_clock > m_swerveProfileStartTime
Time when active profile began.
Definition: swerve_drive_subsystem.h:232
frc2::PIDController m_linearPID
Correction parameters for x/y error when following drive profile.
Definition: swerve_drive_subsystem.h:233
DriveControlMode
Enumerator for either field-centric or robot centric drive modes.
Definition: swerve_drive_subsystem.h:56
@ robotCentricControl
Definition: swerve_drive_subsystem.h:56
@ fieldCentricControl
Definition: swerve_drive_subsystem.h:56
bool m_profileComplete
True once a drive profile has been completed.
Definition: swerve_drive_subsystem.h:230
void CancelDrivingProfile()
Cancel the current driving profile without marking it complete.
Definition: swerve_drive_subsystem.cpp:580
bool m_followingProfile
True when an incomplete drive profile is being run.
Definition: swerve_drive_subsystem.h:229
void UpdateFollowerRotationalPIDConstraints(frc::TrapezoidProfile< units::degrees >::Constraints constraints)
Update constraints to rotate robot along profiled path.
Definition: swerve_drive_subsystem.cpp:565
FileSystemHomingStorage m_fsStorage
Roborio filesystem access for homes.
Definition: swerve_drive_subsystem.h:227
units::degree_t m_fieldHomeOffset
Offset from IMU angle to 0 field angle (intake away from driver station)
Definition: swerve_drive_subsystem.h:205
frc::Pose2d UpdateOdometry()
Reads module states & gyro, updates odometry, and returns latest pose estimate.
Definition: swerve_drive_subsystem.cpp:469
void UpdateFollowerLinearPIDParams(double kP, double kI, double kD)
Change PID parameters for linear follower. These adjust velocities based on distance error from path ...
Definition: swerve_drive_subsystem.cpp:555
void InitializeOdometry(const frc::Pose2d ¤tPose)
Set current robot position. Useful for initializing initial position before autonomous.
Definition: swerve_drive_subsystem.cpp:443
void InitializeMotorsFromFS()
Initialize motors from saved file.
Definition: swerve_drive_subsystem.cpp:513
void StartDrivingProfile(SwerveTrapezoidalProfileSegment newProfile)
Start driving a new profile. This also resets the finished flag.
Definition: swerve_drive_subsystem.cpp:572
frc::SwerveDriveKinematics< 4 > m_swerveDriveKinematics
Kinematics model for swerve drive system.
Definition: swerve_drive_subsystem.h:217
SwerveModule m_backLeft
Back left swerve module.
Definition: swerve_drive_subsystem.h:199
DriveControlMode m_controlMode
Active control mode.
Definition: swerve_drive_subsystem.h:194
frc::ProfiledPIDController< units::radians > m_rotationalPID
Correction parameters for rotational error when following drive profile.
Definition: swerve_drive_subsystem.h:235
void SetControlMode(SwerveDriveSubsystem::DriveControlMode controlMode)
Definition: swerve_drive_subsystem.cpp:491
wpi::array< frc::SwerveModuleState, 4 > GetRawModuleStates(SwerveDriveSubsystem::Velocities velocities)
Get the Raw Module States object and switch between robot-centric and field-centric.
Definition: swerve_drive_subsystem.cpp:167
units::degree_t GetIMUYaw() const
Definition: swerve_drive_subsystem.cpp:589
argos_lib::NTMotorPIDTuner m_driveMotorPIDTuner
Utility to tune drive motors.
Definition: swerve_drive_subsystem.h:238
wpi::array< frc::SwerveModuleState, 4 > GetCurrentModuleStates()
Get the active states of all swerve modules.
Definition: swerve_drive_subsystem.cpp:209
bool ProfileIsComplete() const
Check if a driving profile path has been completed.
Definition: swerve_drive_subsystem.cpp:585
void InitializeMotors()
Initialize motors from persistent storage.
Definition: swerve_drive_subsystem.cpp:495
frc::ADIS16448_IMU m_imu
Definition: swerve_drive_subsystem.h:202
frc::ChassisSpeeds GetChassisVelocity()
Get the robot velocity in chassis frame (x toward intake, y toward left) based on GetCurrentModuleSta...
Definition: swerve_drive_subsystem.cpp:597
std::shared_ptr< NetworkTablesWrapper > m_pNetworkTable
Instance of network table class.
Definition: swerve_drive_subsystem.h:224
std::unique_ptr< SwerveTrapezoidalProfileSegment > m_pActiveSwerveProfile
Profile to execute.
Definition: swerve_drive_subsystem.h:231
void StopDrive()
Stop all motors.
Definition: swerve_drive_subsystem.cpp:408
SwerveModule m_frontRight
Front right swerve module.
Definition: swerve_drive_subsystem.h:197
Pigeon2 m_pigeonIMU
Definition: swerve_drive_subsystem.h:203
frc::SwerveDriveOdometry< 4 > m_odometry
Odometry to track robot.
Definition: swerve_drive_subsystem.h:219
frc::Rotation2d GetContinuousOdometryAngle()
Definition: swerve_drive_subsystem.cpp:451
units::degree_t m_continuousOdometryOffset
Offset to convert [-180,180] odometry angle to continuous angle.
Definition: swerve_drive_subsystem.h:221
void ResetIMUYaw()
Definition: swerve_drive_subsystem.cpp:593
units::degree_t m_prevOdometryAngle
Last odometry angle used for continuous calculations.
Definition: swerve_drive_subsystem.h:220
units::degree_t GetFieldCentricAngle() const
Get the field-centric angle of the robot based on gyro and saved reference orientation.
Definition: swerve_drive_subsystem.cpp:483
argos_lib::RobotInstance m_instance
Definition: swerve_drive_subsystem.h:192
Definition: swerve_drive_subsystem.h:24
frc::SwerveModuleState GetState()
Definition: swerve_drive_subsystem.cpp:549
WPI_TalonFX m_drive
Definition: swerve_drive_subsystem.h:27
CANCoder m_encoder
Definition: swerve_drive_subsystem.h:30
WPI_TalonFX m_turn
Definition: swerve_drive_subsystem.h:28
Definition: swerve_trapezoidal_profile.h:18
Allows user to set PID parameters from network tables and update the motor configurations on updates....
Definition: nt_motor_pid_tuner.h:48
RobotInstance
Differentiates between practice robot and competition robot.
Definition: config_types.h:13
Definition: constraints.h:16
A struct for holding the 3 different input velocities, for organization.
Definition: swerve_drive_subsystem.h:211
const double sideVelocity
Definition: swerve_drive_subsystem.h:213
const double rotVelocity
Definition: swerve_drive_subsystem.h:214
const double fwVelocity
Definition: swerve_drive_subsystem.h:212
Definition: config_types.h:25