Author Topic: PID help for beginner  (Read 4506 times)

0 Members and 1 Guest are viewing this topic.

Offline hayamaTopic starter

  • Beginner
  • *
  • Posts: 1
  • Helpful? 0
PID help for beginner
« 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.

Offline benji

  • Supreme Robot
  • *****
  • Posts: 830
  • Helpful? 0
Re: PID help for beginner
« Reply #1 on: April 11, 2008, 10:03:12 AM »
Quote
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? ;)


Quote
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
good ol' BeNNy

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: PID help for beginner
« Reply #2 on: April 11, 2008, 02:17:37 PM »
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
Check out the uBotino robot controller!

Offline JesseWelling

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 707
  • Helpful? 0
  • Only You Can Build A Robot!
Re: PID help for beginner
« Reply #3 on: April 11, 2008, 04:05:52 PM »
This article is a very good reference for those wanting to see some code:
http://www.embedded.com/2000/0010/0010feat3.htm

Offline stopgo

  • Full Member
  • ***
  • Posts: 58
  • Helpful? 0
Re: PID help for beginner
« Reply #4 on: April 15, 2008, 10:54:03 AM »
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.
« Last Edit: April 15, 2008, 10:55:16 AM by stopgo »

 

SMF spam blocked by CleanTalk