The SparkMax motor controller has both a set(double speed) and setVoltage(double outputVolts) function. I’m unclear as to when I would use one over the other as well as the values that would be passed. I don’t have access to electronics at the moment that I can experiment to find my answers. My specific questions:
What is the range of values that can be passed to setVoltage(double outputVolts)? Is this -1 to 1 as in set(double speed) and some conversion takes place in the function?
I have read that setVoltage(double outputVolts) accounts for battery sag. So can I one-for-one replace the use of set(double speed) with setVoltage(double outputVolts) passing in the exact same parameter value when battery sag will be a concern for the performance of the mechanism (such as in a simple autonomous drivetrain routine)?
In what types of applications would set(double speed) be used over setVoltage(double outputVolts)?
If anyone has specific info I can read that explains this more I would appreciate it. Trying to get it all straight in my head so I’m not just blindly using one function over another and am making informed choices in how I code. The example code that I found doesn’t show the use of setVoltage() for SparkMax.
You would pass in a value that would be the voltage you want the motor to be sent, usually something like -12 to 12.
If you used setVoltage(6) and your battery was at 12 volts it would be like set(0.5) but if your voltage dropped to 6 volts at the battery then setVoltage(6) would be like set(1.0).
If you have something like a climber where you want it to go as fast as it can no matter how low the battery is using set(1.0) would be an option.
Although you could still use setVoltage(12.0) in that case. It’ll clamp to 12 V (1.0 when normalized). The main place to use set(), in my opinion, is when you’re passing joystick axis readings directly to motors in teleop.
Not sure if it was ever fixed, but we were experiencing huge oscillations when using “setVotlage()” on the spakmaxes with our shooter. We ended up enabling voltage compensation and just using “set()” instead and this seemed to work much better. Not sure if we were during something wrong or there was some smoothing filter on the voltage but it was rough.
I know this thread is older but my team experienced issues where our robot would drift to the left a bit when using set() and it would get worse and worse the lower battery voltage we had. We then extended the differential drive class and modified the curvurtureDrive() function to use setVoltage() instead of set() and noticed the robot drove a lot straighter. So in this case 1806 prefers the setVoltage() function instead because of better consistency and more accurate driving. We also don’t use swerve drive though so I’m unaware if the issue is more obvious with a swerve compared to a West Coast drive
Would be interesting to see if anyone would be able to empirical testing on how exactly these controllers react. I have always found the documentation of the modes a bit vauge at best. I do find it interesting you where having issues with oscillations with set voltage. My guess of what might cause that is you where demanding enough power to cause the battery voltage to drop and that was causing an oscillation with your tuning.