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

📄 pid_8h.html

📁 Atmel算法(pid)-步进电机驱动源码 HOWTO,不好用你找我,绝对ok!
💻 HTML
📖 第 1 页 / 共 2 页
字号:
    <td>      &nbsp;    </td>    <td><p>PID Status. <p>Setpoints and data used by the PID control algorithm    </td>  </tr></table><hr><h2>Function Documentation</h2><a class="anchor" name="a8"></a><!-- doxytag: member="pid.h::PID_Controller" ref="a8" args="(int16_t setPoint, int16_t processValue, 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"><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 class="md"></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 class="md"></td>          <td class="md" nowrap><a class="el" href="structpidData.html">pidData_t</a> *&nbsp;</td>          <td class="mdname" nowrap> <em>pid_st</em></td>        </tr>        <tr>          <td class="md"></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 valign="top"></td><td valign="top"><em>setPoint</em>&nbsp;</td><td>Desired value. </td></tr>    <tr><td valign="top"></td><td valign="top"><em>processValue</em>&nbsp;</td><td>Measured value. </td></tr>    <tr><td valign="top"></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#l00065">65</a> of file <a class="el" href="pid_8c-source.html">pid.c</a>.<p>References <a class="el" href="pid_8h-source.html#l00054">pidData::D_Factor</a>, <a class="el" href="pid_8h-source.html#l00052">pidData::I_Factor</a>, <a class="el" href="pid_8h-source.html#l00046">pidData::lastProcessValue</a>, <a class="el" href="pid_8h-source.html#l00075">MAX_I_TERM</a>, <a class="el" href="pid_8h-source.html#l00063">MAX_INT</a>, <a class="el" href="pid_8h-source.html#l00056">pidData::maxError</a>, <a class="el" href="pid_8h-source.html#l00058">pidData::maxSumError</a>, <a class="el" href="pid_8h-source.html#l00050">pidData::P_Factor</a>, <a class="el" href="pid_8h-source.html#l00037">SCALING_FACTOR</a>, and <a class="el" href="pid_8h-source.html#l00048">pidData::sumError</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00305">SpeedController()</a>.<div class="fragment"><pre class="fragment"><a name="l00066"></a>00066 {<a name="l00067"></a>00067   <a class="code" href="stdint_8h.html#a57">int16_t</a> error, p_term, d_term;<a name="l00068"></a>00068   <a class="code" href="stdint_8h.html#a59">int32_t</a> i_term;<a name="l00069"></a>00069   <a class="code" href="stdint_8h.html#a59">int32_t</a> ret;<a name="l00070"></a>00070   <a class="code" href="stdint_8h.html#a59">int32_t</a> temp;<a name="l00071"></a>00071 <a name="l00072"></a>00072   error = setPoint - processValue;<a name="l00073"></a>00073 <a name="l00074"></a>00074   <span class="comment">// Calculate Pterm and limit error overflow</span><a name="l00075"></a>00075   <span class="keywordflow">if</span> (error &gt; pid_st-&gt;<a class="code" href="structpidData.html#o3">maxError</a>)<a name="l00076"></a>00076   {<a name="l00077"></a>00077     p_term = <a class="code" href="pid_8h.html#a1">MAX_INT</a>;<a name="l00078"></a>00078   }<a name="l00079"></a>00079   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (error &lt; -pid_st-&gt;maxError)<a name="l00080"></a>00080   {<a name="l00081"></a>00081     p_term = -<a class="code" href="pid_8h.html#a1">MAX_INT</a>;<a name="l00082"></a>00082   }<a name="l00083"></a>00083   <span class="keywordflow">else</span><a name="l00084"></a>00084   {<a name="l00085"></a>00085     p_term = pid_st-&gt;<a class="code" href="structpidData.html#o5">P_Factor</a> * error;<a name="l00086"></a>00086   }<a name="l00087"></a>00087 <a name="l00088"></a>00088   <span class="comment">// Calculate Iterm and limit integral runaway</span><a name="l00089"></a>00089   temp = pid_st-&gt;<a class="code" href="structpidData.html#o6">sumError</a> + error;<a name="l00090"></a>00090   <span class="keywordflow">if</span>(temp &gt; pid_st-&gt;<a class="code" href="structpidData.html#o4">maxSumError</a>)<a name="l00091"></a>00091   {<a name="l00092"></a>00092     i_term = <a class="code" href="pid_8h.html#a3">MAX_I_TERM</a>;<a name="l00093"></a>00093     pid_st-&gt;<a class="code" href="structpidData.html#o6">sumError</a> = pid_st-&gt;<a class="code" href="structpidData.html#o4">maxSumError</a>;<a name="l00094"></a>00094   }<a name="l00095"></a>00095   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(temp &lt; -pid_st-&gt;<a class="code" href="structpidData.html#o4">maxSumError</a>)<a name="l00096"></a>00096   {<a name="l00097"></a>00097     i_term = -<a class="code" href="pid_8h.html#a3">MAX_I_TERM</a>;<a name="l00098"></a>00098     pid_st-&gt;<a class="code" href="structpidData.html#o6">sumError</a> = -pid_st-&gt;<a class="code" href="structpidData.html#o4">maxSumError</a>;<a name="l00099"></a>00099   }<a name="l00100"></a>00100   <span class="keywordflow">else</span><a name="l00101"></a>00101   {<a name="l00102"></a>00102     pid_st-&gt;<a class="code" href="structpidData.html#o6">sumError</a> = temp;<a name="l00103"></a>00103     i_term = pid_st-&gt;<a class="code" href="structpidData.html#o1">I_Factor</a> * pid_st-&gt;<a class="code" href="structpidData.html#o6">sumError</a>;<a name="l00104"></a>00104   }<a name="l00105"></a>00105 <a name="l00106"></a>00106   <span class="comment">// Calculate Dterm</span><a name="l00107"></a>00107   d_term = pid_st-&gt;<a class="code" href="structpidData.html#o0">D_Factor</a> * (pid_st-&gt;<a class="code" href="structpidData.html#o2">lastProcessValue</a> - processValue);<a name="l00108"></a>00108 <a name="l00109"></a>00109   pid_st-&gt;<a class="code" href="structpidData.html#o2">lastProcessValue</a> = processValue;<a name="l00110"></a>00110 <a name="l00111"></a>00111   ret = (p_term + i_term + d_term) / <a class="code" href="pid_8h.html#a0">SCALING_FACTOR</a>;<a name="l00112"></a>00112   <span class="keywordflow">if</span>(ret &gt; <a class="code" href="pid_8h.html#a1">MAX_INT</a>)<a name="l00113"></a>00113   {<a name="l00114"></a>00114     ret = <a class="code" href="pid_8h.html#a1">MAX_INT</a>;<a name="l00115"></a>00115   }<a name="l00116"></a>00116   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(ret &lt; -<a class="code" href="pid_8h.html#a1">MAX_INT</a>)<a name="l00117"></a>00117   {<a name="l00118"></a>00118     ret = -<a class="code" href="pid_8h.html#a1">MAX_INT</a>;<a name="l00119"></a>00119   }<a name="l00120"></a>00120 <a name="l00121"></a>00121   <span class="keywordflow">return</span>((<a class="code" href="stdint_8h.html#a57">int16_t</a>)ret);<a name="l00122"></a>00122 }</pre></div><p>    </td>  </tr></table><a class="anchor" name="a7"></a><!-- doxytag: member="pid.h::PID_Init" ref="a7" args="(int16_t p_factor, int16_t i_factor, int16_t d_factor, pidData_t *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">(&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 class="md"></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 class="md"></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 class="md"></td>          <td class="md" nowrap><a class="el" href="structpidData.html">pidData_t</a> *&nbsp;</td>          <td class="mdname" nowrap> <em>pid</em></td>        </tr>        <tr>          <td class="md"></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 valign="top"></td><td valign="top"><em>p_factor</em>&nbsp;</td><td>Proportional term. </td></tr>    <tr><td valign="top"></td><td valign="top"><em>i_factor</em>&nbsp;</td><td>Integral term. </td></tr>    <tr><td valign="top"></td><td valign="top"><em>d_factor</em>&nbsp;</td><td>Derivate term. </td></tr>    <tr><td valign="top"></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#l00041">41</a> of file <a class="el" href="pid_8c-source.html">pid.c</a>.<p>References <a class="el" href="pid_8h-source.html#l00054">pidData::D_Factor</a>, <a class="el" href="pid_8h-source.html#l00052">pidData::I_Factor</a>, <a class="el" href="pid_8h-source.html#l00046">pidData::lastProcessValue</a>, <a class="el" href="pid_8h-source.html#l00075">MAX_I_TERM</a>, <a class="el" href="pid_8h-source.html#l00063">MAX_INT</a>, <a class="el" href="pid_8h-source.html#l00056">pidData::maxError</a>, <a class="el" href="pid_8h-source.html#l00058">pidData::maxSumError</a>, <a class="el" href="pid_8h-source.html#l00050">pidData::P_Factor</a>, and <a class="el" href="pid_8h-source.html#l00048">pidData::sumError</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00135">main()</a>.<div class="fragment"><pre class="fragment"><a name="l00043"></a>00043 {<a name="l00044"></a>00044   <span class="comment">// Start values for PID controller</span><a name="l00045"></a>00045   pid-&gt;<a class="code" href="structpidData.html#o6">sumError</a> = 0;<a name="l00046"></a>00046   pid-&gt;<a class="code" href="structpidData.html#o2">lastProcessValue</a> = 0;<a name="l00047"></a>00047   <span class="comment">// Tuning constants for PID loop</span><a name="l00048"></a>00048   pid-&gt;<a class="code" href="structpidData.html#o5">P_Factor</a> = p_factor;<a name="l00049"></a>00049   pid-&gt;<a class="code" href="structpidData.html#o1">I_Factor</a> = i_factor;<a name="l00050"></a>00050   pid-&gt;<a class="code" href="structpidData.html#o0">D_Factor</a> = d_factor;<a name="l00051"></a>00051   <span class="comment">// Limits to avoid overflow</span><a name="l00052"></a>00052   pid-&gt;<a class="code" href="structpidData.html#o3">maxError</a> = <a class="code" href="pid_8h.html#a1">MAX_INT</a> / pid-&gt;<a class="code" href="structpidData.html#o5">P_Factor</a>;<a name="l00053"></a>00053   pid-&gt;<a class="code" href="structpidData.html#o4">maxSumError</a> = <a class="code" href="pid_8h.html#a3">MAX_I_TERM</a> / pid-&gt;<a class="code" href="structpidData.html#o1">I_Factor</a>;<a name="l00054"></a>00054 }</pre></div><p>    </td>  </tr></table><a class="anchor" name="a9"></a><!-- doxytag: member="pid.h::PID_Reset_Integrator" ref="a9" 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">(&nbsp;</td>          <td class="md" nowrap valign="top"><a class="el" href="structpidData.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#l00129">129</a> of file <a class="el" href="pid_8c-source.html">pid.c</a>.<p>References <a class="el" href="pid_8h-source.html#l00048">pidData::sumError</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00816">CommutationTicksUpdate()</a>.<div class="fragment"><pre class="fragment"><a name="l00130"></a>00130 {<a name="l00131"></a>00131   pid_st-&gt;<a class="code" href="structpidData.html#o6">sumError</a> = 0;<a name="l00132"></a>00132 }</pre></div><p>    </td>  </tr></table><hr size="1"><address style="align: right;"><small>Generated on Mon Mar 27 09:31:32 2006 for AVR447: Sine wave driving of three phase motor by&nbsp;<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 + -