7#include <frc/ADIS16448_IMU.h>
9#include <frc/controller/HolonomicDriveController.h>
10#include <frc/kinematics/ChassisSpeeds.h>
11#include <frc/kinematics/SwerveDriveKinematics.h>
12#include <frc/kinematics/SwerveDriveOdometry.h>
13#include <frc/kinematics/SwerveModulePosition.h>
14#include <frc/kinematics/SwerveModuleState.h>
15#include <frc2/command/SubsystemBase.h>
23#include "ctre/Phoenix.h"
24#include "frc/StateSpaceUtil.h"
25#include "frc/estimator/SwerveDrivePoseEstimator.h"
78 void SwerveDrive(
const double fwVelocity,
const double sideVelocity,
const double rotVelocity);
84 void SwerveDrive(
const units::degree_t& velAngle,
const double& velocity,
const double& rotVelocity);
89 void SwerveDrive(
const units::degree_t& velAngle,
const double& velocity);
102 void Home(
const units::degree_t& angle);
110 void FieldHome(units::degree_t homeAngle = 0_deg,
bool updateOdometry =
true);
145 frc::Pose2d
GetPoseEstimate(
const frc::Pose2d& robotPose,
const units::millisecond_t& latency);
330 void HomeToFS(
const units::degree_t& angle);
Subsystem for controlling the swerve drivetrain of the robot.
Definition swerve_drive_subsystem.h:56
void Home(const units::degree_t &angle)
Save homes to persistent storage and updates module motors.
Definition swerve_drive_subsystem.cpp:541
frc::Pose2d GetContinuousOdometry()
Definition swerve_drive_subsystem.cpp:636
void Disable()
Handle the robot disabling.
Definition swerve_drive_subsystem.cpp:220
void HomeToFS(const units::degree_t &angle)
Save homes to a file.
Definition swerve_drive_subsystem.cpp:690
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:594
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:759
SwerveModule m_backRight
Back right swerve module.
Definition swerve_drive_subsystem.h:252
std::unique_ptr< SwerveTrapezoidalSpline > m_pActiveSwerveSplineProfile
Profile to execute.
Definition swerve_drive_subsystem.h:286
frc::HolonomicDriveController m_followerController
Controller to follow drive profile.
Definition swerve_drive_subsystem.h:290
SwerveModule m_frontLeft
Front left swerve module.
Definition swerve_drive_subsystem.h:250
frc::Pose2d UpdateEstimatedPose()
Reads module states & gyro, updates pose estimator, and returns latest pose estimate.
Definition swerve_drive_subsystem.cpp:641
std::chrono::time_point< std::chrono::steady_clock > m_swerveProfileStartTime
Time when active profile began.
Definition swerve_drive_subsystem.h:287
frc2::PIDController m_linearPID
Correction parameters for x/y error when following drive profile.
Definition swerve_drive_subsystem.h:289
DriveControlMode
Enumerator for either field-centric or robot centric drive modes.
Definition swerve_drive_subsystem.h:62
@ robotCentricControl
Definition swerve_drive_subsystem.h:62
@ fieldCentricControl
Definition swerve_drive_subsystem.h:62
bool m_profileComplete
True once a drive profile has been completed.
Definition swerve_drive_subsystem.h:283
void CancelDrivingProfile()
Cancel the current driving profile without marking it complete.
Definition swerve_drive_subsystem.cpp:798
bool m_followingProfile
True when an incomplete drive profile is being run.
Definition swerve_drive_subsystem.h:282
bool IsFollowingProfile() const
Check if drivetrain is following a profile.
Definition swerve_drive_subsystem.cpp:807
units::degree_t m_fieldHomeOffset
Offset from IMU angle to 0 field angle (intake away from driver station)
Definition swerve_drive_subsystem.h:259
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:752
argos_lib::NTSubscriber m_rotationalFollowerConstraintTuner_accel
Definition swerve_drive_subsystem.h:300
void InitializeOdometry(const frc::Pose2d ¤tPose)
Set current robot position. Useful for initializing initial position before autonomous.
Definition swerve_drive_subsystem.cpp:606
void InitializeMotorsFromFS()
Initialize motors from saved file.
Definition swerve_drive_subsystem.cpp:704
frc::Pose2d GetPoseEstimate(const frc::Pose2d &robotPose, const units::millisecond_t &latency)
Get the latest pose estimate.
Definition swerve_drive_subsystem.cpp:655
void StartDrivingProfile(SwerveTrapezoidalProfileSegment newProfile)
Start driving a new profile. This also resets the finished flag.
Definition swerve_drive_subsystem.cpp:777
frc::SwerveDriveKinematics< 4 > m_swerveDriveKinematics
Kinematics model for swerve drive system.
Definition swerve_drive_subsystem.h:271
SwerveModule m_backLeft
Back left swerve module.
Definition swerve_drive_subsystem.h:253
DriveControlMode m_controlMode
Active control mode.
Definition swerve_drive_subsystem.h:248
wpi::array< frc::SwerveModulePosition, 4 > GetCurrentModulePositions()
Get the active positions of all swerve modules.
Definition swerve_drive_subsystem.cpp:274
void SetControlMode(SwerveDriveSubsystem::DriveControlMode controlMode)
Definition swerve_drive_subsystem.cpp:682
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:228
argos_lib::NTSubscriber m_linearFollowerTuner_P
Definition swerve_drive_subsystem.h:293
units::degree_t GetIMUYaw() const
Definition swerve_drive_subsystem.cpp:811
argos_lib::NTSubscriber m_linearFollowerTuner_D
Definition swerve_drive_subsystem.h:295
argos_lib::NTMotorPIDTuner m_driveMotorPIDTuner
Utility to tune drive motors.
Definition swerve_drive_subsystem.h:292
wpi::array< frc::SwerveModuleState, 4 > GetCurrentModuleStates()
Get the active states of all swerve modules.
Definition swerve_drive_subsystem.cpp:270
bool ProfileIsComplete() const
Check if a driving profile path has been completed.
Definition swerve_drive_subsystem.cpp:803
void SwerveDrive(const double fwVelocity, const double sideVelocity, const double rotVelocity)
Main drive function for the robot.
Definition swerve_drive_subsystem.cpp:278
void InitializeMotors()
Initialize motors from persistent storage.
Definition swerve_drive_subsystem.cpp:686
frc::ADIS16448_IMU m_imu
Definition swerve_drive_subsystem.h:256
units::degrees_per_second_t GetRobotPitchRate()
Get the rate of robot pitch.
Definition swerve_drive_subsystem.cpp:554
frc::ChassisSpeeds GetChassisVelocity()
Get the robot velocity in chassis frame (x toward intake, y toward left) based on GetCurrentModuleSta...
Definition swerve_drive_subsystem.cpp:819
argos_lib::NTSubscriber m_rotationalFollowerConstraintTuner_vel
Definition swerve_drive_subsystem.h:299
units::degree_t GetRobotPitch() const
Get the robot pitch as determined by the pigeon IMU.
Definition swerve_drive_subsystem.h:236
frc::ProfiledPIDController< units::radians >::Constraints m_rotationalPIDConstraints
Definition swerve_drive_subsystem.h:288
void LockWheels()
Put the robot wheels in an x shape where it locks the movement of it.
Definition swerve_drive_subsystem.cpp:560
void UpdateFollowerRotationalPIDConstraints(frc::TrapezoidProfile< units::radians >::Constraints constraints)
Update constraints to rotate robot along profiled path.
Definition swerve_drive_subsystem.cpp:764
argos_lib::NTSubscriber m_rotationalFollowerTuner_I
Definition swerve_drive_subsystem.h:297
std::unique_ptr< SwerveTrapezoidalProfileSegment > m_pActiveSwerveProfile
Profile to execute.
Definition swerve_drive_subsystem.h:285
void StopDrive()
Stop all motors.
Definition swerve_drive_subsystem.cpp:530
SwerveModule m_frontRight
Front right swerve module.
Definition swerve_drive_subsystem.h:251
Pigeon2 m_pigeonIMU
Definition swerve_drive_subsystem.h:257
frc::Rotation2d GetNearestSquareAngle()
Definition swerve_drive_subsystem.cpp:631
frc::SwerveDriveOdometry< 4 > m_odometry
Odometry to track robot.
Definition swerve_drive_subsystem.h:273
bool m_manualOverride
Definition swerve_drive_subsystem.h:284
argos_lib::NTSubscriber m_rotationalFollowerTuner_P
Definition swerve_drive_subsystem.h:296
frc::Rotation2d GetContinuousOdometryAngle()
Definition swerve_drive_subsystem.cpp:614
units::degree_t m_continuousOdometryOffset
Offset to convert [-180,180] odometry angle to continuous angle.
Definition swerve_drive_subsystem.h:275
void ResetIMUYaw()
Definition swerve_drive_subsystem.cpp:815
argos_lib::SwerveFSHomingStorage m_fsStorage
Roborio filesystem access for homes.
Definition swerve_drive_subsystem.h:280
argos_lib::NTSubscriber m_linearFollowerTuner_I
Definition swerve_drive_subsystem.h:294
bool GetManualOverride()
Definition swerve_drive_subsystem.cpp:590
argos_lib::NTSubscriber m_rotationalFollowerTuner_D
Definition swerve_drive_subsystem.h:298
frc::SwerveDrivePoseEstimator< 4 > m_poseEstimator
accounts vision-based measurements for odometry
Definition swerve_drive_subsystem.h:277
units::degree_t m_prevOdometryAngle
Last odometry angle used for continuous calculations.
Definition swerve_drive_subsystem.h:274
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:651
argos_lib::RobotInstance m_instance
Definition swerve_drive_subsystem.h:246
Definition swerve_drive_subsystem.h:29
frc::SwerveModuleState GetState()
Definition swerve_drive_subsystem.cpp:740
WPI_TalonFX m_drive
Definition swerve_drive_subsystem.h:32
CANCoder m_encoder
Definition swerve_drive_subsystem.h:35
WPI_TalonFX m_turn
Definition swerve_drive_subsystem.h:33
frc::SwerveModulePosition GetPosition()
Definition swerve_drive_subsystem.cpp:746
Definition swerve_trapezoidal_profile.h:18
Definition swerve_trapezoidal_spline.h:19
Allows user to set PID parameters from network tables and update the motor configurations on updates....
Definition nt_motor_pid_tuner.h:48
Subscribes to Network Tables entry updates and calls a specified callback to use the new value.
Definition nt_subscriber.h:17
Definition fs_homing.h:17
RobotInstance
Differentiates between practice robot and competition robot.
Definition config_types.h:13
A struct for holding the 3 different input velocities, for organization.
Definition swerve_drive_subsystem.h:265
const double sideVelocity
Definition swerve_drive_subsystem.h:267
const double rotVelocity
Definition swerve_drive_subsystem.h:268
const double fwVelocity
Definition swerve_drive_subsystem.h:266
Definition config_types.h:25