Swerve Drive Programming Help

Hello! Need help with some Java coding with serve drive. Neo motors and spark max controllers.

We have been testing and making progress, but we’ve finally come to a stop. The modules move, but not in the right way. When we attempt to move the robot, the left modules work fine, but the right modules don’t work as well. On the right front module, it only turns, no driving. On the right back module, it only drives.

When it comes to the front right (FR) module, we think the following is happening.

The turning spark max (SP8-turning) is working fine, but the drive spark max (SP5-drive) doesn’t seem to be given any task to execute. The light on the SP5 simply shows solid magenta, meaning valid connection. SP8 shows green when forward and red when backward when moved by the Xbox controller joystick. It is turning at the right angle, just no drive motion.

I do have a list of tests we have done with electronics/mechanical troubleshooting. However, this is off of memory, so it would always be good to double check if something seems super suspicious to you:

-We tried changing the “non working” drive motor in the FR module to a new motor. No difference
-We tried changing the “non working” spark max controller in the FR (SP5) to a new spark max. No difference either
-We tried swapping the connection between SP5 and SP8 both with the wires and the code. This made the drive go at the right rpm, meaning it was the same as the left modules. However, it didn’t turn at all. This was the baffling test.
-We have triple checked the CAN wiring and CAN id’s.
-There might be more tests but I can’t remember them.

Here is a link to our code. We think this is likely the error somewhere. Robot Code

I’d appreciate the help.

I’m not able to take a full look at the code right now, but at a glance I don’t think your swerve drive kinematics object is set up properly. I believe the correct order for signs is different than what you have. I would suggest referencing the constants file of the GitHub BaseFalconSwerve by 364.

If you are using neos and spark maxes, I would highly recommend using or taking heavy inspiration from 3512’s published swerve code. As an added bonus, they have encoder and gyro values automatically streaming to the dashboard to help with troubleshooting. GitHub - frc3512/SwerveBot-2022: The source code for the 2022 FRC postseason swerve drive robot. We got our Swerve up and running pretty quickly using their base code.

Edit: Upon a cursory inspection it looks like you are already taking inspiration from 3512.
Here are some ideas on places to check for issues:
-Be sure to clone the latest release from 3512, they updated it about 1-2 weeks ago and fixed some errors
-Using the dashboard readouts, confirm your gyro is indeed ccw+.
-Using the dashboard readouts, be sure to grab the encoder offsets there, not from ctre’s hardware utility.
-Ensure that the cancoders on the turn motors are ccw+ using the dashboard
-Using the Rev utility ensure that the integrated encoders are reading ccw+, if not change the boolean for inverted.

Are you getting any canID errors when enabled?

Just at a quick glance. When you create your kinematics object you have to create them in the same order that you pass the swerve module states into.

Looks like you do FR, FL, BR, BL on the kinematics object x+ is to the front, and y+ is to the left of the robot when it is facing a 0 degree heading (faced away from the alliance station wall), but you are passing the swerve module states FL, FR, BL, BR.

As said before CCW is + robot heading rotation. Use a dashboard to make sure your encoder readings are going up when rotating ccw and down when rotating cw.

This is an earlier version 2194 code. Suggest you switch to https://github.com/fondyfire2194/SwerveControllerArrays2023

It has the same CAN IDS plus better Shuffleboard displays.

The version you have does have Jog commands for each of the 8 motors - see RobotContainer for button usage. CANOK checks are included

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.