"Getting Started with smart cars"-location-and incremental-PID implementation code

Source: Internet
Author: User

PID control is the most common algorithm in the production of intelligent car, it mainly divided into two kinds: position and increment. The following is a discussion of the characteristics of these two types of PID and code implementation.


1. Position-type PID

Features: position pid is used to integrate all the error values in the past, so it is related to the whole state of the past.

Code implementation:

typedef struct PID//define struct body

{

float LastError; Last Error

float Sumerror; Error integral term

} PID;

Static PID SPID;

Static PID *sptr=&spid;

void Pid_init (void)//pointer initialization

{

Sptr->lasterror = 0;

Sptr->sumerror = 0;

}

Float Pidcalc (float nextpoint)

{

float Derror,error;

Error = Setpoint-nextpoint; Deviation

Sptr->sumerror + = Error; Integral

Derror = error-sptr->preverror; Current differential

Sptr->lasterror = Error;

Return (kp* Error//scale item

+ki * Sptr->sumerror//Points

+kd* derror); Differential term

}

   

 

 

 

2. Incremental PID


Features: the increment of PID output is the increment of control quantity, the influence of misoperation is small

Code implementation:

Typedefstruct PID

{

float V_lasterror; ERROR[-1]

float V_preserror; Error[-2]

}pid;

Staticpid SPID;

Staticpid *sptr=&spid;

Voidpid_init (void)//pointer initialization

{

Sptr->v_lasterror = 0; ERROR[-1]

Sptr->v_preserror = 0; Error[-2]

}

Voidpid_caculate (U16 set_value,float Get_value)

{

float g_fdirectioncontrolout1=0;

V_error=get_value-set_value;

g_fdirectioncontrolout1= P * (v_error-sptr->v_lasterror) + I * v_error + D (V_ERROR-2*SPTR-&G T V_LASTERROR+SPTR->V_PRESERROR);//calculate current output increment

Sptr->v_preserror =sptr->v_lasterror; Storage error, for next calculation

Sptr->v_lasterror = V_error;

G_fdirectioncontrolout2 + = g_fdirectioncontrolout1;//Last output plus current output increment

G_fdirectioncontroloutold = g_fdirectioncontroloutnew;

G_fdirectioncontroloutnew =g_fdirectioncontrolout2;

}

 

The choice of P, I, d three links, generally only use PI control or PD control, such as speed control requires steady state error, then the integral link, so the use of Pi control, and the use of direction control, because there is no need for steady state error, so the use of PD control can be, The function of D is to eliminate the oscillation caused by the P link.

 

Contact Us
Taobao shop    : http://shop60443799.taobao.com/
Technical Exchange QQ Group:108190422    Camera Group
                      132879827    PV Group
                      118404899    Electromagnetic Group
Technical Exchange mailbox  : DEMOK@VIP.QQ.COM 
Technical Forum    : http://blog.csdn.net/demok2010
Official website    :  www.demok.com.cn

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.