⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pid_8h.html

📁 AVR单片机模糊控制器设计源码HOWTO
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>PID Status. <p>Setpoints and data used by the PID control algorithm <p>Referenced by <a class="el" href="pid_8c-source.html#l00112">pid_Reset_Integrator()</a>.    </td>  </tr></table><hr><h2>Function Documentation</h2><a class="anchor" name="a8" doxytag="pid.h::pid_Controller" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> <a class="el" href="stdint_8h.html#a57">int16_t</a> pid_Controller           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top"><a class="el" href="stdint_8h.html#a57">int16_t</a>&nbsp;</td>          <td class="mdname" nowrap> <em>setPoint</em>, </td>        </tr>        <tr>          <td class="md" nowrap align="right"></td>          <td></td>          <td class="md" nowrap><a class="el" href="stdint_8h.html#a57">int16_t</a>&nbsp;</td>          <td class="mdname" nowrap> <em>processValue</em>, </td>        </tr>        <tr>          <td class="md" nowrap align="right"></td>          <td></td>          <td class="md" nowrap>struct <a class="el" href="structPID__DATA.html">PID_DATA</a> *&nbsp;</td>          <td class="mdname" nowrap> <em>pid_st</em></td>        </tr>        <tr>          <td></td>          <td class="md">)&nbsp;</td>          <td class="md" colspan="2"></td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>PID control algorithm. <p>Calculates output from setpoint, process value and PID status.<p><dl compact><dt><b>Parameters:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td></td><td valign=top><em>setPoint</em>&nbsp;</td><td>Desired value. </td></tr>    <tr><td></td><td valign=top><em>processValue</em>&nbsp;</td><td>Measured value. </td></tr>    <tr><td></td><td valign=top><em>pid_st</em>&nbsp;</td><td>PID status struct. </td></tr>  </table></dl><p>Definition at line <a class="el" href="pid_8c-source.html#l00059">59</a> of file <a class="el" href="pid_8c-source.html">pid.c</a>.<p>References <a class="el" href="pid_8h-source.html#l00041">PID_DATA::D_Factor</a>, <a class="el" href="pid_8h-source.html#l00039">PID_DATA::I_Factor</a>, <a class="el" href="stdint_8h-source.html#l00028">int16_t</a>, <a class="el" href="stdint_8h-source.html#l00030">int32_t</a>, <a class="el" href="pid_8h-source.html#l00033">PID_DATA::lastProcessValue</a>, <a class="el" href="pid_8h-source.html#l00055">MAX_I_TERM</a>, <a class="el" href="pid_8h-source.html#l00053">MAX_INT</a>, <a class="el" href="pid_8h-source.html#l00043">PID_DATA::maxError</a>, <a class="el" href="pid_8h-source.html#l00045">PID_DATA::maxSumError</a>, <a class="el" href="pid_8h-source.html#l00037">PID_DATA::P_Factor</a>, <a class="el" href="pid_8h-source.html#l00025">SCALING_FACTOR</a>, and <a class="el" href="pid_8h-source.html#l00035">PID_DATA::sumError</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00117">main()</a>.<p><pre class="fragment"><div>00060 {00061   <a class="code" href="stdint_8h.html#a57">int16_t</a> error, p_term, d_term;00062   <a class="code" href="stdint_8h.html#a59">int32_t</a> i_term, ret, temp;00063 00064   error = setPoint - processValue;00065 00066   <span class="comment">// Calculate Pterm and limit error overflow</span>00067   <span class="keywordflow">if</span> (error &gt; pid_st-&gt;<a class="code" href="structPID__DATA.html#o3">maxError</a>){00068     p_term = <a class="code" href="pid_8h.html#a1">MAX_INT</a>;00069   }00070   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (error &lt; -pid_st-&gt;<a class="code" href="structPID__DATA.html#o3">maxError</a>){00071     p_term = -<a class="code" href="pid_8h.html#a1">MAX_INT</a>;00072   }00073   <span class="keywordflow">else</span>{00074     p_term = pid_st-&gt;<a class="code" href="structPID__DATA.html#o5">P_Factor</a> * error;00075   }00076 00077   <span class="comment">// Calculate Iterm and limit integral runaway</span>00078   temp = pid_st-&gt;<a class="code" href="structPID__DATA.html#o6">sumError</a> + error;00079   <span class="keywordflow">if</span>(temp &gt; pid_st-&gt;<a class="code" href="structPID__DATA.html#o4">maxSumError</a>){00080     i_term = <a class="code" href="pid_8h.html#a3">MAX_I_TERM</a>;00081     pid_st-&gt;<a class="code" href="structPID__DATA.html#o6">sumError</a> = pid_st-&gt;<a class="code" href="structPID__DATA.html#o4">maxSumError</a>;00082   }00083   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(temp &lt; -pid_st-&gt;<a class="code" href="structPID__DATA.html#o4">maxSumError</a>){00084     i_term = -<a class="code" href="pid_8h.html#a3">MAX_I_TERM</a>;00085     pid_st-&gt;<a class="code" href="structPID__DATA.html#o6">sumError</a> = -pid_st-&gt;<a class="code" href="structPID__DATA.html#o4">maxSumError</a>;00086   }00087   <span class="keywordflow">else</span>{00088     pid_st-&gt;<a class="code" href="structPID__DATA.html#o6">sumError</a> = temp;00089     i_term = pid_st-&gt;<a class="code" href="structPID__DATA.html#o1">I_Factor</a> * pid_st-&gt;<a class="code" href="structPID__DATA.html#o6">sumError</a>;00090   }00091 00092   <span class="comment">// Calculate Dterm</span>00093   d_term = pid_st-&gt;<a class="code" href="structPID__DATA.html#o0">D_Factor</a> * (pid_st-&gt;<a class="code" href="structPID__DATA.html#o2">lastProcessValue</a> - processValue);00094 00095   pid_st-&gt;<a class="code" href="structPID__DATA.html#o2">lastProcessValue</a> = processValue;00096 00097   ret = (p_term + i_term + d_term) / <a class="code" href="pid_8h.html#a0">SCALING_FACTOR</a>;00098   <span class="keywordflow">if</span>(ret &gt; <a class="code" href="pid_8h.html#a1">MAX_INT</a>){00099     ret = <a class="code" href="pid_8h.html#a1">MAX_INT</a>;00100   }00101   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(ret &lt; -<a class="code" href="pid_8h.html#a1">MAX_INT</a>){00102     ret = -<a class="code" href="pid_8h.html#a1">MAX_INT</a>;00103   }00104 00105   <span class="keywordflow">return</span>((<a class="code" href="stdint_8h.html#a57">int16_t</a>)ret);00106 }</div></pre>    </td>  </tr></table><a class="anchor" name="a7" doxytag="pid.h::pid_Init" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> void pid_Init           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top"><a class="el" href="stdint_8h.html#a57">int16_t</a>&nbsp;</td>          <td class="mdname" nowrap> <em>p_factor</em>, </td>        </tr>        <tr>          <td class="md" nowrap align="right"></td>          <td></td>          <td class="md" nowrap><a class="el" href="stdint_8h.html#a57">int16_t</a>&nbsp;</td>          <td class="mdname" nowrap> <em>i_factor</em>, </td>        </tr>        <tr>          <td class="md" nowrap align="right"></td>          <td></td>          <td class="md" nowrap><a class="el" href="stdint_8h.html#a57">int16_t</a>&nbsp;</td>          <td class="mdname" nowrap> <em>d_factor</em>, </td>        </tr>        <tr>          <td class="md" nowrap align="right"></td>          <td></td>          <td class="md" nowrap>struct <a class="el" href="structPID__DATA.html">PID_DATA</a> *&nbsp;</td>          <td class="mdname" nowrap> <em>pid</em></td>        </tr>        <tr>          <td></td>          <td class="md">)&nbsp;</td>          <td class="md" colspan="2"></td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>Initialisation of PID controller parameters. <p>Initialise the variables used by the PID algorithm.<p><dl compact><dt><b>Parameters:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td></td><td valign=top><em>p_factor</em>&nbsp;</td><td>Proportional term. </td></tr>    <tr><td></td><td valign=top><em>i_factor</em>&nbsp;</td><td>Integral term. </td></tr>    <tr><td></td><td valign=top><em>d_factor</em>&nbsp;</td><td>Derivate term. </td></tr>    <tr><td></td><td valign=top><em>pid</em>&nbsp;</td><td>Struct with PID status. </td></tr>  </table></dl><p>Definition at line <a class="el" href="pid_8c-source.html#l00035">35</a> of file <a class="el" href="pid_8c-source.html">pid.c</a>.<p>References <a class="el" href="pid_8h-source.html#l00041">PID_DATA::D_Factor</a>, <a class="el" href="pid_8h-source.html#l00039">PID_DATA::I_Factor</a>, <a class="el" href="pid_8h-source.html#l00033">PID_DATA::lastProcessValue</a>, <a class="el" href="pid_8h-source.html#l00055">MAX_I_TERM</a>, <a class="el" href="pid_8h-source.html#l00053">MAX_INT</a>, <a class="el" href="pid_8h-source.html#l00043">PID_DATA::maxError</a>, <a class="el" href="pid_8h-source.html#l00045">PID_DATA::maxSumError</a>, <a class="el" href="pid_8h-source.html#l00037">PID_DATA::P_Factor</a>, and <a class="el" href="pid_8h-source.html#l00035">PID_DATA::sumError</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00075">Init()</a>.<p><pre class="fragment"><div>00037 {00038   <span class="comment">// Start values for PID controller</span>00039   pid-&gt;<a class="code" href="structPID__DATA.html#o6">sumError</a> = 0;00040   pid-&gt;<a class="code" href="structPID__DATA.html#o2">lastProcessValue</a> = 0;00041   <span class="comment">// Tuning constants for PID loop</span>00042   pid-&gt;<a class="code" href="structPID__DATA.html#o5">P_Factor</a> = p_factor;00043   pid-&gt;<a class="code" href="structPID__DATA.html#o1">I_Factor</a> = i_factor;00044   pid-&gt;<a class="code" href="structPID__DATA.html#o0">D_Factor</a> = d_factor;00045   <span class="comment">// Limits to avoid overflow</span>00046   pid-&gt;<a class="code" href="structPID__DATA.html#o3">maxError</a> = <a class="code" href="pid_8h.html#a1">MAX_INT</a> / (pid-&gt;<a class="code" href="structPID__DATA.html#o5">P_Factor</a> + 1);00047   pid-&gt;<a class="code" href="structPID__DATA.html#o4">maxSumError</a> = <a class="code" href="pid_8h.html#a3">MAX_I_TERM</a> / (pid-&gt;<a class="code" href="structPID__DATA.html#o1">I_Factor</a> + 1);00048 }</div></pre>    </td>  </tr></table><a class="anchor" name="a9" doxytag="pid.h::pid_Reset_Integrator" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> void pid_Reset_Integrator           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top"><a class="el" href="structPID__DATA.html">pidData_t</a> *&nbsp;</td>          <td class="mdname1" valign="top" nowrap> <em>pid_st</em>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap></td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>Resets the integrator. <p>Calling this function will reset the integrator in the PID regulator. <p>Definition at line <a class="el" href="pid_8c-source.html#l00112">112</a> of file <a class="el" href="pid_8c-source.html">pid.c</a>.<p>References <a class="el" href="pid_8h.html#a6">pidData_t</a>, and <a class="el" href="pid_8h-source.html#l00035">PID_DATA::sumError</a>.<p><pre class="fragment"><div>00113 {00114   pid_st-&gt;<a class="code" href="structPID__DATA.html#o6">sumError</a> = 0;00115 }</div></pre>    </td>  </tr></table><hr size="1"><address style="align: right;"><small>Generated on Thu Feb 16 16:22:41 2006 for AVR221 - PID controller by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.7 </small></address></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -