My team decided to have a swerve drive this year and I'm having trouble programming it

I used this document Introduction · FRC Swerve Drive Programming to help me get started but some of the methods involving PID are outdated and I don’t know how to convert them to the 2022 PID controllers. Our swerve modules are the thrifty bot swerve modules, using Falcon 500’s for driving and Neo 550’s for the angles. Any help is greatly appreciated.

If you share your code you have so far it will make it easier to try to help! I’m happy to take a look.

here is the link to my github

Hi, we recently were able to get our serve to work. While getting our serve to work we encounter a fair number of issues, from broken encoder wires to wacked up pid controllers. I’m still no expert but I’m willing to help.

What is your current issues? Are you trying to get the code to build or are you getting jittery wheels? We had seemingly random jittering in our wheels and it turned out to be the PID controller was misconfigured. If you wheels are jittering try setting the p value to 0.1 and the I and D values to 0. Test your code and double the p value until your wheels jitter again. Then go back to the last value that didn’t jitter.

In our final code attempt we used this video for guidance and found it quite useful for setting up the swerve code:

I hope some of this is useful.


Thank you, I will make sure to look at that. As of right now I’m just trying to convert that code I found to the 2022 stuff so I haven’t necessarily seen how it all interacts with the robot quite yet. I’m just very unfamiliar with PID so I’m not 100% as to how it all works.

If you are very unfamiliar with PID, your time would probably be better-spent working some simple PID examples (say, an azimuthal controller on a single module) than attempting to write code for a whole drive.

Thriftybot has example code for Java linked here:

It may be worth it to at least take a peek. I haven’t looked at it much myself (we have the SDS MK3s, so I haven’t had much reason to look).

Thanks, I tried finding this but for some reason I was unable to. I will make sure to read through it later.

Update: we finally got the wires for the mag encoders in but now the sparks that they are plugged into won’t run. I have already set them into alternate encoder mode through the client and they are in brushed mode but they still won’t move.

I used that video and it really helped but right now the main issues we’re having is that our mag encoders don’t work with the spark max encoders which I’ve seen is a common problem. And the other problem is after uploading that code the motors that are in charge of the angles just move without any joystick input.

1 Like

This is my revised version, right now when I enable the robot the angle motors all move without any joystick input/

Do you have the cables swizzled? In brushless mode smaxes don’t have the same pinout as a SRX. You can either re-solder the cables to a breakout board or connect them to the RoboRIO. Information on how to do this is… Somewhere. I seem to recall some info on how to do that existing, but I cannot find it now.

I read a very long form on here about that, and we decided that tomorrow when we have access to the robot we’re going to attempt to wire them directly to the rio using the analog ports.

1 Like

Just remembered that the analog ports are 3 pins but what I read about the encoders I need 4 which would be ground, 5v, A, and B so how would we go about wiring that to the RIO.

The CTRE mag encoders are both quadratures, two digital inputs or absolute with is a PWM input to the Rio. Not analog. For swerve you want to use the absolute.

See this for more information Connect ctre mag encoders directly to roborio dio ports

What model of encoder are you using for the module rotation sensor? You and the code mention it being analog, but the variable name magEncoder and your mentioning of 4 wires make it sound like a quadrature or digital encoder.

If using the CTRE SRX MagEncoder wired to the rio directly, you need to use 2 DIO channels or a PWM channel. Using 2 DIO channels, you only need to provide 5v and Ground from one channel and then only the signal wire of the second channel is necessary. I’m not sure if the RIO can directly read a PWM input signal.

Edit: looks like @FrankJ beat me to it

The absolute encoder has a much slower update rate though compared to a relative encoder.

So if you can get away with zeroing your modules, you can use the quadrature encoder to get better signal response time.

We’re using the CTRE Mag encoders

We are using the absolute output (PWM) through GPIO pins on the Rio. Speed has not been a problem with the thrifty swerve modules. I would avoid the complication of adding the quadrature outputs unless you are having a problem.


So if wired to the PWM ports how would I bring that up in the code because I know for analog and digital inputs you just call them that, but PWM I’ve only ever programmed motors through that.