![]() |
Use a button to make a motor move a certain number of rotations
Ok I was curious to see if this would work for making a motor move an exact amount of rotations when a button is pressed, thanks.
![]() |
Re: Use a button to make a motor move a certain number of rotations
It depends on how you set your motors in Begin.vi, and what type of motor controllers you are using. Most likely, this will cause your motors to run at full speed forward or backward, while the button is pressed.
If you are using encoders and configured Talon SRX's to use CAN and position control with proper PID values, you may get a twitch. You will need proper software setup, encoders, and good PID values to do what you want to do accurately. The drive reference contains data that will configure the various drive and motor vi's to interpret their inputs properly. By default, the maximum input/output is 1, which corresponds to a 100% forward or backward. Your ±3.76... input will be seen as a saturated maximum of 1. The default mode if you just open a can Talon SRX will be Percent Vbus, which works the same as PWM, and doesn't use feedback from an encoder. All of this being said, you can approximate the closed-loop control to do what you want with a sensibly low speed and a timer, but this will take a LOT of experimentation, and the results will be highly variable. |
Re: Use a button to make a motor move a certain number of rotations
Quote:
|
Re: Use a button to make a motor move a certain number of rotations
What is the number of pulses per rev for the built-in encoders? I think the only legal motors that have built-in encoders have 7 pulses per revolution and a 71:1 step down through the typically attached gearboxes. Are these the ones that you are using?
If so, that could correspond to 7 x 4 x 71 = 1988 counts per revolution. The factor of four is because the encoder is quadrature, and has four registered pulse edges per pulse cycle. That means you would be seeking a count of approximately 7475. The math changes if you are using a different gearbox. Note that the numbers I am using are integers. You can't have fractional pulses. All of this assumes that you set the output type as position in Begin.vi, and that you have appropriate PID terms. |
Re: Use a button to make a motor move a certain number of rotations
Quote:
|
Re: Use a button to make a motor move a certain number of rotations
You would put it as an input to the drive (where you have it), but you have to have the drive motors properly configured. One other thing, is that you need a little more logic to latch the value. The Teleop.vi runs approximately every 20 ms. As soon as you let go of the button, your input will be to drive the motor back to the 0 position. This isn't what you want.
If you intend to drive your robot completely with position commands, you will need a state machine that keeps track of the current values, incrementing and decrementing the intended position. It is much easier to drive in speed or voltage mode. |
Re: Use a button to make a motor move a certain number of rotations
Quote:
|
Re: Use a button to make a motor move a certain number of rotations
Ok I think I'm starting to understand this, so would I put the 7475 number as distance per count in begin for the encoder? Past that I'm not sure how I can assign a button to work under that motor count for the encoder and the motor in teleop
|
Re: Use a button to make a motor move a certain number of rotations
Can you post the snippet of code from Begin.vi where you setup these motors?
|
Re: Use a button to make a motor move a certain number of rotations
Quote:
![]() |
Re: Use a button to make a motor move a certain number of rotations
Quote:
![]() ![]() |
Re: Use a button to make a motor move a certain number of rotations
Your snippets are illuminating.
OK, here's the rest of the story. Unfortunately, you won't have a simple way of just sending a number to the motor controller, as you are using PWM Victors, which have no understanding of encoders or close loop modes. You will need to implement a PID control in LabView, where the encoder inputs are compared to your desired position. The outputs will drive the motor voltages up and down, until the desired position is realized. LabView has several built-in PID functions, and there are many threads here about how to use them. |
Re: Use a button to make a motor move a certain number of rotations
Quote:
|
Re: Use a button to make a motor move a certain number of rotations
Quote:
|
Re: Use a button to make a motor move a certain number of rotations
Quote:
|
Re: Use a button to make a motor move a certain number of rotations
Quote:
The motors themselves don't have any intelligence. Their inputs are only the voltage applied to the wires. The encoders are not linked in any way to the windings in the motor. You have setup some DIO channels to take the A and B data from the encoders. This information goes straight into the roboRio, which has to do something with it, to control the input to the victors. The roboRio is the brain in this case. The new Talon SRX's are intelligent, and can do the work onboard with no involvement of the roboRio. The older Jaguars had promise of this, but in practice, they rarely worked as designed for encoder-driven closed loop feedback. I have trouble finding the right words to describe how much I LOVE the Talon SRX's closed loop modes. |
Re: Use a button to make a motor move a certain number of rotations
Quote:
|
Re: Use a button to make a motor move a certain number of rotations
Quote:
|
Re: Use a button to make a motor move a certain number of rotations
Quote:
|
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. |
Re: Use a button to make a motor move a certain number of rotations
Quote:
Other option is to implement a proportional gain yourself. Take the current encoder value, subtract the current reading and multiply it by a constant (you'll have to play with the constant to get it where the robot gets close without oscillating) |
| All times are GMT -5. The time now is 21:25. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi