Hello, I was wondering if i could use Neo Brushless motor with a certain rpm value (lets say 400 rpm). How can i do that? Does SparkMax or Rev Hardware Client has a function that can do that? Or do i need some kind of reducer?
Yes! The NEOs have builtin encoders, so you can (assuming you use Java) use the sparkMax.getEncoder() method to access them.
From there, you can use either the sparkMaxPIDController or a wpiib pid controller, referencing the encoder.getVelocity() method, which returns RPM, to get an output voltage or percentage to supply the SparkMax.
Hope this helps.
You need velocity closed loop control. The basics are explained here:
REV also provides a sample project here:
Using the PID controller of the SparkMax (in velocity control mode) is best practice…
Having said that, if you just want to get something up and running, there is a way to do this using only the encoder. There is an underlying relationship between voltage and RPM…
- 0V should give you 0 RPM
- 12V should give you 5676 RPM (known as the “free speed” of a NEO)
Thus if you want 2838 RPM (half the free speed) you should send 6V (ie. half of 12V), etc.
What this means is that you can just scale voltage proportional to your desired speed compared to the free speed of the motor. This is called your feedforward voltage - basically your way of saying “to even go this RPM, I know that I roughly need to provide this voltage based on what I know about my system and hardware”
This will work surprisingly well, but with two issues:
- It will likely take a while to spin up to your desired speed, assuming you are trying to rotate some mass, like on a shooter wheel
- It will likely not get exactly to your desired speed because the system is not “perfect” ie. there is mass, friction, etc.
Thus you can add on a little extra (or less) voltage depending on how far you actually are below (or above) your desired speed, in addition to that feedforward voltage. We would say this “closes the loop” on velocity because now you are asking “what is my actual RPM?” and using that to modify the voltage you send to the motor. This is basically the P (for proportional) component of a PID controller.
If none of this makes any sense (my apologies!) try dropping this line into your code to set the speed of your motor if you’re using Java. In this example, with a desired speed of 400 RPM:
encoder = motor.getRelativeEncoder();
motor.setVoltage( 12.0 * 400.0 / 5676.0 + 12.0 * .0001 * (400.0 - encoder.getVelocity()) );
The .0001 component is basically your proportional coefficient for a PID controller. Making it larger will cause you to spin up faster but at some point will likely cause you to oscillate around 400 RPM instead reach some steady state around it. Making it smaller will reduce this effect. This is something you will just have to play around with to find what works best for your system. Always best to start small and increase until you hit undesirable behavior.
The way it is now, we can imagine what will happen when spinning up from a speed of 0 RPM.
At 0 RPM → 12.0 * 400.0 / 5676.0 + 12.0 * .0001 * (400.0 - 0) = 1.33V
At 100 RPM → 12.0 * 400.0 / 5676.0 + 12.0 * .0001 * (400.0 - 100.0) = 1.21V
At 200 RPM → 12.0 * 400.0 / 5676.0 + 12.0 * .0001 * (400.0 - 200.0) = 1.09V
At 300 RPM → 12.0 * 400.0 / 5676.0 + 12.0 * .0001 * (400.0 - 300.0) = 0.97V
At 400 RPM → 12.0 * 400.0 / 5676.0 + 12.0 * .0001 * (400.0 - 400.0) = 0.85V
Essentially, it will give it some extra juice to accelerate and spin up, and then roll off to just the feedforward voltage when you reach your desired RPM.
Having said all this, as others have said, it is best practice to use the SparkMax PID controller. For things like prototyping, this is likely to work just fine! Hope this helps!
It depends on why you want to reduce the speed. As Martini159 pointed out, you only need a very small voltage (0.85v, ~1/14 of 12 v) to run a NEO at 400 RPM with no load. That means you only get 1/14 of the torque also, and only 1/14^2 (1/196) of the power. A gear box to reduce the speed is a much better choice if you want to reduce speed that much.
Thanks for all the help. It is a lot clearer now. I’ll take a look at PID controller and the closed loop control.
We are planning on using the motors on our elevator system. For this system we wanted a motor speed of 300-400 rpm and a torque of 2.5-3.0 Nm. On the Empirical NEO Motor Curves graph in NEO’s datasheet it looks like there is 2.5 Nm torque at 400 rpm. I was planning on spinning the motor at 400 rpm to get this torque value. Would this have worked or did I misunderstand the graph? If it would have worked, would you still recommend using a gearbox?