|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
|||
|
|||
|
PID Help
Hey guys, our team is looking into using PID with encoders and implementing them on our drive system. I've gotten to the point where I can change the setpoint at will and get our motor to drive an encoder to a specific value, but we cannot seem to get it to do so without a considerable amount of overtravel.
In this code, Distance is the recorded distance in pulses of the encoder. We have calculated that a pulse is equal to approximately .73 degrees travel of the shaft of our motor, so anything more than a pulse off is not acceptable. http://i.imgur.com/zc2iMgA.jpg In this code, the left and right trigger buttons are no longer being used. The controller axis is being used to set the setpoint. Since the maximum magnitude of our process variable (Distance) is 124, I have taken the axis value and multiplied it by 124, so a value of 1 on our axis will set the setpoint of our PID at 124. Here is a picture of our gains, outputs, etc: http://i.imgur.com/PKx6P7i.jpg These values are the results of me trying to tune them is such a way that our motor can get to a specified value with a high amount of precision without overshooting, and without taking a long amount of time to adjust the value to an acceptable range. If anybody has successfully run PID.vi with an encoder with high precision, could you please look and see what I am missing here? And if you have had this type of issue, could you tell me how you resolved it? Thanks, William |
|
#2
|
|||||
|
|||||
|
Re: PID Help
Does this motor have a load on it?
PID hits a target somewhat better when there is some sort of drag to slow it down. An unloaded motor will coast right on by the setpoint until the PID reacts to bring it back where it will probably coast by again. Why is your output scaled to +/-50 instead of a typical motor +/-1 ? Have you considered plotting the waveform to visualize how the system is behaving? Last edited by Mark McLeod : 20-01-2015 at 22:03. |
|
#3
|
|||
|
|||
|
Re: PID Help
At the moment, no, it does not.
|
|
#4
|
|||
|
|||
|
Re: PID Help
I originally had the output set to full 100/-100 capacity, and was just trying anything to alleviate the overtravel on the system. I haven't considered plotting a waveform yet.
|
|
#5
|
|||||
|
|||||
|
Re: PID Help
For a test load you can just add something harmless (mostly harmless) to rub against the motor shaft.
Also, setting your speed controller to Brake mode will help a little bit. |
|
#6
|
||||
|
||||
|
Re: PID Help
I am not the most knowledgeable on this subject but, you seem to be taking the distance out of the encoder, since a drivetrain is set up for continuous motion shouldn't your PID be targeting a specific rate at which the wheels should be spinning? (assuming this is for dynamic input, such as driving in teleop, not autonomous movement) There is a rate output on the encoder, so do you want your code to look a little more like this?
Code: http://i.imgur.com/5Jja5Ce.png What I have written here may just be a load of garbage. It has not been tested, it just seems logical to me. I tried to comment my thought process. Last edited by Skyehawk : 21-01-2015 at 00:07. |
|
#7
|
|||||
|
|||||
|
Re: PID Help
Quote:
Start by setting the gain very low and the times to zero (which will disable the integral and derivative terms). Put the appropriate load on the motor and start increasing the gain until it becomes unstable, then back the gain down again. If you don't get to the set point in a reasonable amount of time, set the integral time to a value slightly longer than you think it should take to get to the set point, and tweak it from there. You might be able to ignore the derivative term completely. |
|
#8
|
||||||
|
||||||
|
Re: PID Help
You're being set up for failure if you're trying to control to +/- 1 sensor tick. I always aim for getting 10 times the resolution compared to the accuracy requirements.
|
|
#9
|
|||
|
|||
|
Re: PID Help
Quote:
So from the OP, it appears that you are using a 500 pulse encoder mounted directly on the motor shaft? Do you have any gear box before the wheels and what is the ratio? What size wheels? Assuming a 5:1 gearbox and a 4" wheel (~12.56 circumfrence) would give distance resolution of 0.005" Is that really what your accuracy requirement is? I recommend double checking your requirements. |
|
#10
|
||||
|
||||
|
Re: PID Help
Quote:
Quote:
Quote:
Quote:
I want to reiterate that we are using these motors and encoders in the context of mounting them on top of our drive motors and rotating them 90 degrees clockwise or counterclockwise, allowing a "sideshifting" motion, increasing field mobility. Thank you all for your input, and I hope I addressed all the issues properly. |
|
#11
|
|||
|
|||
|
Re: PID Help
A potentiometer may be a more appropriate sensor.
|
|
#12
|
||||
|
||||
|
Re: PID Help
This is true, simply make a mounting bracket for the potentiometer and provide linkage to your swerve module, coaxial is another route that completely circumnavigates this issue.
If youre dead set on using an encoder for your swerve feedback then you should look into tuning your PID methodically and slowly. For high reduction applications like this your proportional will be a pretty small number (0.2 would probably be a good starting point). Ignore I and D until you reach something under control that levels out. Hope you have some success. |
|
#13
|
|||||
|
|||||
|
Re: PID Help
Most potentiometers will only rotate a certain number of rotations (often about 240 degrees), making them inappropriate to steer a swerve drive. We used a Hall-effect sensor that simulated a continuous rotation potentiometer for our kicker last year. I believe it cost about $50 from McMaster-Carr, but I don't have the model number. I did a bit of browsing, and found several devices of this type under "angle sensor", but I couldn't find anyone who posted a price on the web site.
|
|
#14
|
|||
|
|||
|
Re: PID Help
Quote:
|
|
#15
|
||||||
|
||||||
|
Re: PID Help
Quote:
Imagine instead that you're accuracy requirement was 0.75 degrees, but you're sensor measured 0.075 degrees (10 times the resolution compared to the resolution requirements). You would know the difference between a very small bit off, and 0.75 degrees off, and your PID controller could output a different value based on how far off it is. Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|