PID Controller in 364's base swerve drive code

We’re currently using 364’s base swerve drive.
we have a PID controller for the movement but i think it doesn’t work properly, when i use the right stick(used for rotation) and the left stick(used for moving) together the offset angle of every module is changed.
so after a couple of seconds of doing this motion everything is messed up and i have to upload the code again or reset the robot.

the code :


do any of you have solution for this problem?

1 Like

If you could share all of your code that would be helpful to find the issue.

The issue to me sounds like the steering gear ratios are probably wrong in code, but it’s impossible to say for sure.

the offset angle of every module is changed

What exactly do you mean by this? How are the modules different? Are the modules still all pointing in the same direction when you just try and move around? Or are some modules offset to others?

I assumed the ladder, which would cause each module to accumulate error quickly.

As i said : when the robot rotates around its own axis and simultaneously move forwards or backwards or a combination of both(the x and y axis together) the angle of the modules is wrong.
after a while of moving the robot in the way that i described earlier , i tried to move it just by using the right stick (used for rotating the robot) and it gives me the positions which are shown in the picture. Which are clearly wrong because at that position there’s no way that the robot will spin around its own axis.

what causes them to accumulate error quickly?

My theory was that the steer gear ratio in your code was not what the steer gear ratio of your physical module was. This would cause the actual angle of the wheel and what the steering TalonFX thinks the angle of the wheel is to quickly become different, or to accumulate error.

After looking at the picture of your chassis and reading your code, it doesn’t seem like this is the issue. It appears you are using SDS MK4i modules, and the steering gear ratio in your code is correct for that module.

Did you follow the steps in the 364 base Falcon swerve repo for tuning the PID? You also have a really large D value set for your steering PID, that might be what’s causing your problem. Try running a only p loop for steering and see what happens.

To add to what @anon37142155 said, make sure you followed all the instructions of the BaseFalconSwerve readme.

On top of this, I would put the chassis on blocks, and manually, by hand, thoroughly check that both the CANCoder output and the integrated encoder angle output are both correct. Remember that counter clockwise should be positive as well.

In addition to what others have already stated, something I noted while debugging our swerve drive is that if we turned the robot on and started driving before the Phoenix libraries were done initializing, it would reset our axis motors and mess up our configs. If you are enabling as soon as possible after a deploy, this might be your issue.

To test this, you could make a method that calls the resetToAbsolute() method in SwerveModule to force the modules to reset in TeleOp.

You can get weird behaviors if you don’t have the modules numbered correctly – in other words, if the CAN identifiers for the motors on each corner don’t match what is expected in the code. There is a coordinate system that applies, and also an ordering convention for the modules. Here’s one thread where this has come up on CD before. This is another thing to check out.

Based on the picture sent, this isn’t (the only) issue. If that were the case the wheels would still be parallel or perpendicular when trying to rotate in place.

1 Like

From the description, I wasn’t sure what was being tried in the picture.

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