For the complete documentation index, see llms.txt. This page is also available as Markdown.

Gyroscopes

Supported gyroscope/IMU types for swervedrive.json's gyro field

Gyroscope Checklist

Configuring the gyro

In swervedrive.json the gyro is one object plus two drive-wide settings:

{
  "gyro": {
    "type": "pigeon2_can",
    "id": 13,
    "canbus": "canivore"
  },
  "gyroAxis": "yaw",
  "gyroInvert": true,
  "modules": ["frontleft.json", "frontright.json", "backleft.json", "backright.json"]
}
  • gyro.type — one of the supported types below, formatted vendor_connection, or custom to configure the gyro yourself (see Custom Gyro).

  • gyro.id — CAN ID of the device (ignored where not applicable).

  • gyro.canbus — CAN bus name. Use "" for your control system's default bus (rio on a roboRIO), or a CANivore name if the device is on one — see Control system and CAN buses.

  • gyroAxis — which physical axis of the sensor to read as robot heading: yaw (default), pitch, or roll. Only change this if the sensor is mounted on an edge or angle.

  • gyroInvert — invert the heading reading. If your robot spins out of control with no controller input, invert this.

Supported gyroscope types

Device

type

Communication

pigeon2_can

CAN; supports CANivore

canandgyro_can

CAN; default bus only, no CANivore

navx3_can

CAN 2.0 / CAN FD

SystemCore internal IMU

systemcore_internal

listed in the config schema but not yet implemented — the parser throws if selected. Do not use yet.

custom

any — you construct and supply the gyro yourself

If you need a gyro not on this list — including the older roboRIO SPI/I2C/USB-serial NavX (AHRS) devices called out in the hint above, which the CAN-only parser no longer builds — use the custom type below.

Custom Gyro

This is the reference summary — for a full walkthrough see How to use a custom gyro.

Set gyro.type to custom and YAGSL's parser skips gyro configuration entirely: it never calls SwerveDriveConfig.withGyro()/withGyroInverted(), and gyroAxis/gyroInvert in swervedrive.json are ignored. You're expected to call withGyro()/withGyroInverted() yourself on the SwerveDriveConfig you pass into SwerveParser.createSwerveDrive(...) — everything else in the config (modules, motor controllers, encoders) is still built normally from the JSON.

This is the escape hatch for any gyro the parser doesn't build for you — most commonly the roboRIO SPI-mounted Studica AHRS (the classic NavX2), since only the CAN-based NavX3 is supported directly.

NavX3-CAN supports CAN 2.0 and has CAN-FD capability. See Studica's notes for CAN-FD requirements.

Checklist

NavX3-CAN ships factory-calibrated. For higher accuracy, re-calibrate with Studica Hardware Manager — it auto-detects sensor orientation during calibration. Connect CAN-H/CAN-L to the robot bus and make sure the bus is properly terminated.

Pigeon 2

Checklist

Communicates over CAN and can be paired with a CANivore to keep it off your control system's default CAN bus — set a CANivore name and use it as canbus.

Canandgyro


General gyro tips (still apply regardless of device)

  • Mount the gyro as close to the robot's center of rotation as practical — off-center mounting couples translational vibration into the heading reading.

  • Always keep the robot still for a few seconds after power-on if your device does an on-the-fly calibration; moving during that window produces a bad heading for the rest of the match.

  • If the robot's heading drifts over a match, see Swerve Drive Drift Causes.

Last updated

Was this helpful?