We almost but not quite can get the SparkMax Smart Motion for position running correctly using an analog signal plugged into the SparkMax data port breakout board. The software is essentially the Rev example plus a few lines of Java code for the analog input.
The analog signal represents the position and is .5V to 1.8V; all is well with acquiring and displaying that signal.
We set a setpoint of 0.65V and tolerance of say 0.05 (it doesn’t matter - behavior is the same).
The controller controls to 0.70V (obviously within tolerance of 0.65 + 0.05). There is a slight chatter as the system operates within about 0.002V every second or two as the system position sags a tiny bit or there is a bit of noise in the sensor circuit and then the position is bumped back up with the motor on for an instant as the system responds very quickly to a Neo at high power.
The min motor voltage allowed is -1 and the max is 0 (the system is to run only one direction).
How can we get the system to push closer to the setpoint so the slight sag or noisy circuit stays in tolerance longer? If at the setpoint, the position will hold for minutes without additional motor operation.
We’ve tried too many combinations of kP, kI, kD, kF, Izone, max velocity, and max acceleration. Changing these values does effect the system in reasonably expected ways but nothing gets into the tolerable region far enough (closer to the setpoint) to give more time between jolts of motor voltage (usually about .5 %VBus to 1 %VBus).
Problem Number 2: Another observation that is confounding us and make alternate solutions difficult is the get velocity reports a velocity about 2.7 times smaller than the actual velocity over a wide range of velocities.
Smart motion cascades through velocity control, generally not a great idea to use it. Generate trapezoid profiles on the Rio and use position control mode on the spark
Thanks for the advice. We thought the velocity control of Smart Motion was exactly what we needed.
We want to get to our setpoint, say 0.65V, as fast as possible without exceeding -3400 RPM, at which point the motor should go off. The system will sag a bit and the motor should go back on at the allowed error of say 0.65 + 0.05 = 0.70.
Too high of acceleration is of secondary concern but would be handy to use as a limit of extreme acceleration.
The Smart Motion parameters seemed to be what is needed to do this but the motor stops at the near edge of the allowed error and the max speed is somewhat related to the motor speed but it’s not predictable and reported or attempted to set RPM doesn’t seem to have anything to do with the actual motor speed units.
If we could set a tolerance on the motor’s zero speed (e.g. any voltage requested below 0.02 is off), we could more easily use WPILib. If the SparkMax reported the correct speed we could use the WPILib. Neither seem to be happening for us. The periodic status for velocity appears slower than the published rate and doesn’t change as expected with the set frame rate method.
Thanks for the responses. We coded our own Smart Motion and named it Smarter Motion, of course. Changing the setpoint to fool the Smart Motion would band-aid one problem but the velocity limits weren’t working right, either. We’re happy with our way except it was a lot more work that we didn’t think we should have to do.