This lesson is still work in progress - more will be added to it soon

Lesson 6 - Swerve Drive Integration


Intro to Swerve Drive

Swerve drive is a type of drive train that utilises 8 motors and an AHRS (Attitude and Heading Reference System) to allow the robot to freely move in 2 dimensional space

Each wheel consists of two motors one for rotation and the other for drive

Achieving the harmony between all 8 motors required for swerve drive to work properly is no easy task

Thankfully, FIRST does most of the heavy lifting for us and provides access to helper classes that take care of the tricky parts of swerve like odometry and kinematics

Most of the actual work we do on swerve drive consists of tuning PID loops which you can go to (insert pid loop lesson here) to learn about and updating it when new firmware is released

This lesson is meant to acclamate you to the software of Swerve Drive in the unlikely case you end up working on it


Basics of swerve drive

Each swerve drive module is stored inside the array titled m_swerveModules

When a TeleopSwerve Command is submitted the inputs are first proccesed depending on the operator mode

Next, a chassis speed object is created which wraps the inputs in a format that the Swerve Drive Kinematics class can read

This chassis object is then sent to the set chassis speed method which sends the chassis speed object to a swerve kinematics instance to be turned into a swerve state

These states go through one last check to ensure they do not go over the max speed the robot can handle before finally being applied to each swerve module


Field relative vs Field absolute

Swerve Drive is cool and all but it's main usefulness comes from it's ability to perform field absolute control

Field absolute means that no matter the robots pose it will always move in the same direction absolute to the operator

This controll style allows for the agility and ease of use that swerve drive is known for and is the primary reason for choosing it over another drive train style

To acheive this effect the Swerve Drive class utilises the swerve drive odometry class and AHRS to interpret translation2D objects fed in by the Xbox Controller

It then compares this against the field absolute speed of the robot to convert it into a chassis speed before following the same pipeline stated in the previous section