YAGSL
  • Welcome to Yet Another Swerve Document
    • Resources
  • Overview
    • What we do
    • Our Features
      • Telemetry
      • Simulation
      • Lock Pose
      • Max Speed
      • Chassis Speed Discretization
      • Vision Odometry
      • Heading Correction
      • Auto-centering Modules
      • Offset Offloading
      • Cosine Compensation
      • Module Auto-synchronization
      • Angular Velocity Compensation
    • Changelog
    • Java API
    • Example Code
    • Config Generator
    • 💸Donations
    • 👕Merch
    • Discord
  • Fundamentals
    • Swerve Drive
    • Swerve Modules
  • Bringing up swerve
    • Preface
    • Swerve Information
    • Check your gyroscope
    • Check your motors
    • Creating your first configuration
  • Configuring YAGSL
    • Getting to know your robot
      • Gear Ratio
    • Dependency Installation
    • Configuration
      • Swerve Drive Configuration
      • Physical Properties Configuration
      • PIDF Properties Configuration
        • PIDF
      • Swerve Module Configuration
      • Controller Properties Configuration
      • Device Configuration
    • Code Setup
    • Standard Conversion Factors
    • How to tune PIDF
    • When to invert?
    • Flowcharts
    • The eight steps
    • Swerve Drive Drift
    • SparkMAX Common Problems
    • Verifying your Module Locations
    • Tuning out Drift
  • Devices
    • Gyroscope
      • NavX
      • Pigeon
      • Pigeon 2.0
      • ADXRS450
      • ADIS16448
      • ADIS16470
    • Motor Controllers
      • SparkMAX
      • SparkFlex
      • TalonFX
    • Absolute Encoders
  • Analytics and Debugging
    • FRC Web Components
    • Advantage Scope
  • Product Guides
    • Java API
    • PathPlanner
    • ❌Tuning PID with REV Hardware Client
    • ❌Drive Code
  • Legacy Documentation
Powered by GitBook
On this page
  • Gyroscope Checklist
  • Swerve IMU wrapper
  • Recommended Gyroscopes
  • NavX2 MXP by Studica
  • Pigeon2 IMU by CTRE
  • Gyroscope Configuration
  • Possible Gyroscope Types

Was this helpful?

Edit on GitHub
  1. Devices

Gyroscope

PreviousTuning out DriftNextNavX

Last updated 4 months ago

Was this helpful?

YAGSL supports a wide variety of Gyroscopes in an effort to best help teams of all budgets, while we do recommend the NavX or Pigeon2 and officially support and have tested them, we do try to support others with varying degrees of success.

Gyroscope Checklist

Swerve IMU wrapper

YAGSL creates wrappers over all supported Gyroscope types to uniformly fetch and set data that is needed for a Swerve Drive to operate, this wrapper is called . All Gyroscope's can be fetched from the object via the object which is generated from the swervedrive.json file given. For a user program to fetch the raw gyroscope object all you must do is as follows while casting the object to the right type, in our case this will be a NavX AHRS class.

   /**
   * Initialize {@link SwerveDrive} with the directory provided.
   *
   * @param directory Directory of swerve drive config files.
   */
  public SwerveSubsystem(File directory)
  {
    // Angle conversion factor is 360 / (GEAR RATIO * ENCODER RESOLUTION)
    //  In this case the gear ratio is 12.8 motor revolutions per wheel rotation.
    //  The encoder resolution per motor revolution is 1 per motor revolution.
    double angleConversionFactor = SwerveMath.calculateDegreesPerSteeringRotation(12.8, 1);
    // Motor conversion factor is (PI * WHEEL DIAMETER IN METERS) / (GEAR RATIO * ENCODER RESOLUTION).
    //  In this case the wheel diameter is 4 inches, which must be converted to meters to get meters/second.
    //  The gear ratio is 6.75 motor revolutions per wheel rotation.
    //  The encoder resolution per motor revolution is 1 per motor revolution.
    double driveConversionFactor = SwerveMath.calculateMetersPerRotation(Units.inchesToMeters(4), 6.75, 1);

    // Configure the Telemetry before creating the SwerveDrive to avoid unnecessary objects being created.
    SwerveDriveTelemetry.verbosity = TelemetryVerbosity.HIGH;
    try
    {
      swerveDrive = new SwerveParser(directory).createSwerveDrive(maximumSpeed, angleConversionFactor, driveConversionFactor);
    } catch (Exception e)
    {
      throw new RuntimeException(e);
    }
    swerveDrive.setHeadingCorrection(false); // Heading correction should only be used while controlling the robot via angle.

     navx = ()swerveDrive.getGyro().getIMU();

  }

Recommended Gyroscopes

These gyroscopes have been thoroughly tested and are used by many FRC teams. Generally speaking these will give you the best performance and reliability as well as help from the community at large.

Gyroscope Configuration

Only CTRE devices currently support the canbus option, if your device is using the roboRIO canbus you must use the value of null or "rio" for supported CTRE devices. If you are using a CANivore, and the device is on the CANivore bus, the name must match the CANivore name.

In swervedrive.json you specify the gyroscope with the

{
  "imu": {
    "type": "",
    : ,
    : ""
  },
  "invertedIMU": true,
  "modules": [
    "frontleft.json",
    "frontright.json",
    "backleft.json",
    "backright.json"
  ]
}

If your robot spins out of control without any controller input you probably need to invert your IMU here.

Possible Gyroscope Types

Device
type
Communication

pigeon

CAN; does not support CANivore.

pigeon2

CAN; supports CANivore

canandgyro

CAN; does not support CANivore.

navx , navx_spi

roboRIO MXP SPI

navx_i2c

I2C port on the roboRIO MXP. Not recommended!

navx_usb

Serial over USB Cable to roboRIO (not recommended)

navx_mxp_serial

Serial over roboRIO MXP

adis16448

roboRIO MXP

adis16470

roboRIO SPI port

adxrs450

roboRIO SPI port.

Analog Gyro

analog

AnalogInput

by Studica

by CTRE

SwerveIMU
SwerveDrive
SwerveDriveConfiguration
NavX2 MXP
Pigeon2 IMU
Pigeon
Pigeon2
Canandgyro
NavX
NavX
NavX
NavX
ADIS16448
ADIS16470
ADXRS450
navX2-MXP Robotics Navigation SensorStudica Limited
Logo
Pigeon 2.0CTR Electronics
Logo