How to tune a ProfiledPIDController

First, l want to thank everyone who has give me a helping hand in swerve’s auto. l have successfully achieved swerve’s rotation in the path. However, my swerve doesn’t rotate smooth to get to the desired rotation. l have used a holonomicDriveController to do the path following. And l think the thetacontroller is not tuned well , causing the robot’s osciliation during the rotation. l know that tuning the PIDController is a trial and error. However , l have tried nearly all possible kP and the swerve doesn’t rotate as l expect (maybe there is something wrong with my tuning method). l heard that sysid can do some help in the profiledpidcontroller’s tuning. But how should l do that? Which TrapezoidProfile.Constraints should l set? Or is there any other good method to tune the ProfiledPIDController?

Any reply is appreciated!

There isn’t nearly enough information to troubleshoot remotely. What values of kP did you try? How did the robot’s behavior change with those different values? What are the value of the other constants? Since the behavior of the holonomicDriveController depends on how well tuned the steering and drive controllers are, how have you verified those? Can you share the plots you’ve generated to troubleshoot this problem?

Firstly, l have set the kP to 2 and the robot osciliates fiercely when rotating. Then l half to and half it and half it to 0.3 , it still osciliates when rotating.

The cruise veocity is 2Math.PI and the accel is Math.PIMath.PI.

In the teleop , the swerve drives very well.

l also want to know where to get the ProfiledPIDController’s plot? :joy:

When tuning gains blindly, you have to think in terms of orders-of-magnitude. If 0.3 oscillates, try 0.03 next, and 0.003 after that, and so on. You need to perform a logarithmic search, because without doing the dimensional analysis beforehand you have no idea what scale you are on.

So how to graph the ProfiledPIDController’s setpoint and the goal . l think it will help me tune it. Besides , can l use the sysid to tune the profiledpidcontroller. And how should l do that. l think that l should let the swerve in a rotation behave and lock the swerve’s wheel , maybe the wheel should like below:

And then l should run the four tests on the sysid and get the kP feedback . But how can l make sure that the unit of kP is consistent with mine?

1 Like

Such a test will certainly work, provided you can lock the modules correctly. You’ll have to do the math to convert from motor rotations to robot rotations (the wheels are moving in a circle, so just figure out how many times the wheels turn per robot rotation and proceed from there).

Thanks , l will do the test soon!

1 Like

image
What does this mean?

It means your motion threshold is too high, most likely.

What should l change?

image

image

After l have chosen the forward in the sysid , it can’t be opened again.\

1 Like

Make sure you have the most recent version of SysId.

Also, delete sysid.json and sysid-window.json.

l use WPILIB 2022.2.1

Where are these two files?

Thanks , it is now OK!

1 Like

$HOME/AppData/Roaming

image
Which value should set?

image
And l use the drivetrain angulat mode to test it, is that right?

The smallest value that correctly trims out all the data from before the mechanism begins to move.

Ideally yes, but you’ll have to be careful about wheel directions and also that mode is currently broken because of how it reads from the gyro. Instead, do a linear test.

Thanks , it seems that the feedforward parameters are too big. Besides , l set the kP got from the Sysid to the ProfiledPIDController, but it can’t rotate to the desired angle timely as l expect. l think the kP is too small , but the swerve doesn’t osciliate with this kP.