PID controller (proportional-integral-differential controller)-V

Source: Internet
Author: User

Linear actuator-pid ControlIntroduction

This application-designed to explain the basics of PID control and how to implement a basic control loop using Ph Idgets.

Once implemented, the control loop would allow the linear actuator to move to a precise position and remain there, even if An external-tries to move it.

PID Control BasicsProportional Control

The goal of a control loop is to use data from the feedback device (in this case, the potentiometer) to iteratively adjust The output

Until it has reached the target value.

For example, consider this and control loop (this code would is used in the sensor Change event handler):

Dutycycle = targetposition- actualposition; if  - )     ; if (Dutycycle <-)      =-+;

Whenever the potentiometer value (actualposition) changes, the event handler triggers and updates the Duty Cycle of the MO Tor.

Eventually, this would result in the motor reaching its target. The following table further illustrates how this works:

This diagram illustrates the flow of the simple control loop being implemented.

The function PID () is called, which sets a new duty cycle, which causes the actuator to move.

Eight milliseconds later, the potentiometer that keeps track of what far the actuator have extended causes an analog input C Hange Event,

Which in turn calls PID () again. The cycle continues until the target position is reached.

The type of control we ' ve just implemented here is called Proportional control,

Because the output is directly proportional to the error.

We can multiply (targetposition-actualposition) by a gain value if we want to control how the control loop behaves when It gets close to the target.

A lower value (i.e. less than 1) would result in a further gradual reduction in speed as the actuator reaches its target posit Ion

While a larger value would result in a sharper, quicker response.

We'll call this value of the proportional gain, or Kp for short.

If the proportional gain is set too high, the actuator would overshoot the target position and oscillate back and forth Aro und the target.

While we ' ve gained basic control of the actuator position, there is still some problems with purely proportional control.

You could find the actuator never quite reaches the target position, especially with a low proportional gain.

Also, if the load on the actuator changes while it's moving, it won ' t be able to react to the difference.

To solve these problems, we need a integral term.

Integral Control

The purpose of the integral term in a control loop be-to-look-back at all of the past error

and accumulate it into an offset, the control loop can use.

Combined with our proportional control loop, it'll be able to react to changes on load and land closer

To the target position if we choose our gain values properly.

0.008= targetposition-= (Kp * error) + (Ki *if)       - ; Else if (Dutycycle <-)      =-+; Else       + = (Error * dt);

Where DT is the change in time between iterations of the control loop.

For this example, DT are set to 0.008 seconds, which are the update rate of the analog input.

The integral is only accumulated when the duty cycle isn ' t saturated at 100% or-100%.

This prevents the control loop from needlessly accumulating the integral when it's already running at maximum velocity.

Now we have the control gains: Kp and Ki.

Kp still functions as it does in the proportional example, and Ki controls what influential the integral term is.

Increasing the integral gain would cause the control loop to reach the target faster,

and ensure that's the exact target rather than settling to a value close to the target.

Just like the proportional gain, increasing the integral gain too much can cause instability.

After tweaking the control gains, your may find, PI control was sufficient for your application.

If you ' re have trouble finding control gains that provide the results you ' re looking for, Y

ou can implement full PID control by adding the derivative term.

derivative Control

Derivative control looks at past errors in the system and calculates the slope of those errors to predict future error Val UEs.

