plotExamplePropControl脚本

这段MATLAB代码用于绘制一个**平滑比例控制器(smoothed proportional controller)**的操作示例图。以下是代码的详细解读:


代码功能

  • 目的:展示比例控制器在不同过程变量(如温度)下的控制行为。
  • 背景:基于论文 Katzin, D., Marcelis, L. F. M., & van Mourik, S. (2021) 中的研究,用于生成论文中的图4。
  • 核心:通过绘制比例控制器的输出,展示其在不同温度下的控制行为。

代码解析

  1. 注释说明
    matlab
    复制
    % PLOTEXAMPLEPROPCONTROL Plot an example of the operation of a smoothed proportional controller
    % Used to create Figure 4 in: 
    %   Katzin, D., Marcelis, L. F. M., & van Mourik, S. (2021). 
    %   Energy savings in greenhouses by transition from high-pressure sodium 
    %   to LED lighting. Applied Energy, 281, 116019. 
    %   https://doi.org/10.1016/j.apenergy.2020.116019

    这些注释提供了代码的功能描述、背景信息(用于生成论文中的图4),以及相关论文的引用。

  2. 作者信息
    matlab
    复制
    % David Katzin, Wageningen University
    % david.katzin@wur.nl
    % david.katzin1@gmail.com

    这部分注释提供了作者的姓名、单位和联系方式。

  3. 定义变量
    matlab
    复制
    x.tAir = 0:0.001:40;
    a.heatSetPoint = 18.5;
    p.tHeatBand = -1;
    • x.tAir:过程变量(如温度)的范围,从 0 到 40,步长为 0.001。
    • a.heatSetPoint:加热设定点(set point),值为 18.5。
    • p.tHeatBand:比例控制器的带宽(bandwidth),值为 -1。
  4. 绘制比例控制器输出
    matlab
    复制
    plot(x.tAir, proportionalControl(x.tAir, a.heatSetPoint, -p.tHeatBand, 0, 1));
    • 调用 proportionalControl 函数计算比例控制器的输出,并绘制曲线。
    • proportionalControl 函数的输入参数:
      • x.tAir:过程变量(温度)。
      • a.heatSetPoint:设定点。
      • -p.tHeatBand:带宽的负值。
      • 01:控制器输出的最小值和最大值。
  5. 设置图形属性
    matlab
    复制
    grid
    axis([18 20 -0.1 1.1])
    xticks(18:0.25:20)
    xticklabels({'','','x = setPoint','','','','x = setPoint+Pband','',''})
    • grid:在图形中添加网格线。
    • axis([18 20 -0.1 1.1]):设置图形的横轴范围为 18 到 20,纵轴范围为 -0.1 到 1.1。
    • xticksxticklabels:设置横轴刻度和标签,突出显示设定点和带宽。
  6. 绘制设定点和带宽的参考线
    matlab
    复制
    hold on
    plot([19.5 19.5], [-1 2], 'LineWidth',0.3,'LineStyle','--',...
        'Color',[0.15 0.15 0.15]);
    plot([18.5 18.5], [-1 2], 'LineWidth',0.3,'LineStyle','--',...
        'Color',[0.15 0.15 0.15]);
    • 在设定点(18.5)和设定点加带宽(19.5)处绘制垂直虚线,用于标记关键点。
  7. 设置纵轴刻度和标签
    matlab
    复制
    yticks(-0.2:0.2:1.2)
    yticklabels({'','No action', '0.2', '0.4', '0.6','0.8','Full action',''})
    • 设置纵轴刻度和标签,表示控制器输出的不同状态(从“无动作”到“全动作”)。
  8. 绘制控制器输出的上下限参考线
    matlab
    复制
    plot([10 30], [0 0], 'LineWidth',0.3,'LineStyle','--',...
        'Color',[0.15 0.15 0.15]);
    plot([10 30], [1 1], 'LineWidth',0.3,'LineStyle','--',...
        'Color',[0.15 0.15 0.15]);
    • 在控制器输出的下限(0)和上限(1)处绘制水平虚线。
  9. 设置坐标轴标签
    matlab
    复制
    xlabel('Process variable x','LineWidth',0.3);
    ylabel('Controller action','LineWidth',0.3);
    • 设置横轴标签为“过程变量 x”。
    • 设置纵轴标签为“控制器动作”。

比例控制器公式

假设 proportionalControl 函数的实现如下:

matlab
复制
function output = proportionalControl(x, setPoint, band, minOutput, maxOutput)
    % 计算比例控制器的输出
    output = max(minOutput, min(maxOutput, (x - setPoint) / band));
end
  • 公式解释:

     

    output=clamp(xsetPointband,minOutput,maxOutput)\text{output} = \text{clamp}\left(\frac{x – \text{setPoint}}{\text{band}}, \text{minOutput}, \text{maxOutput}\right)

    • clamp 表示将输出限制在 minOutputmaxOutput 之间。
    • x 接近 setPoint 时,输出接近 0。
    • x 超出 setPoint + band 时,输出达到最大值。

示例

假设:

  • 设定点 setPoint = 18.5
  • 带宽 band = -1
  • 控制器输出范围 [0, 1]
  1. x = 18.5(设定点)时:

     

    output=18.518.51=0\text{output} = \frac{18.5 – 18.5}{-1} = 0

  2. x = 19.5(设定点加带宽)时:

     

    output=19.518.51=1(被限制为 0)\text{output} = \frac{19.5 – 18.5}{-1} = -1 \quad (\text{被限制为 0})

  3. x = 17.5(设定点减带宽)时:

     

    output=17.518.51=1\text{output} = \frac{17.5 – 18.5}{-1} = 1


总结

这段代码通过绘制比例控制器的输出曲线,展示了其在不同过程变量(如温度)下的控制行为。适用于温室控制系统的分析和优化。

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