May your shirts be full of buttons, yours inspiration be plentiful, and your error messages be few. - Barry Bonzack [more]
 Chief Delphi PID Control algorithm(to control PWM Duty Cycle based on Current)
 CD-Media CD-Spy
 portal register members calendar search Today's Posts Mark Forums Read FAQ rules

#1
06-13-2012, 05:39 AM
 PID Registered User no team Join Date: Jun 2012 Location: asia Posts: 2
PID Control algorithm(to control PWM Duty Cycle based on Current)

Hi All,

How to arrive at a proportional gain Kp and ki in a PI control algorithm? We have to control the PWM Duty Cycle to a motor based up on the current drawn by the motor. If the desired current is 5A, & if we measure current as 6A, then how will we know what should be the duty cycle to get the desired current. Because most of the explanation on the web says that desired - measured * Kp gives the duty cycle. How to convert the error which is in terms of current to duty cycle. More over, the current is varying at different voltage levels, i.e the measured current for a 70% and 60% duty cycle at 10V is different than the measured current for 70% and 60% dty cycle at 12V.
#2
06-13-2012, 08:35 AM
 efoote868 foote stepped in AKA: E. Foote FRC #0868 Team Role: Mentor Join Date: Mar 2006 Rookie Year: 2005 Location: Noblesville, IN Posts: 1,768
Re: PID Control algorithm(to control PWM Duty Cycle based on Current)

The conversion units from amps to duty cycle is included in the constant values Kp and Ki.

e.g. (6A - 5A) * (Kp %/A) = Kp%

To get the duty cycle, add all components:

(error * Kp) + (integrated error * Ki) = duty cycle.

The constants Kp and Ki are usually determined experimentally, through trial and error. I would recommend tuning your motor at a constant voltage to determine Kp (start with Ki = 0), and then changing the voltage to determine Ki.
#3
06-13-2012, 11:25 PM
 PID Registered User no team Join Date: Jun 2012 Location: asia Posts: 2
Re: PID Control algorithm(to control PWM Duty Cycle based on Current)

Hi,

We are trying as u said tuning KP but we see lot of oscillation in the current output.

Thanks
#4
06-14-2012, 07:18 AM
 efoote868 foote stepped in AKA: E. Foote FRC #0868 Team Role: Mentor Join Date: Mar 2006 Rookie Year: 2005 Location: Noblesville, IN Posts: 1,768
Re: PID Control algorithm(to control PWM Duty Cycle based on Current)

You might want to consider using a feedback loop instead of strictly PID.

Think of it this way - when the error drops to zero, you don't want to set your Duty Cycle to zero, you want to keep it exactly the same.

New Duty Cycle = Old Duty Cycle + Error * Constant.
#5
06-14-2012, 08:44 AM
 Ether systems engineer (retired) no team Join Date: Nov 2009 Rookie Year: 1969 Location: US Posts: 9,126
Re: PID Control algorithm(to control PWM Duty Cycle based on Current)

Quote:
 Originally Posted by efoote868 You might want to consider using a feedback loop instead of strictly PID.
PID uses feedback

Quote:
 Think of it this way - when the error drops to zero, you don't want to set your Duty Cycle to zero, you want to keep it exactly the same.
That's what the "I" in PID is for.

#6
06-14-2012, 11:10 AM
 efoote868 foote stepped in AKA: E. Foote FRC #0868 Team Role: Mentor Join Date: Mar 2006 Rookie Year: 2005 Location: Noblesville, IN Posts: 1,768
Re: PID Control algorithm(to control PWM Duty Cycle based on Current)

Thanks Ether, I originally had it in my mind that the proportional error would be the driving force in the system, but focusing on I should work better.

I should have wrote P instead of PID.
#7
06-14-2012, 03:04 PM
 DonRotolo Getting ready for the break FRC #0832 Team Role: Mentor Join Date: Jan 2005 Rookie Year: 2005 Location: Atlanta GA Posts: 7,344
Re: PID Control algorithm(to control PWM Duty Cycle based on Current)

Oscillations are a result of a functioning PID loop that is not properly tuned. Play with multipliers for P and I to gauge their effect, as a prelude to proper tuning. Start with 1 for P and 0 for I, and work from there.

P gives you a direction and magnitude for your correction towards setpoint.
I takes care of long-term error, allowing the value to creep towards setpoint when P is small.
D keeps the correction from happening too fast.
__________________

I am N2IRZ - What's your callsign?
#8
06-14-2012, 03:45 PM
 Chris Hibner Eschewing Obfuscation Since 1990 AKA: Lars Kamen's Roadie FRC #0051 (Wings of Fire (on sabbatical)) Team Role: Engineer Join Date: May 2001 Rookie Year: 1997 Location: Canton, MI Posts: 1,507
Re: PID Control algorithm(to control PWM Duty Cycle based on Current)

Quote:
 Originally Posted by PID Hi, Thanks for your reply. We are trying as u said tuning KP but we see lot of oscillation in the current output. Thanks
If it's oscillating, KP is too big.

Keep cutting it in half until it stops oscillating, then bring it up slowly until it just starts to oscillate.
__________________
-
An ounce of perception is worth a pound of obscure.
#9
06-20-2012, 08:59 AM
 FrankJ Robot Mentor FRC #2974 (WALT) Team Role: Mentor Join Date: Feb 2011 Rookie Year: 2009 Location: Marietta GA Posts: 2,441
Re: PID Control algorithm(to control PWM Duty Cycle based on Current)

Realizing if you put 3 controls engineers in a room you will get 4 different way to do tuning. One way to empirically tune a PID.
1) with the Ki & Kd gains set at 0. increase the Kp until the process value, PV, (in your case current) starts to oscillate. Do not confuse noise with oscillation, although the more noise the slower your PID will have to be. Kp will never get you to the set point unless you add a manual offset to the output. Set Kp to about half of that.
2)keeping Kp set to the value in step 1, Do the same to Ki. This will give you starting values that you can tweak to your hearts content.
3)Kd stands for destabling. Most of the time I leave it at 0. But on some systems it can be useful. Start small & work up.
4)Test your tuning by making a step change to set point and watch how it responds. Over tuned will oscillate wildly. Under tuned, it will slowly reach set point with out any over shoot. Classically tuned it will over shoot and then settle on set point with decreasing oscillation.
#10
06-20-2012, 10:38 AM
 Hugh Meyer Registered User FRC #1741 (Red Alert Robotics) Team Role: Mentor Join Date: Feb 2009 Rookie Year: 2008 Location: Greenwood Indiana Posts: 168
Re: PID Control algorithm(to control PWM Duty Cycle based on Current)

http://igor.chudov.com/manuals/Servo...hout-a-PhD.pdf

-Hugh

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     User Announcements FIRST     General Forum         FIRST E-Mail Blast Archive     Rumor Mill     Career     Robot Showcase Technical     Technical Discussion     Robotics Education and Curriculum     Motors     Electrical         CAN     Programming         NI LabVIEW         C/C++         Java         Python     Control System         FRC Control System         Sensors     Pneumatics     Kit & Additional Hardware     CAD         Inventor         SolidWorks         Creo     IT / Communications         3D Animation and Competition         Website Design/Showcase         Videography and Photography         Computer Graphics     National Instruments LabVIEW and Data Acquisition         LabView and Data Acquisition Competition     Unsung FIRST Heroes     Awards         Chairman's Award     Rules/Strategy         Scouting         You Make The Call     Team Organization         Fundraising         Starting New Teams         Finding A Team         College Teams     Championship Event     Regional Competitions     District Events     Off-Season Events     Thanks and/or Congrats     FRC Game Design     OCCRA         OCCRA Q&A         OCCRA Programming Other     Chit-Chat         Games/Trivia             Fantasy FIRST     Car Nack's Corner     College & University Education     Dean Kamen's Inventions     FIRST-related Organizations         Western Region Robotics Forum         Southern California Regional Robotics Forum         The Blue Alliance             Video Archives     FIRST In the News...     FIRST Lego League         Lego Mindstorm Discussion     FIRST Tech Challenge     VEX         VEX Robotics Competition         VEX IQ     Televised Robotics     Math and Science         NASA Discussion ChiefDelphi.com Website     CD Forum Support     Extra Discussion

All times are GMT -5. The time now is 01:04 PM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.

 -- English (12 hour) -- English (24 hour) Contact Us - Chief Delphi - Rules - Archive - Top