You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When switching from velocity control to duty cycle or voltage control, the applied output of the Spark Max oscillates rapidly between the correct output and the output from the previous control mode. Here's the code I've been using to test this:
Below is a screenshot from an URCL log, with the 1ms applied output period configured above. When enabling the first time in duty cycle mode, the applied output is correct and current draw is small. Velocity control also works as expected with no motion. When switching back to duty cycle mode, the applied output oscillates very rapidly. This causes the mechanism (a swerve drive wheel in this case) to rapidly oscillate, and the current draw is very high.
When zooming in on the third enable, you can see that the Spark Max runs at the correct duty cycle only for very short periods of time (1ms as it appears in the log with 1ms sampling).
This behavior is not perfectly consistent. Below is an example where I cycle between velocity and duty cycle control several times. Often, the oscillation is much less severe when switching back to duty cycle control (you can see occasional jumps and slightly higher current draw). However, I can reliably get the extreme oscillation by swapping back and forth many times (as in this example).
Some other observations:
This occurs when switching from velocity control to either duty cycle or voltage control, but not switching from position control to either of the others.
It can be temporarily fixed by restarting robot code, but not by reconfiguring devices with the same code running.
When the code is started/restarted, enabling first in duty cycle/voltage control works properly but switching to velocity control as any point causes it to return (as shown in the screenshots).
After the extreme oscillation has occurred once, it seems much more likely to repeat when enabled subsequently.
If the example code is adjusted to include an arbitrary FF value, the oscillation is between the correct duty cycle output and the arbitrary FF value (the other PID gains are 0).
I've tested this on several Spark Max devices running 2025.0.0-prerelease.6, though not a Spark Flex. The REVLib version is 2025.0.0-beta-2. I've also attached WPILOG files with the URCL data from the two screenshots.
Thank you for the extremely detailed report. This will be fixed in the next release of REVLib.
The issue is due to the fact that REVLib is not correctly stopping sending the previous setpoint command, so when you switch control types, it would be sending a velocity setpoint command along with a duty cycle setpoint command.
However, this only happens when switching to the duty cycle control type, which doesn't match up with your claim of it happening with voltage control type (and I haven't been able to reproduce this). I was able to reproduce this and this will also be fixed.
Interestingly enough, it seems that this bug has been present for the last 4 years.
When switching from velocity control to duty cycle or voltage control, the applied output of the Spark Max oscillates rapidly between the correct output and the output from the previous control mode. Here's the code I've been using to test this:
Below is a screenshot from an URCL log, with the 1ms applied output period configured above. When enabling the first time in duty cycle mode, the applied output is correct and current draw is small. Velocity control also works as expected with no motion. When switching back to duty cycle mode, the applied output oscillates very rapidly. This causes the mechanism (a swerve drive wheel in this case) to rapidly oscillate, and the current draw is very high.
When zooming in on the third enable, you can see that the Spark Max runs at the correct duty cycle only for very short periods of time (1ms as it appears in the log with 1ms sampling).
This behavior is not perfectly consistent. Below is an example where I cycle between velocity and duty cycle control several times. Often, the oscillation is much less severe when switching back to duty cycle control (you can see occasional jumps and slightly higher current draw). However, I can reliably get the extreme oscillation by swapping back and forth many times (as in this example).
Some other observations:
I've tested this on several Spark Max devices running
2025.0.0-prerelease.6
, though not a Spark Flex. The REVLib version is2025.0.0-beta-2
. I've also attached WPILOG files with the URCL data from the two screenshots.spark_issue.wpilog.zip
spark_issue_extended.wpilog.zip
The text was updated successfully, but these errors were encountered: