文章目录
-
- 0. 被控对象与设计要求
- 1. 比例控制
- 2.PID 控制
- 3. 调参
0. 被控对象与设计要求
上一节我们知道了我们的开环响应并不能满足设计需求,这一节我们通过一个PID控制器使我们的系统满足设计需求。 这里把设计需求和系统转换方程粘贴在这里: 设计需求(阶跃响应):
- 稳定时间<2s
- 超调<5%
- 稳态误差<1%
转换方程:
1. 比例控制
首先来看一个加了控制器的单位负反馈系统的框图
我们的目标是通过设计控制器 C ( s ) C(s)C(s) 来使系统满足要求。我们先从单纯的比例控制开始,在电机Plant前面加一个比例控制器,然后得到新的系统(这里我们随意定了比例系数为100)
<code class="prism language-csharp has-numbering"><span class="token operator">%</span>motor parameter J <span class="token operator">=</span> <span class="token number">0.01</span><span class="token punctuation">;</span> b <span class="token operator">=</span> <span class="token number">0.1</span><span class="token punctuation">;</span> K <span class="token operator">=</span> <span class="token number">0.01</span><span class="token punctuation">;</span> R <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span> L <span class="token operator">=</span> <span class="token number">0.5</span><span class="token punctuation">;</span> <span class="token operator">%</span>motor tf function s <span class="token operator">=</span> <span class="token function">tf</span><span class="token punctuation">(</span><span class="token string">'s'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> P_motor <span class="token operator">=</span> K<span class="token operator">/</span><span class="token punctuation">(</span><span class="token punctuation">(</span>J<span class="token operator">*</span>s<span class="token operator">+</span>b<span class="token punctuation">)</span><span class="token operator">*</span><span class="token punctuation">(</span>L<span class="token operator">*</span>s<span class="token operator">+</span>R<span class="token punctuation">)</span><span class="token operator">+</span>K<span class="token operator">^</span><span class="token number">2</span><span class="token punctuation">)</span> <span class="token operator">%</span>定义我们的纯比例控制器 Kp <span class="token operator">=</span> <span class="token number">100</span><span class="token punctuation">;</span> C <span class="token operator">=</span> <span class="token function">pid</span><span class="token punctuation">(</span>Kp<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">%</span>新的单位负反馈系统 sys_cl <span class="token operator">=</span> <span class="token function">feedback</span><span class="token punctuation">(</span>C<span class="token operator">*</span>P_motor<span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token function">linearSystemAnalyzer</span><span class="token punctuation">(</span><span class="token string">'step'</span><span class="token punctuation">,</span>sys_cl<span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">:</span><span class="token number">0.01</span><span class="token punctuation">:</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </code>
得到新系统的单位阶跃响应
新的系统稳定时间控制在了0.567s,满足了稳定时间<2s的要求。但是新系统的超调很大,变得不满足要求。 回顾控制理论知识,增大Kp在减小稳态误差的同时也会增大超调,我们来检查一下是不是这样。 运行以下代码打开matlab的控制系统设计工具(输入是开环转换方程)
<code class="prism language-csharp has-numbering"><span class="token function">controlSystemDesigner</span><span class="token punctuation">(</span>P_motor<span class="token punctuation">) </span> </code>
在弹出的窗口选择添加新的阶跃输入图像
选择IOTransfer_r2y(画出输入输出图像),然后点击plot
接下来双击左边的C,该变它的值之后按Enter,看系统响应如何变化
可以发现,增加比例系数确实能够减少稳态误差,但是增加超调。因此我们还需要微分和积分控制。
2.PID 控制
这次我们给控制器加上微分和积分系数(随便定的值)
<code class="prism language-csharp has-numbering"><span class="token operator">%</span>PID 控制器(未调参) Kp <span class="token operator">=</span> <span class="token number">75</span><span class="token punctuation">;</span> Ki <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span> Kd <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span> C <span class="token operator">=</span> <span class="token function">pid</span><span class="token punctuation">(</span>Kp<span class="token punctuation">,</span>Ki<span class="token punctuation">,</span>Kd<span class="token punctuation">)</span><span class="token punctuation">;</span> sys_cl <span class="token operator">=</span> <span class="token function">feedback</span><span class="token punctuation">(</span>C<span class="token operator">*</span>P_motor<span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token function">linearSystemAnalyzer</span><span class="token punctuation">(</span><span class="token string">'step'</span><span class="token punctuation">,</span>sys_cl<span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">:</span><span class="token number">1</span><span class="token punctuation">:</span><span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </code>
系统的稳定时间变长,依旧不满足设计要求,因此我们需要调节我们的PID参数知道系统满足设计要求。
3. 调参
稳定时间很长的原因是Ki太小,系统不能很快的收敛,我们增大Ki至200,重新绘制响应图
<code class="prism language-csharp has-numbering"><span class="token operator">%</span>PID 控制器(调节Ki) Kp <span class="token operator">=</span> <span class="token number">75</span><span class="token punctuation">;</span> Ki <span class="token operator">=</span> <span class="token number">200</span><span class="token punctuation">;</span> Kd <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span> C <span class="token operator">=</span> <span class="token function">pid</span><span class="token punctuation">(</span>Kp<span class="token punctuation">,</span>Ki<span class="token punctuation">,</span>Kd<span class="token punctuation">)</span><span class="token punctuation">;</span> sys_cl <span class="token operator">=</span> <span class="token function">feedback</span><span class="token punctuation">(</span>C<span class="token operator">*</span>P_motor<span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token function">linearSystemAnalyzer</span><span class="token punctuation">(</span><span class="token string">'step'</span><span class="token punctuation">,</span>sys_cl<span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">:</span><span class="token number">0.01</span><span class="token punctuation">:</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </code>
系统稳定时间快了很多,但是超调很大。现在我们增大Kd,来试着减少超调
<code class="prism language-csharp has-numbering"><span class="token operator">%</span>PID 控制器(调节Kd) Kp <span class="token operator">=</span> <span class="token number">75</span><span class="token punctuation">;</span> Ki <span class="token operator">=</span> <span class="token number">200</span><span class="token punctuation">;</span> Kd <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span> C <span class="token operator">=</span> <span class="token function">pid</span><span class="token punctuation">(</span>Kp<span class="token punctuation">,</span>Ki<span class="token punctuation">,</span>Kd<span class="token punctuation">)</span><span class="token punctuation">;</span> sys_cl <span class="token operator">=</span> <span class="token function">feedback</span><span class="token punctuation">(</span>C<span class="token operator">*</span>P_motor<span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token function">linearSystemAnalyzer</span><span class="token punctuation">(</span><span class="token string">'step'</span><span class="token punctuation">,</span>sys_cl<span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">:</span><span class="token number">0.01</span><span class="token punctuation">:</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span> </code>
发现系统已经完全满足设计要求,因此Kp=75, Ki=200,Kd=10 定义的PID控制器可以用在这里作为电机控制器。 这里也可以用Matlab自带的PID tunner工具箱来调参,不再赘述