Society of Robots - Robot Forum
Software => Software => Topic started by: hayama on April 11, 2008, 09:06:00 AM
-
I need to implement a PID control. I've seen a lot of tutorials online, and I get the concept, but am just having thinking on how to implement it. For example I know the desired value vs. the actual value (is this from dead reckoning?) is needed. How is the desired value calculated? For example, the software tells the robot to move x inches forward. At the end of the process you would have the desired value and the actual value (encoder readings). However, what if your code is not to "move forward x inches", but rather just "move forward". How would the desired position be calculated then?
Also, what exactly is done with the output of the PID loop?
I appreciate the help.
-
How is the desired value calculated? For example, the software tells the robot to move x inches forward
dont you say that youve answered your own question? ;)
what if your code is not to "move forward x inches", but rather just "move forward". How would the desired position be calculated then?
there is no desired position in this case as you dont desire to go anywhere
make your questions a little more clear
-
I am no expert at PID as I am trying to understand how to use it myself. But here is what I understood:
- pid works by comparing the difference between the desired input with the current input and adjusts the output to reduce the difference
- the input may be speed and the output may be pwm for the motors
- to accelerate, the desired speed needs to be gradually increased by acceleration factor
- to slow down and stop at the desired distance, the desired speed needs to be gradually decreased by acceleration factor starting from a certain distance before the desired distance is reached
-
This article is a very good reference for those wanting to see some code:
http://www.embedded.com/2000/0010/0010feat3.htm
-
Hayama,
Benji's right, you have some logic errors. Try to model the problem as something like this:
I want to go forward 15 clicks (on my wheel encoders), and I feed some variable v to my motors.
Then a really crude PID controller might go something like this
error = 0
while (get_clicks() != 15 clicks) {
error += get_clicks() - 15
v = Kp*(get_clicks() - 15) + Ki*error + Kd*(get_clicks() - previous_clicks)
previous_clicks = get_clicks()
update_motors(v)
}
Where you tune the K's yourself.