|
Re: Use a button to make a motor move a certain number of rotations
OK, there are a few things that you can do to get it pretty close without doing a full PID. No matter what, you need to get your logic right, which means that pressing a button will toggle a persistent state. You need to flop between deployed and not deployed, and the state has to be retained from one pass through your code to the next. Feedback nodes (at the bottom of the structures palette) are helpful for this. After you get this worked out, this logic can switch your case structure (or selects) to start moving in the right direction.
Once you have that part figured out, you can use the PID vi's that are included in LabView. Since the output shaft is so slow relative to the count, you can probably get away with using only a well-chosen P gain, setting the I and D to zero.
If you don't want to use the PID function, you can implement the P part on your own. Basically, you calculate the difference between where you are (current encoder count) and where you want to be (final encoder count), and multiply this number by the P gain that you choose. This number is then fed to the motor set vi.
As you approach the desired final encoder count (called the setpoint), the resulting number will get smaller, and the motor will slow, eventually stopping.
If your P gain is set too low, it will never reach the setpoint as the commanded voltage will eventually not be enough to move the motor. If the P gain is too high, the motor will oscillate about the setpoint. Because of this, you could purposefully choose a P that is slightly too low, and bump up your setpoint to a number that lets your motor rest where you want it to end up.
This last paragraph is an adequate way to accomplish your goals, only because your design is essentially toggling between two points. You fudge the setpoint numbers for deploy and retract, until it acts the way you want it to. This may not be viewed as the correct way from a control system perspective, but it will be good enough.
|