go away spammer

Author Topic: Making a servo with a PID algorithm  (Read 7725 times)

0 Members and 1 Guest are viewing this topic.

Offline DaaniiTopic starter

  • Robot Overlord
  • ****
  • Posts: 138
  • Helpful? 3
Making a servo with a PID algorithm
« on: May 05, 2011, 11:23:03 PM »
Rather than hijack another person's thread, I started this one. I'd like to make a servo out of a windshield wiper motor, a potentiometer and a motor controller. An Arduino controls the motor controller.

So far I've just got a simple algorithm that will get the motor to within plus or minus 1% of a target value between 0 and 1023. But the time to get on target is fairly slow -- about three seconds to go the full range of the potentiometer. I'd like to do better.

I've seen a suggestion to use a PID algorithm. How exactly would I do that?

Offline marto

  • Jr. Member
  • **
  • Posts: 9
  • Helpful? 1
Re: Making a servo with a PID algorithm
« Reply #1 on: May 06, 2011, 12:02:06 AM »
http://en.wikipedia.org/wiki/PID_controller

Algorithm is shown. Implemented it and then tune the values manually.

I would advise just PD controller (I = 0) unless really necessary. 

Offline DaaniiTopic starter

  • Robot Overlord
  • ****
  • Posts: 138
  • Helpful? 3
Re: Making a servo with a PID algorithm
« Reply #2 on: May 06, 2011, 10:09:27 AM »
Thanks for the link, marto. But what I do not understand is how you work the PID (or PD) algorithm into the code. Do you use the results of the algorithm to drive the motor? In other words, do you use motor speed as the target? I just don't understand how that works.

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: Making a servo with a PID algorithm
« Reply #3 on: May 06, 2011, 11:50:09 AM »
How fast can the motor move? Can it go the travel of the pot (just use a direct DC voltage) any faster than 3sec?

Quote
In other words, do you use motor speed as the target?
No, use the motor position and calculate the position error per unit time. This kinda gives what the speed should be, greater error = move faster.

The Wiki article is fairly theoretical so do some googling for a practical approach (Microchip has at least one App Note with code) and also search the SoR forums for a number of discussions on PID.

Offline DaaniiTopic starter

  • Robot Overlord
  • ****
  • Posts: 138
  • Helpful? 3
Re: Making a servo with a PID algorithm
« Reply #4 on: May 06, 2011, 08:40:14 PM »
How fast can the motor move? Can it go the travel of the pot (just use a direct DC voltage) any faster than 3sec?

At top speed the motor can go from end to end of the potentiometer in about 0.6 seconds. But it overshoots pretty badly at that speed, so to get better performance I had to cut down the speed.

I'll look at the things you suggest and see what I can come up with. They are helpful. Thanks.

Offline BradleyK

  • Beginner
  • *
  • Posts: 6
  • Helpful? 1
Re: Making a servo with a PID algorithm
« Reply #5 on: May 09, 2011, 08:21:44 PM »
look at the arduino PID function

http://www.arduino.cc/playground/Code/PIDLibrary


Offline DaaniiTopic starter

  • Robot Overlord
  • ****
  • Posts: 138
  • Helpful? 3
Re: Making a servo with a PID algorithm
« Reply #6 on: May 09, 2011, 10:35:40 PM »
Thanks, that PID library might be helpful.

Offline TheBadger

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Re: Making a servo with a PID algorithm
« Reply #7 on: May 13, 2011, 04:44:09 PM »
http://www.inpharmix.com/jps/PID_Controller_For_Lego_Mindstorms_Robots.html

this made me understand how PID works, this guy is great.

 


Get Your Ad Here