Hi everyone,
As 6838, this year we upgraded our mk4 swerve modules to mk4i with a conversion kit. Recently, we were trying out last season’s swerve code and had issues with the rotation motor’s PID algorithm. We are sure that we set the TalonFX and CANCoder IDs, and the Gear ratio correctly. After trying different kP values, the modules were oscillating almost randomly (sometimes two of the modules stayed still while the other two were oscillating). Hence, we decided to test the swerve code on a single module and worked with that code.
In that code, we tried to set the module angle at a constant setpoint and tuned the kP value according to that setpoint (i.e. 150 degrees). It seemed to work satisfactorily, however, once we set the setpoint to 40 degrees, the module was oscillating at a particular angle (far more different than the setpoint). Increasing the kP value ended up with an oscillation within almost 360 degrees while decreasing the kP value caused either to oscillate at a particular angle or stand still. Both tried a basic hand-written PID algorithm and the PIDController class and there was no change. We tried using both the signed and unsigned configurations for the CANCoder. However, nothing changed. The current CANCoder value was alternating between 170 and -170.
Here is a video of the constant setpoint trial. (The video is in slow-mo and a single PID algorithm is running throughout the whole video. The wheel turns to the desired rotation, then instantly rotates to the opposite direction, and then gets back to the desired one.)
Here is a video of a trial with a small kP value:
Here is another trial with a slightly greater kP value:
I believe that a proper PID output to the motor has to look like that graph.
However, according to my observation, our PID output looks like this:
In total, we tried using a constant setpoint, tuning kP values, using different CANCoder degree absolute sensor range configurations, a handwritten algorithm, and the PIDController class.
I appreciate it so much if anyone could help with this issue
Note: The optimization of the desired rotation angle was present in the first code we tried, however, we did not include it while working on a single module. Additionally, the offsets were not set as we left setting the offsets after solving the oscillation issue.