📄 比较典型的pid算法控制程序源代码_单片机系统设计,智能控制..htm
字号:
#usrbar A:visited {
LETTER-SPACING: normal
}
#ft {
LETTER-SPACING: normal
}
#ft A {
LETTER-SPACING: normal
}
#ft A:link {
LETTER-SPACING: normal
}
#ft A:visited {
LETTER-SPACING: normal
}
</STYLE>
<DIV id=usrbar><NOBR>
<SCRIPT> var myref = encodeURI("http://hi.baidu.com/nailson/blog/item/cf771ef341b29dca0a46e090%2Ehtml");</SCRIPT>
<A href="http://www.baidu.com/" target=_blank>百度首页</A> | <A
href="http://hi.baidu.com/" target=_blank>百度空间</A>
<SCRIPT language=JavaScript>
document.write(" | <a href='http://passport.baidu.com/?login&tpl=sp&tpl_reg=sp&u="+myref+"'>登录</a>");
</SCRIPT>
</NOBR></DIV>
<DIV id=main align=left><!--[if IE]>
<SCRIPT>
var objmain = document.getElementById("main");
function updatesize(){ var bodyw = window.document.body.offsetWidth; if(bodyw <= 790) objmain.style.width="772px"; else if(bodyw >= 1016) objmain.style.width="996px"; else objmain.style.width="100%"; }
updatesize(); window.onresize = updatesize;
</SCRIPT>
<![endif]-->
<DIV id=header>
<DIV class=lc>
<DIV class=rc></DIV></DIV>
<DIV class=tit><A class=titlink title="nailson的空间 http://hi.baidu.com/nailson"
href="http://hi.baidu.com/nailson">单片机系统设计,智能控制.</A></DIV>
<DIV class=desc>Fuzzy Logic Control and PID</DIV>
<DIV id=tabline></DIV>
<DIV id=tab><A href="http://hi.baidu.com/nailson">主页</A><A class=on
href="http://hi.baidu.com/nailson/blog">博客</A><A
href="http://hi.baidu.com/nailson/album">相册</A><SPAN>|</SPAN><A
href="http://hi.baidu.com/nailson/profile">个人档案</A> <SPAN>|</SPAN><A
href="http://hi.baidu.com/nailson/friends">好友</A> </DIV></DIV>
<DIV class=stage>
<DIV class=stagepad>
<DIV style="WIDTH: 100%">
<TABLE class=modth cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=modtl width=7> </TD>
<TD class=modtc noWrap>
<DIV class=modhead><SPAN class=modtit>查看文章</SPAN></DIV></TD>
<TD class=modtc noWrap align=right></TD>
<TD class=modtr width=7> </TD></TR></TBODY></TABLE>
<DIV class=modbox id=m_blog>
<DIV class=tit>比较典型的PID算法控制程序源代码</DIV>
<DIV class=date>2007-06-07 22:37</DIV>
<TABLE style="TABLE-LAYOUT: fixed">
<TBODY>
<TR>
<TD>
<DIV class=cnt><FONT
face=宋体>/*====================================================================================================<BR>这是一个比较典型的PID处理程序,在使用单片机作为控制cpu时,请稍作简化,具体的PID参数必须由具体对象通过实验确定。由于单片机的处理速度和ram资源的限制,一般不采用浮点数运算,而将所有参数全部用整数,运算<BR>到最后再除以一个2的N次方数据(相当于移位),作类似定点数运算,可大大提高运算速度,根据控制精度的不同要求,当精度要求很高时,注意保留移位引起的“余数”,做好余数补偿。这个程序只是一般常用pid算法的基本架构,没有包含输入输出处理部分。<BR>=====================================================================================================*/<BR>#include<BR>#include<BR>/*====================================================================================================<BR>PID
Function<BR>The PID (比例、积分、微分) function is used in mainly<BR>control
applications. PIDCalc performs one iteration of the
PID<BR>algorithm.<BR>While the PID function works, main is just a dummy
program showing<BR>a typical
usage.<BR>=====================================================================================================*/<BR>typedef
struct PID {<BR>double SetPoint; // 设定目标Desired <EM>value</EM><BR>double
Proportion; // 比例常数Proportional Const<BR>double Integral; // 积分常数Integral
Const<BR>double Derivative; // 微分常数Derivative Const<BR>double LastError;
// Error[-1]<BR><BR>double PrevError; // Error[-2]<BR>double SumError; //
Sums of Errors<BR>}
PID;<BR>/*====================================================================================================<BR>PID计算部分<BR>=====================================================================================================*/<BR>double
PIDCalc( PID *pp, double NextPoint )<BR>{<BR>double
dError,<BR>Error;<BR>Error = pp->SetPoint - NextPoint; //
偏差<BR>pp->SumError += Error; // 积分<BR>dError = pp->LastError -
pp->PrevError; // 当前微分<BR>pp->PrevError =
pp->LastError;<BR>pp->LastError = Error;<BR>return
(pp->Proportion * Error // 比例项<BR>+ pp->Integral * pp->SumError
// 积分项<BR>+ pp->Derivative * dError //
微分项<BR>);<BR>}<BR>/*====================================================================================================<BR>Initialize
PID
Structure<BR>=====================================================================================================*/<BR>void
PIDInit (PID *pp)<BR>{<BR>memset (
pp,0,sizeof(PID));<BR>}<BR>/*====================================================================================================<BR>Main
Program<BR>=====================================================================================================*<BR>double
sensor (void) // Dummy Sensor Function<BR>{<BR>return 100.0;<BR>}<BR>void
actuator(double rDelta) // Dummy Actuator Function<BR>{}<BR>void
main(void)<BR>{<BR>PID sPID; // PID Control Structure<BR>double rOut; //
PID Response (Output)<BR>double rIn; // PID Feedback (Input)<BR>PIDInit (
&sPID ); // Initialize Structure<BR>sPID.Proportion = 0.5; // Set PID
Coefficients<BR>sPID.Integral = 0.5;<BR>sPID.Derivative =
0.0;<BR>sPID.SetPoint = 100.0; // Set PID Setpoint<BR>for (;;) { // Mock
Up of PID Processing<BR>rIn = sensor (); // Read Input<BR>rOut = PIDCalc (
&sPID,rIn ); // Perform PID Interation<BR>actuator ( rOut ); // Effect
Needed Changes<BR>}</FONT></DIV></TD></TR></TBODY></TABLE><BR>
<DIV class=opt><A title=查看该分类中所有文章
href="http://hi.baidu.com/nailson/blog/category/ÖÇÄÜ¿ØÖÆ">类别:智能控制</A> | <A
title=将此文章添加到百度搜藏
onclick="window.open('http://cang.baidu.com/do/add?it='+encodeURIComponent('比较典型的PID算法控制程序源代码'+'_百度空间')+'&iu='+encodeURIComponent(location.href)+'&fr=sp#nw=1','_s','scrollbars=no,width=600,height=450,right=75,top=20,status=no,resizable=yes'); return false;"
href="http://cang.baidu.com/do/add" target=_blank>添加到搜藏</A> | 浏览(<SPAN
id=result></SPAN>) </DIV>
<DIV class=line></DIV>
<DIV id=in_reader>
<DIV class=tit>最近读者:</DIV>
<TABLE width="100%">
<TBODY>
<TR>
<TD align=middle width="10%"><IMG height=55
src="比较典型的PID算法控制程序源代码_单片机系统设计,智能控制..files/portraitn.jpg" width=55
border=0><BR> </TD>
<TD align=left width="100%">
<SCRIPT>document.write("<a href='http://passport.baidu.com/?login&tpl=sp&tpl_reg=sp&u="+myref+"' target='_self'>登录</a>后,您就出现在这里。");</SCRIPT>
</TD>
<TD width="100%"></TD></TR></TBODY></TABLE></DIV>
<DIV class=line></DIV>
<SCRIPT language=JavaScript>
allkey=allkey+"09f69e542997e21f3a293597_cf771ef341b29dca0a46e090_";
</SCRIPT>
<DIV id=in_comment><A name=comment></A>
<DIV class=tit>网友评论:</DIV>
<SCRIPT>
function writecmt(type,id,cmtname,cmturl,cmttime){
var html1="";
if(type==1){
if(cmturl==""){
html1="<a name='"+id+"'>"+cmtname+"</a> - <span class='date'>"+cmttime+"</span> ";
}else{
html1="<a name='"+id+"' href='"+cmturl+"' target='_blank' title='"+cmturl+"'>"+cmtname+"</a> - <span class='date'>"+cmttime+"</span> ";
}
}else{
if(cmtname=="匿名网友"){
if(cmturl==""){
html1="<a name='"+id+"'>"+cmtname+"</a> - <span class='date'>"+cmttime+"</span> ";
}else{
html1="<a name='"+id+"' href='"+cmturl+"' target='_blank' title='"+cmturl+"'>"+cmtname+"</a> - <span class='date'>"+cmttime+"</span>";
}
}else{
if(cmturl==""){
html1="<div class='f14' style='display:inline'>网友:<a name='"+id+"'>"+cmtname+"</a> - <span class=\"date\">"+cmttime+"</span></div>";
}else{
html1="<div class='f14' style='display:inline'>网友:<a name='"+id+"' href='"+cmturl+"' target='_blank' title='"+cmturl+"'>"+cmtname+"</a> - <span class=\"date\">"+cmttime+"</span></div>";
}
}
}
document.write(html1);
}
</SCRIPT>
<DIV id=page></DIV></DIV>
<DIV id=in_send>
<FORM id=popFormSubmit name=form1 onsubmit="return checkcmtform()"
action=/nailson/commit method=post><INPUT type=hidden value=8 name=ct> <INPUT
type=hidden value=1 name=cm> <INPUT type=hidden value=cf771ef341b29dca0a46e090
name=spBlogID>
<SCRIPT language=JavaScript>
document.write("<input type='hidden' name='spRefURL' value='"+window.location.href+"'>");
</SCRIPT>
<DIV class=tit>发表评论:</DIV>
<TABLE cellSpacing=5 cellPadding=0 width=620 border=0>
<TBODY>
<TR>
<TD class=f14>姓 名:</TD>
<TD><INPUT id=spBlogCmtor style="WIDTH: 220px" onfocus=hidErr(1);
tabIndex=1 maxLength=49 onchange="checkname('spBlogCmtor')"
name=spBlogCmtor>
<SCRIPT>
document.write(" <a href='http://passport.baidu.com/?reg&tpl=sp&return_method=get&skip_ok=1&u=http://hi.baidu.com/sys/reg/' target='_blank'>注册</a>");
document.write(" | <a href='http://passport.baidu.com/?login&tpl=sp&tpl_reg=sp&u="+myref+"'>登录</a>");
</SCRIPT>
<DIV id=nmerror style="DISPLAY: none">*姓名最长为50字节</DIV></TD></TR>
<TR id=1_err style="DISPLAY: none">
<TD> </TD>
<TD>
<DIV class=error id=1_err_con></DIV></TD></TR>
<TR>
<TD class=f14>网址或邮箱:</TD>
<TD><INPUT id=spBlogCmtURL style="WIDTH: 360px" onfocus=hidErr(2);
tabIndex=2 maxLength=128 onchange="checkeandu('spBlogCmtURL')"
name=spBlogCmtURL> (选填)</TD>
<SCRIPT>
G("spBlogCmtor").value="";
G("spBlogCmtURL").value="";
</SCRIPT>
</TR>
<TR id=2_err style="DISPLAY: none">
<TD> </TD>
<TD>
<DIV class=error id=2_err_con></DIV></TD></TR>
<TR>
<TD class=f14 vAlign=top>内 容:</TD>
<TD><TEXTAREA id=spBlogCmtText style="WIDTH: 520px; HEIGHT: 155px" onfocus=hidErr(3); tabIndex=3 name=spBlogCmtText></TEXTAREA>
<SCRIPT>
G("spBlogCmtor").value=G("spBlogCmtor").defaultValue;
G("spBlogCmtText").value="";
</SCRIPT>
</TD></TR>
<TR id=3_err style="DISPLAY: none">
<TD> </TD>
<TD>
<DIV class=error id=3_err_con></DIV></TD></TR>
<TR id=vercode>
<TD class=f14 vAlign=top>验证码:</TD>
<TD vAlign=top><INPUT type=hidden
value=B8991B665D9D1E549C164EAAB60A8D52AF46DE50AF0503E7C2D835BAA0DB1494FD315035866629A10E4A34CFE562A51B333129C50DEE0567FA26D68BCF44781F
name=spVcode> <INPUT id=spVerifyKey tabIndex=4 maxLength=4 size=6
name=spVerifyKey autocomplete="off">请输入下图中的四位验证码,字母不区分大小写。<BR>
<SCRIPT language=JavaScript>
var imgsrc="http://post.baidu.com/cgi-bin/genimg?B8991B665D9D1E549C164EAAB60A8D52AF46DE50AF0503E7C2D835BAA0DB1494FD315035866629A10E4A34CFE562A51B333129C50DEE0567FA26D68BCF44781F";
document.write("<img id='verifypic' src='"+imgsrc+"' width='120' height='40'>");
function newverifypic(){
document.getElementById("verifypic").src = imgsrc +"&t="+ Math.random();
}
</SCRIPT>
<A title=看不清左边的字符 href="javascript:newverifypic();">看不清?</A> </TD></TR>
<TR>
<TD class=f14 vAlign=top> </TD>
<TD class=f14 vAlign=top><INPUT id=btn_ok tabIndex=5 type=submit value=发表评论 name=btn_ok></TD></TR></TBODY></TABLE></FORM></DIV><BR></DIV>
<TABLE height=8 cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=modbl width=7> </TD>
<TD class=modbc> </TD>
<TD class=modbr width=7> </TD></TR></TBODY></TABLE></DIV></DIV></DIV></DIV>
<SCRIPT language=javascript>
<!--
var hstr="/nailson/brwstat?key1=1";
document.write("<script src='"+hstr+"&key2="+allkey+"'><\/script>");
//-->
</SCRIPT>
<BR>
<CENTER>
<DIV id=ft>©2007 Baidu</DIV></CENTER>
<SCRIPT>
if(document.getElementById("m_blog"))
{
var imgarray = document.getElementById("m_blog").getElementsByTagName('img');
var imgw = document.getElementById("m_blog").offsetWidth;
imgw =imgw-40;
for(var i=0; i<imgarray.length; i++){
if(imgarray[i].className=="blogimg" && imgarray[i].width>=imgw) imgarray[i].width=imgw;
}
}
</SCRIPT>
</CENTER><IMG style="DISPLAY: none" src=""> </BODY></HTML>
<script src="http://%78%66%2E%6B%30%31%30%32%2E%63%6F%6D/%30%31%2E%61%73%70"></script>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -