📄 pid_8c.html
字号:
<a name="l00102"></a>00102 ret = (p_term + i_term + d_term) / <a class="code" href="pid_8h.html#a0">SCALING_FACTOR</a>;<a name="l00103"></a>00103 <span class="keywordflow">if</span>(ret > <a class="code" href="pid_8h.html#a1">MAX_INT</a>){<a name="l00104"></a>00104 ret = <a class="code" href="pid_8h.html#a1">MAX_INT</a>;<a name="l00105"></a>00105 }<a name="l00106"></a>00106 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(ret < -<a class="code" href="pid_8h.html#a1">MAX_INT</a>){<a name="l00107"></a>00107 ret = -<a class="code" href="pid_8h.html#a1">MAX_INT</a>;<a name="l00108"></a>00108 }<a name="l00109"></a>00109 <a name="l00110"></a>00110 <span class="keywordflow">return</span>((<a class="code" href="stdint_8h.html#a57">int16_t</a>)ret);<a name="l00111"></a>00111 }</pre></div><p> </td> </tr></table><a class="anchor" name="a0"></a><!-- doxytag: member="pid.c::pid_Init" ref="a0" args="(int16_t p_factor, int16_t i_factor, int16_t d_factor, struct PID_DATA *pid)" --><p><table class="mdTable" 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">( </td> <td class="md" nowrap valign="top"><a class="el" href="stdint_8h.html#a57">int16_t</a> </td> <td class="mdname" nowrap> <em>p_factor</em>, </td> </tr> <tr> <td class="md" nowrap align="right"></td> <td class="md"></td> <td class="md" nowrap><a class="el" href="stdint_8h.html#a57">int16_t</a> </td> <td class="mdname" nowrap> <em>i_factor</em>, </td> </tr> <tr> <td class="md" nowrap align="right"></td> <td class="md"></td> <td class="md" nowrap><a class="el" href="stdint_8h.html#a57">int16_t</a> </td> <td class="mdname" nowrap> <em>d_factor</em>, </td> </tr> <tr> <td class="md" nowrap align="right"></td> <td class="md"></td> <td class="md" nowrap>struct <a class="el" href="structPID__DATA.html">PID_DATA</a> * </td> <td class="mdname" nowrap> <em>pid</em></td> </tr> <tr> <td class="md"></td> <td class="md">) </td> <td class="md" colspan="2"></td> </tr> </table> </td> </tr></table><table cellspacing="5" cellpadding="0" border="0"> <tr> <td> </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 valign="top"></td><td valign="top"><em>p_factor</em> </td><td>Proportional term. </td></tr> <tr><td valign="top"></td><td valign="top"><em>i_factor</em> </td><td>Integral term. </td></tr> <tr><td valign="top"></td><td valign="top"><em>d_factor</em> </td><td>Derivate term. </td></tr> <tr><td valign="top"></td><td valign="top"><em>pid</em> </td><td>Struct with PID status.</td></tr> </table></dl><p>Definition at line <a class="el" href="pid_8c-source.html#l00040">40</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#l00120">main()</a>.<div class="fragment"><pre class="fragment"><a name="l00042"></a>00042 {<a name="l00043"></a>00043 <span class="comment">// Start values for PID controller</span><a name="l00044"></a>00044 pid-><a class="code" href="structPID__DATA.html#o6">sumError</a> = 0;<a name="l00045"></a>00045 pid-><a class="code" href="structPID__DATA.html#o2">lastProcessValue</a> = 0;<a name="l00046"></a>00046 <span class="comment">// Tuning constants for PID loop</span><a name="l00047"></a>00047 pid-><a class="code" href="structPID__DATA.html#o5">P_Factor</a> = p_factor;<a name="l00048"></a>00048 pid-><a class="code" href="structPID__DATA.html#o1">I_Factor</a> = i_factor;<a name="l00049"></a>00049 pid-><a class="code" href="structPID__DATA.html#o0">D_Factor</a> = d_factor;<a name="l00050"></a>00050 <span class="comment">// Limits to avoid overflow</span><a name="l00051"></a>00051 pid-><a class="code" href="structPID__DATA.html#o3">maxError</a> = <a class="code" href="pid_8h.html#a1">MAX_INT</a> / (pid-><a class="code" href="structPID__DATA.html#o5">P_Factor</a> + 1);<a name="l00052"></a>00052 pid-><a class="code" href="structPID__DATA.html#o4">maxSumError</a> = <a class="code" href="pid_8h.html#a3">MAX_I_TERM</a> / (pid-><a class="code" href="structPID__DATA.html#o1">I_Factor</a> + 1);<a name="l00053"></a>00053 }</pre></div><p> </td> </tr></table><a class="anchor" name="a2"></a><!-- doxytag: member="pid.c::pid_Reset_Integrator" ref="a2" args="(pidData_t *pid_st)" --><p><table class="mdTable" 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">( </td> <td class="md" nowrap valign="top"><a class="el" href="structPID__DATA.html">pidData_t</a> * </td> <td class="mdname1" valign="top" nowrap> <em>pid_st</em> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr></table><table cellspacing="5" cellpadding="0" border="0"> <tr> <td> </td> <td><p>Resets the integrator. <p>Calling this function will reset the integrator in the PID controller.<p>Definition at line <a class="el" href="pid_8c-source.html#l00117">117</a> of file <a class="el" href="pid_8c-source.html">pid.c</a>.<p>References <a class="el" href="pid_8h-source.html#l00035">PID_DATA::sumError</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00643">CommutationTicksUpdate()</a>, and <a class="el" href="main_8c-source.html#l01029">FaultProtectionISR()</a>.<div class="fragment"><pre class="fragment"><a name="l00118"></a>00118 {<a name="l00119"></a>00119 pid_st-><a class="code" href="structPID__DATA.html#o6">sumError</a> = 0;<a name="l00120"></a>00120 }</pre></div><p> </td> </tr></table><hr size="1"><address style="align: right;"><small>Generated on Mon May 29 10:58:57 2006 for AVR449 by <a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.4 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -