Swerve Misalignment / Drift

Hi all,

My team is currently trying to get Swerve working through YAGSL. We are continuously experiencing encoder drift and wheel misalignment.

When we try to correct for alignment on a wheel, other wheels misalign.

We are using MK4i Swerve with CTR Cancoders, SparkMax motor controllers and Neo Brushless. Navx IMU connected through MXP. No CANivore.

If anyone could take a look at our code and offer any suggestions it would be much appreciated!

GitHub - Nanuet-Knightronz/2025-Robot-Codebase at SwerveDrive

First question when you say sparkmax encoders do you mean an encoder plugged into the sparkmax or the internal neo encoders? You’ll need external absolute encoders to avoid having to manually set your wheels before every match. I’ve only worked with exclusively ctre drivetrains, but this problem is often 1 or a combination of several things.

  • Check that your magnets are glued into the modules correctly so they aren’t spinning.
  • Check and double each modules can IDs are correct. Ctre has a function in their desktop software to blink the motors for a given motor which helps verify this. I believe rev has something similar.
  • Verify you put the can IDs into code in the expected order. Not exactly sure what yagsl expects but others often use front left front right back left back right.
  • Check you’re following any instructions for orienting your imu relative to the modules. It’s not enough for the wheels to all be pointed in the same direction, they need to be pointed in the correct direction relative to the imu.

Your front right json contents shown below. The id is the SparkMax or Cancoder Can-bus address. The
‘canbus” should be blank.
Make sure you can flash each device using Rev Hardware Manager.
{
“location”: {
“front”: -11.75,
“left”: 11.75
},
“absoluteEncoderOffset”: 0,
“drive”: {
“type”: “sparkmax”,
“id”: 113,
“canbus”: 13
},
“angle”: {
“type”: “sparkmax”,
“id”: 116,
“canbus”: 16
},
“encoder”: {
“type”: “cancoder”,
“id”: 1,
“canbus”: 21
},
“inverted”: {
“drive”: false,
“angle”: false
},
“absoluteEncoderInverted”: false
}

2 Likes

you just solidified my choice on not releasing 2025 until i get a proper JSON schema.

The id field is THE CAN ID! The canbus field is THE NAME OF A CANIVORE! The canbus field is a string. The following would be your config assuming the id field is your CAN ID!

{
“location”: {
“front”: -11.75,
“left”: 11.75
},
“absoluteEncoderOffset”: 0, // I break things here for a reason. Please watch the videos and read the documentation at https://docs.yagsl.com
“drive”: {
“type”: “sparkmax”,
“id”: 113,
“canbus”: null
},
“angle”: {
“type”: “sparkmax”,
“id”: 116,
“canbus”: null
},
“encoder”: {
“type”: “cancoder”,
“id”: 1,
“canbus”: null
},
“inverted”: {
“drive”: false,
“angle”: false
},
“absoluteEncoderInverted”: false
}

The json is from the original post. We had no problems creating own json files from your documentation.

I realized that after posting! You were completely right in your post which is why i reacted :point_up: .

I hope you guys like it! Lmk if there’s anything that can be better!

Your front right json contents shown below. The id is the SparkMax or Cancoder Can-bus address. The
‘canbus” should be blank.
Make sure you can flash each device using Rev Hardware Manager.

Thanks so much! This seems like it solved out issues. Our programmers are new this year so we truly appreciate the help.

1 Like