# Voltage Compensation on Sparks

My team is using sparks and NEOs this year, and we’re having trouble understanding how voltage compensation works. We are using a PIDF loop to control our shooter (well actually almost everything, but the shooter is a good example), and have tuned everything to work sort of ok with default settings. However, even after tuning P we still see a large effect from battery voltage drop. Would voltage compensation solve this problem? Does it convert the PID output to a voltage, or are the units of the loop constants themselves altered? Any pitfalls to avoid?

Edit: I didn’t phrase this right, and clarified in a comment. This is the clarification:

I’m sorry, I didn’t really make myself clear. I meant to say that the exact speed of the motor is highly sensitive to battery fluctuation up or down. It seems as though this is because the PIDF loop gives values in terms of an absolute percentage of voltage. It doesn’t matter if our target is 12 volts or 7, because so long as the fluctuations are unaccounted for we can’t hit either with a percentage of bus voltage. It seemed as though SparkMax’s had some functionality to generate a target in terms of voltage, and use measurements of the bus voltage to convert that voltage into a duty cycle.

What I’m not sure of is exactly what will do what. .enableVoltageCompensation() is decribed as setting voltage compensation on “all modes”, but I haven’t figured out how it does so. I’ve seen people reference some other method as well, although I can’t find reference to it at the moment. Normally I’d just experiment a bit with a testbed, but all of them have been harvested to acquire spare parts.

So really I’m asking if there is a way to, on a SparkMax, set the output of the PIDF loop to be a voltage value, which the motor controller will attempt to achieve by computing a power cycle value based on the current voltage (And yes I could just run this on the rio, but we had issues with stuttering. I’m hoping the SparkMax’s faster response time will smooth that out a bit).

What percentage of the 12v output are you shooting at? PID and voltage compensation can only compensate with what the battery can supply.

2 Likes

^^ PID should not also require voltage compensation, except perhaps on your feed-forward term. As @Joe_Ross said, the motor controller can’t give you more than 100% throttle no matter what your PID asks for; you should design so that you’re normally running between half and 3/4 throttle to give yourself headroom especially towards the end of the match.

I’m sorry, I didn’t really make myself clear. I meant to say that the exact speed of the motor is highly sensitive to battery fluctuation up or down. It seems as though this is because the PIDF loop gives values in terms of an absolute percentage of voltage. It doesn’t matter if our target is 12 volts or 7, because so long as the fluctuations are unaccounted for we can’t hit either with a percentage of bus voltage. It seemed as though SparkMax’s had some functionality to generate a target in terms of voltage, and use measurements of the bus voltage to convert that voltage into a duty cycle.

What I’m not sure of is exactly what will do what. .enableVoltageCompensation() is decribed as setting voltage compensation on “all modes”, but I haven’t figured out how it does so. I’ve seen people reference some other method as well, although I can’t find reference to it at the moment. Normally I’d just experiment a bit with a testbed, but all of them have been harvested to acquire spare parts.

So really I’m asking if there is a way to, on a SparkMax, set the output of the PIDF loop to be a voltage value, which the motor controller will attempt to achieve by computing a power cycle value based on the current voltage (And yes I could just run this on the rio, but we had issues with stuttering. I’m hoping the SparkMax’s faster response time will smooth that out a bit).

I don’t think “voltage compensation” does what a lot of people think it does. It not compensate your tuning values for drooping voltage. It only keeps your controller output below the voltage that you set it to.

The user manual states “In voltage compensation mode mode, this is the max scaled voltage.”, so I believe that mean if you set the compensation voltage to 10V, your PID will max at 10V even if the battery is 10V to 12V. If you don’t set it, you’ll max out at the current battery voltage.

Where this gets tricky is that your F-term for constant speed can change with the battery voltage; F-term basically defines an rpm/voltage ratio, and that changes as the battery voltage drops. With just F-tuning, you’ll have a very different value with a 10V battery than you will with a 12V battery.

In a standard PID loop, that’s where your I-term comes in, because it integrates any error to eventually get you to zero error. This page has a nice summary table showing how the different parameters affect rise time, overshoot, and settling time without getting into all the math behind control theory.

1 Like

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