Re: PID in a PIC
Posted by
Alan Marconett KM6VV
on 2000-08-14 11:28:23 UTC
Thanks Dave,
I like the idea of a "rolling" sum for the integral. And your point of
not needing to divide by dt because of the constant interval will save
time. Now to get it all into the PIC. How fast have you been able to
get the algorithm to run? My first thought was to include the PWM for
the R/C servo motor in the same routine, but it is so S L O W (do a .5
to 2.5 ms pulse every 20ms), that I may just put it in another PIC.
Another PIC is slated to do PWM at 5-10 Khz for the drive motors. Idea
is to slow down the drive motors as the turning error comes up.
Alan
Dave Kowalczyk wrote:
I like the idea of a "rolling" sum for the integral. And your point of
not needing to divide by dt because of the constant interval will save
time. Now to get it all into the PIC. How fast have you been able to
get the algorithm to run? My first thought was to include the PWM for
the R/C servo motor in the same routine, but it is so S L O W (do a .5
to 2.5 ms pulse every 20ms), that I may just put it in another PIC.
Another PIC is slated to do PWM at 5-10 Khz for the drive motors. Idea
is to slow down the drive motors as the turning error comes up.
Alan
Dave Kowalczyk wrote:
>
> Alan,
>
> Here's the "meat" of an algorithm I've used for servo modeling in
> Basic. Time intervals for sampling have to be equal for this to work.
>
> 'Find applied voltage based on proportion
> Vapp = (ThetaGoal - Theta) * P
>
> Applied voltage is proportional to error between position and goal
> by a factor "P".
>
> 'Find applied voltage based on derivative
> Vapp = Vapp + ((ThetaGoal - Theta) - (ThetaGoal - Thetaold)) * D
>
> Thetaold is the prior sample of theta (one interval removed). The
> new error minus the old error in one time inteval is the rate of
> change in the error. If the time intevals are always equal, then
> it's not necessary to divide by time. Modify the applied voltage by
> the rate of change multiplied by factor "D".
>
> 'Find applied voltage based on integral
> Ing = Ing + (ThetaGoal - Theta) - Integral(Ip)
> Integral(Ip) = (ThetaGoal - Theta)
> Ip = Ip + 1
> If Ip = 51 Then Ip = 1
> Vapp = Vapp + (I * Ing)
>
> This is a little trickier. The integral in this algorithm is the
> sum of the 50 previous error samplings. Again, the time intervals
> are equal, so no need to multiply by dt. Ing is a rolling sum found
> by adding the current error and subtracting off the error 51 samples
> ago, which is stored in the array Integral(). Then the rolling sum
> (Ing) is modified by factor "I" and added to the applied
> voltage. "I" is usually a small number to avoid oscillation.
>
> Hope this helps! Good luck with your project...
>
> Dave Kowalczyk
> Ames IA
>
> --- In CAD_CAM_EDM_DRO@egroups.com, Tony Jeffree <tony@j...> wrote:
> > It's worth taking a look on the http://www.microchip.com/ website -
> > microchip publish a wide variety of application notes for the PIC
> series,
> > including stuff related to implementing 3-term control algorithms.
> >
> > Regards,
> > Tony
> >
> > At 14:37 10/08/00 -0700, you wrote:
> > >Hi to the List,
> > >
> > >I have been researching PID algorithms, and would like to
> implement a
> > >PID formula in a simple project(?) for my son. The Project is
> a "line
> > >following robot", and what we want to build is a PIC micro
> controller
> > >running a PID calculation. The input "error" is calculated from
> levels
> > >from an array of IR sensors. There are to be three pots digitized
> for
> > >the Kp, Ki & Kd gains. The output of the calculation will be used
> to
> > >control an R/C servo via PWM. The R/C servo steers the robot
> (car).
> > >
> > >The sensors, pots, and PWM stuff is all fine, but in trying to
> implement
> > >the PID calculations, I find that I don't know much about it.
> > >
> > >A PID in a PIC has other obvious uses in CNC.
> > >
> {snip}
>
>
>
> Welcome to CAD_CAM_EDM_DRO@...,an unmoderated list for the discussion of shop built systems, for CAD, CAM, EDM, and DRO.
>
> Addresses:
> Post message: CAD_CAM_EDM_DRO@egroups.com
> Subscribe: CAD_CAM_EDM_DRO-subscribe@egroups.com
> Unsubscribe: CAD_CAM_EDM_DRO-unsubscribe@egroups.com
> List owner: CAD_CAM_EDM_DRO-owner@egroups.com, wanliker@...
> Moderator: jmelson@... [Moderator]
> URL to this page: http://www.egroups.com/group/CAD_CAM_EDM_DRO
> FAQ: http://www.ktmarketing.com/faq.html
> bill,
> List Manager
Discussion Thread
Alan Marconett KM6VV
2000-08-10 14:38:32 UTC
PID in a PIC
Spehro Pefhany
2000-08-10 16:24:18 UTC
Re: [CAD_CAM_EDM_DRO] PID in a PIC
Tony Jeffree
2000-08-13 13:34:53 UTC
Re: [CAD_CAM_EDM_DRO] PID in a PIC
Dave Kowalczyk
2000-08-14 06:21:52 UTC
Re: PID in a PIC
Alan Marconett KM6VV
2000-08-14 11:28:23 UTC
Re: PID in a PIC
Dave Kowalczyk
2000-08-29 20:06:40 UTC
Re: PID in a PIC