Adding derivative control should add stability to the system and increase the control we had over it by Adding another GA In value.

 dt = 0.008  ;error  = targetposition-< Span style= "color: #000000;" > actualposition;dutycycle  = (Kp * error) + (Ki * integral) + (Kd * derivative); if  (dutycycle > 100  ) dutycycle  = 100  ;  else  if  (Dutycycle <-100   =-100  ;  else   integral  + = (Error * DT); derivative  = (err Or-errorlast)/dt; 

Where errorlast is the error value a set number of samples ago.

In a application such as this, a error value from around to samples ago (0.5 seconds) should suffice.

Just as before, we can now use Kd to modify the weight of this new derivative term.

Increasing Kd should smooth things out and increase stability,

But you'll find that it should is kept small in comparison to the other control gains

Or it would cause the control to oscillate when it's near the target.

Sample Program

You can download the "sample program" written for this guide via the link below. This is a Visual C # project.

    • Actuatorpid
Controls and Settings
  1. These boxes contain the information of the attached motor controller. If These boxes is blank, it means the controller object didn ' t successfully attach.
  2. These boxes control which motor output and analog input is being used, and allow you to set each of the control gains. Can click on the '? ' icon in the top right for more information on a particular setting. Changes won't take effect until the "Start" button was hit.
  3. These boxes display the target position set by the slider and the actual position according to the feedback potentiometer. The error is the difference between these values, and the output velocity is the duty cycle of the controller as Dict Ated by the control loop.
  4. The maximum velocity slider controls the maximum duty cycle that the controller would output. It is unrestricted (100%) by default.
  5. This slider selects the target position and from 1 to Sensorvalue of the feedback potentiometer.
  6. Pressing the Start button would initiate the control loop and the actuator would begin to move toward the target position. If The actuator does not move, check your power and connections.
  7. These settings is for actuators whose potentiometers don ' t spans the full range of 0-5V (0-1000 sensorvalue). Experiment with your actuator to discover the potentiometer ' s limits.
  8. This graph would plot the motor's position and the target position over time.  
algorithm

The PID control algorithm in this sample program operates by setting up a change handler for the analog input connected
To the feedback potentiometer, that calls an external function.

This function computes the PID control loop output as briefly described in the previous section.

By changing the output, the motor's duty cycle is set and the function would be called again the next time the sensor Chang E handler triggers

(in 0.008 seconds, because the sampling period of a analog input is 8ms).

This loop would continue until the output of the control loop is zero and at which point the sensor change event would no longe R Trigger.

//The the event handler for the attached feedback sensorvoidActuator_sensorupdate (Objectsender, Sensorupdateeventargs e) {    //If The selected sensor input is the one of that triggered this handler,    if(E.index = =0&& Analogcmb.text = ="0") || (E.index = =1&& Analogcmb.text = ="1"))    {        //Store sensor value in global variableFeedback =E.value; //Run the PID loop        if(started) {PID (); }         //Update the motor controller with the new duty cycleActuator.motors[convert.toint32 (Motorcmb.text)]. Velocity =math.round (output); }}

It's always a good idea to keep your event handlers as small and optimized as possible to avoid missing events.

In this sample program, all of the complexity of the PID algorithm are tucked away in the function "pid ()".

The PID () function:

    • Updates Error variables
    • Checks to see if the actuator have reached its target (and if it has, stops the loop)
    • Updates the the-the-output (duty cycle) of the control loop
    • Limits the duty cycle to the specified output limit
    • Updates the derivative variable

In the downloadable example, this function also updates the graph and all of the text boxes, the variables.

These lines were removed from the excerpt below for increased readability.

//This function does the control system calculations and sets output to the duty cycle, the motor needs to run at.< /c2>voidPID () {//Calculate How far we is from the targetErrorlast =error; Error= Input-feedback; //If The error is within the specified Deadband, and the motor is moving slowly enough,//Or If the motor's target is a physical limit and that limit was hit (within deadband margins),    if(Math.Abs (Error) <= deadband && math.abs (Output) <5)        || (Input < (Deadband +1+ (Double) svmintxt.value) && Feedback < (Deadband +1+ (Double) svmintxt.value))|| (Input > (Double) Svmaxtxt.value-(1+ deadband)) && Feedback > ((Double) Svmaxtxt.value-(1+Deadband))))  {        //Stop The motorOutput =0; Error=0; }    Else    {        //Else, update motor duty cycle with the newest output value//This equation are a simple PID control loopOutput = ((Kp * error) + (Ki * integral)) + (KD *derivative); Errortxt.text=error.    ToString (); }      //Prevent output value from exceeding maximum output specified by user, otherwise accumulate the integral    if(Output >=maxoutput) Output=Maxoutput; Else if(Output <=-maxoutput) Output= -Maxoutput; ElseIntegral+ = (Error *DT); Derivative= (error-errorlast)/DT;}

PID controller (proportional-integral-differential controller)-V

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.