Working with PIDs
Jim Fouch
Posts: 395
I'm looking to implement 4 independent PID controllers for a robotic camera mount for a motorcycle project.
·
I've never used a PID controller but have seen them used to control testing for large A/C traction motors for Locomotives. For that project we used a PLC to control RPM and current during the testing. I did not work on the PLC area of the project but have a very BASIC idea of what a PID does.
·
For this project I will monitor the speed & lean angle of the motorcycle and use that information to position the camera for the best shot. I have 4 axis that I will have control over and I'd like to implement a PID controller on each one to get smooth motion.
·
I'd like to be able to create several different personalities (Position behaviors) stored on an SD card that would allow a look up table to tell the mount what pose to be in based on speed and lean angle. This would also allow me to create more personalities on a PC and quickly switch between them on the fly (Quite literally). This would also reduce memory foot print and program complexity on the Propeller. It would simply look up angles/speeds and then set the set points to the PIDs.
·
Each axis will have feedback and the mount could be put into a mode where a user positions the mount and records the positions (poses) and use them to smoothly transition from one pose to the next.
·
I've seen some examples of PIDs for the Propeller, but I'm really looking for a source to understand how to tune the PID for specific applications. I've looked on Amazon and there are quite a few books out there, but most of them are $100+. I don't have a problem spending the money & time, I'd just prefer to maybe be pointed in the right direction first.· ;-)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jim Fouch
FOUCH SOFTWARE
·
I've never used a PID controller but have seen them used to control testing for large A/C traction motors for Locomotives. For that project we used a PLC to control RPM and current during the testing. I did not work on the PLC area of the project but have a very BASIC idea of what a PID does.
·
For this project I will monitor the speed & lean angle of the motorcycle and use that information to position the camera for the best shot. I have 4 axis that I will have control over and I'd like to implement a PID controller on each one to get smooth motion.
·
I'd like to be able to create several different personalities (Position behaviors) stored on an SD card that would allow a look up table to tell the mount what pose to be in based on speed and lean angle. This would also allow me to create more personalities on a PC and quickly switch between them on the fly (Quite literally). This would also reduce memory foot print and program complexity on the Propeller. It would simply look up angles/speeds and then set the set points to the PIDs.
·
Each axis will have feedback and the mount could be put into a mode where a user positions the mount and records the positions (poses) and use them to smoothly transition from one pose to the next.
·
I've seen some examples of PIDs for the Propeller, but I'm really looking for a source to understand how to tune the PID for specific applications. I've looked on Amazon and there are quite a few books out there, but most of them are $100+. I don't have a problem spending the money & time, I'd just prefer to maybe be pointed in the right direction first.· ;-)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jim Fouch
FOUCH SOFTWARE
Comments
There are many such articles on the net.
By the way, how will you measure the lean angle of your motorcycle ?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Cheers!
Paul Rowntree
· The Parallax book "Process Control" has examples of PID. Free download too.
· http://www.parallax.com/Portals/0/Downloads/docs/prod/sic/Web-PC-v1.0.pdf
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There is a fine line between arrogance and confidence. Make sure you don't cross it...
·
Thanks for the link. There's a ton of info in there, and you can't beat the price. :-)
I haven't looks at it too deeply yet, but will in next few days.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jim Fouch
FOUCH SOFTWARE
I agree that the D is not really a concern. In my experience, the trick is to first get a system together to be able to test each parameter separately, that way you get a 'feel' for how each component works, so that you can put them together to accomplish your goal. After reading tons on the internet, and downloading a lot of code examples from various places, the reality is that you really can't rely on anyone else's code except for guidance, you have figure out what is needed and adapt a solution to fit your needs. I suggest creating a loop that you can easily change the parameters on the fly with some input method for testing, else change the code a lot as you test to see what the parameters are doing to get the response you need.
Of course when you sum the parts, you get a different behavior. The trickiest parameter is the Integral, which you can look at as an accumulator that starts adding up based on how long the error exists and the factor it is adding at. It adds up based on a factor that determines how fast it adds, but is also adding based on how fast your loop is running and checking for errors. I needed to add a maximum limit to the windup to keep things manageable. Too much windup and you run into overshoot and oscillation back and forth over your desired position. The same for proportional, set it too high and it just slams back and forth. What I find is that works well is to play with the integral in to ways: setting the Max Limit, and setting the accumulation Factor. The Factor decides how fast it ramps up to the Max, basically giving you some control over how fast or slow the motor responds to the error.
Here is a very crude object that I am working with that is still not done since I am changing out motors and gears weekly to find a solution. Different motors and gears require a whole new tuning process.
The object requires a modified pwmasm, I included the modified version. The concept of the object is that it chases an error between the position input and the encoder. You could maybe swap the encoder for whatever your tilt input is.
Like someone stated, you may first even skip using PID and try a direct servo method based on your tilt, of course you may need to incorporate some method to ramp the servo and decel it to the position to get a nice motion. Start with all vales at 0 on your system, take each one up to say 1000, see what happens. Then turn it off and play with another value.