Main Content

PID Controller Design in the Live Editor

This example shows how to use theTune PID控制器task in the Live Editor to generate code for designing a PID controller for a linear plant model. TheTune PID控制器task lets you interactively refine the performance of the controller to adjust loop bandwidth and phase margin, or to favor setpoint tracking or disturbance. The task generates a response plot that lets you monitor controller performance while you adjust the tuning parameters.

Open this example to see a preconfigured script containing theTune PID控制器task. For more information about Live Editor tasks generally, seeAdd Interactive Tasks to a Live Script

在现场编辑器中,为您的工厂创建LTI模型。

G= zpk(-5,[-1 -2 -3 -4],6);

要设计该工厂的PID控制器,请打开Tune PID控制器实时编辑任务。在现场编辑选项卡,选择Task>Tune PID控制器。此操作将任务插入您的脚本。

Initial Controller Design

To generate an initial PID controller design, in the植物菜单,选择您创建的植物,GTune PID控制器假设以下图的标准单位反馈控制配置,可以自动生成平衡性能和鲁棒性的PI控制器。

The task also generates a step response plot showing the closed-loop step response fromry使用初始控制器设计。

精炼控制器设计

选择System response characteristics显示此响应的某些时间域特征的数值。

The initial controller design has a rise time of about 1.5 seconds, with about 8% overshoot. Experiment with theResponse Timeand瞬态行为滑块以更改设计目标,并看到它们对步骤响应的影响。

使用PI控制器和该工厂,如果不引入不稳定性或以其他方式降解系统响应,就很难减少响应时间。尝试切换到PID控制器,以查看是否可以达到更好的响应时间。在里面控制器类型下拉菜单,选择PID

You can now reduce the response time of the controller. Experiment with the sliders again, observing the effect on the step response. For an example that shows in more detail how theResponse Timeand瞬态行为sliders affect controller performance, seeTune PID控制器到Favor Reference Tracking or Disturbance Rejection (PID Tuner)。该示例使用PID Tunerapp instead of theTune PID控制器task in the Live Editor, but the behavior and effect of the sliders is the same in both tools.

Examine Generated Code

该任务会自动生成代码,以调整具有指定设计目标的工厂的PID控制器。要查看生成的代码,请单击在任务的底部。该任务扩展以显示生成的代码。

当您更改参数,例如控制器结构,性能目标和响应图类型时,生成代码自动更新以反映新设置。

检查扰动拒绝表现

假设您对闭环系统对工厂输入的干扰响应感兴趣。从 d 1 y,,,,in the输出图下拉菜单,选择Step Plot: Input disturbance rejection。图更新以显示新响应。根据您在更改响应图时设定性能目标的方式,您可能会看到以下响应。

现在,您可以再次使用控制器参数进行实验,并观察它们对扰动排斥的影响。有关一个示例,该示例更详细地说明如何使用滑块和其他设计参数来提高干扰拒绝性能,请参见Tune PID控制器到Favor Reference Tracking or Disturbance Rejection (PID Tuner)。该示例使用PID Tunerapp instead of theTune PID控制器task in the Live Editor, but the behavior and effect of design parameters is the same in both tools.

比较两个控制器设计

Tune PID控制器自动将调谐控制器写入MATLAB®工作区作为一个pid,,,,pidstd,,,,PID2, 或者pidstd2模型对象,以您的控制器设置为准。任务使用任务摘要行中指定的变量名称存储控制器。默认情况下,该变量名称是C。当您更改控制器设置,性能目标或其他调整参数时,默认情况下任务通过变量写入C

You can save a controller design to use as a baseline for comparison while you experiment further with controller types, performance goals, and other settings. To do so, type a new variable name in the task summary line. For instance, change the output controller name toCNEW

现在,当前的设计存储在MATLAB工作区中C。设计的任何进一步更改都存储为CNEW

使用C作为compari基线son, in the基线控制器菜单,选择选择from workspace。然后,选择Cin the menu that appears.

现在,随着您对控制器设计的进一步实验,该图都显示了系统响应的控制器C(虚线)和控制器CNEW(solid line).

使用控制器

因为Tune PID控制器任务将控制器保存到MATLAB工作区,您可以使用控制器,因为您将使用任何其他PID模型对象进行控制和分析。例如,检查控制器性能针对稍微不同的植物模型,以了解闭环系统对参数变化的稳健性。

G1= zpk(-5,[-0.75 -2 -3 -4],8); CL1 = getPIDLoopResponse(C,G1,'closed-loop');cl = getPidloopResponse(c,g,'closed-loop');步骤(CL,CL1)

也可以看看

实时编辑任务

Related Topics