Gray Matter
WorkshopSwerve Basics
Rough draft: nobody has reviewed this lesson yet, and it may not be how things are done this season.
LESSON 18

Swerve Basics

A swerve drive can slide sideways, drive diagonally and spin, all at the same time. This page names its parts and the terms the next pages use.

6 minutes
You’ll need
  • The words CAN bus, CANcoder and CANivore, from Hardware Setup.
  • A swerve robot to look at, for the check at the end.

Components

A swerve drive has a module at each corner: front left, front right, back left and back right, named from behind the robot. Every module can point its wheel in any direction, so the robot can travel one way while facing another.

A swerve module with its two motors on top
Four

Swerve module

Two Kraken motors and a CANcoder. The drive motor spins the wheel, the steer motor points it, and the CANcoder reads which way it points.

CTRE Pigeon 2.0 IMU
One

Pigeon 2

A gyro. It reports which way the robot is facing, which field-centric driving needs.

CANivore USB to CAN FD adapter
One

CANivore

Carries every swerve device on one CAN FD bus, the same part you used on the bench.

That is thirteen devices: eight motors, four CANcoders and one Pigeon 2. You never write the math that turns "drive left while turning" into eight motor commands. Tuner X generates it on the next page.

Basic terms

Robot-centric
Forward is wherever the robot's front points. Turn the robot around and every stick input is mirrored.
Field-centric
Forward is down the field, away from your driver station, no matter which way the robot faces. It needs the Pigeon 2 to know the heading.
Translation2d
A spot on the field: X and Y in meters. new Translation2d(2.0, 6.5) is 2 m down the field and 6.5 m across it.
Rotation2d
A heading, the way the robot's front points. Rotation2d.fromDegrees(90) faces +Y.
Pose2d
A Translation2d and a Rotation2d together: where the robot is and which way it faces. new Pose2d(new Translation2d(2.0, 6.5), Rotation2d.fromDegrees(90)) is that spot, facing +Y.
Odometry
How the robot keeps track of its Pose2d. Every loop it adds up how far each wheel turned. It never checks the field, so slip and bumps make it drift.
+X+Y(0, 0)(8.27, 4.04)(2, 6.5)(14.5, 1.5)
Every pose is measured in meters from the blue corner, on both alliances.

X runs down the length of the field, away from the blue driver station. Y runs across it, to the left. A heading of 0° faces along +X. The frame does not flip on red: a red robot at its own wall reports a large X.

Check your work

Power off. Stand behind a swerve robot with its front pointing away from you.

  1. Name the four corners: front left, front right, back left, back right.
  2. On one module, find the drive motor, the steer motor and the CANcoder.
  3. Find the Pigeon 2 and the CANivore. Count the devices on the bus.
Check

You should see

Thirteen devices: eight motors, four CANcoders and one Pigeon 2.

Check yourself

You are driving field-centric. The robot's front points at you. You push the left stick away from yourself. What does the robot do?

What does field-centric driving need that robot-centric does not?

What does a Pose2d hold?

Why does odometry drift over a match?

Pick an answer for each.