主要内容

Control Real-Time PID Autotuning in金宝app

部署PID自动块块可让您无需Simulink即可实时调整系统金宝app®in the loop. However, it can be useful to run the autotuning algorithm on hardware while controlling the experiment from Simulink.

One way to do so is to use a model that contains a PID controller and a PID autotuner block, and run this model in external simulation mode. External mode allows communication between the Simulink block diagram and the standalone program that is built from the generated code. In this mode, Simulink serves as a real-time monitoring interface in which you can interact with the tuning algorithm running on hardware. For instance, you can start and stop the experiment or change tuning goals from the Simulink interface while the model is running.

When tuning in external mode, you can deploy the experiment algorithm only, such that the PID tuning part of the calculation is performed in Simulink. Doing so can save memory on your target hardware. Running the PID autotuning algorithm in external mode requires a code-generation product such as金宝appSimulink Coder™.

金宝appModel for External-Mode Tuning

用于金宝appPID在外部模式下自动调整的模型类似于以下图表。

在这里,标记的块Read plant output from hardware写入硬件的工厂输入represent hardware interfaces that read data from or write data to your physical plant. When you are ready for tuning, you run this model in external simulation mode.

漫步转移用于开环调节

When you use the开环PID自动调节器, if your controller includes integrator action, consider implementing signal tracking to avoid integrator windup during the tuning experiment. Signal tracking enables the PID controller to continue to track the real plant input while it is out of the loop. Without it, your system can experience a bump when the control loop is closed at the end of the tuning process.

If your PID controller is a SimulinkPID Controller块,您可以使用Enable tracking mode控制器块的参数以避免此凸起。下图说明了一个包含一个的模块开环PID自动调节器块和aPID Controllerblock with tracking mode configured. The plant input feeds into the tracking input of the controller block.

For external-mode tuning, you configure the起步signal as described inPID Autotuning for a Plant Modeled in Simulink. The models illustrated here use a simple switch with a binary signal to start and stop the experiment manually.

您还配置了控制器参数,调整目标和实验参数,如PID Autotuning for a Plant Modeled in Simulink.

Run the Model and Tune the Controller Gains

After configuring the block parameters for the experiment, in the model, selectexternal mode,将仿真时间设置为无限,并运行模型。

Simulink compiles the model and deploys it to your connected hardware.

  • If you have configured thestart/stopsignal to begin and end the tuning process at specific times, allow the simulation to run through the end of the experiment.

  • 如果您配置了手册start/stopsignal, begin the experiment when your plant has reached steady-state. Observe the signal at the%转换输出,并在信号稳定接近100%时停止实验。

When tuning is complete, examine and validate the tuned gains as described inPID Autotuning for a Plant Modeled in Simulink.

有关一个更详细的示例,该示例说明了使用外部模式通过Simulink控制自动调整过程的使用,请参见金宝app使用开环PID自动块实时调整PID控制器.

Reduce Memory Footprint When Using External Mode

自动块块包含两个模块,一个模块执行实时频率响应估计,另一个使用结果估计的响应来调整PID的增长。当您在外部仿真模式下运行包含块金宝app的simulink模型时,默认情况下将部署两个模块。您只能通过部署估计模块来保存目标硬件的内存。在这种情况下,调整算法在Simulink主机计算机上而不是目标硬件上运行。金宝app为此,请使用Reduce memory and avoid task overrun在自动块块中的选项。选择此选项后,部署算法使用大约三分之一的内存,就像清除该选项时一样多。

与频率响应估计相比,PID增益计算需要更多的计算负载。对于快速控制器示例时间,某些硬件可能无法在一个执行周期内完成增益计算。因此,在使用有限的计算功率的硬件时,选择此选项使您可以使用快速示例时间调整PID控制器。

Additionally, when you enable this option, there can be a delay of several sampling periods between when the tuning experiment ends and when the new PID gains arrive at thepid gains输出端口。在将收益推向控制器之前,首先确认pid gainsoutput port instead of usingstart/stopsignal as the trigger for the update.

Caution

当您使用此选项时,必须配置模型,以使数字块参数可在生成的代码中调谐,而不是嵌入。指定可调参数:

  • In the model editor: InConfiguration Parameters, 在Code Generation>优化, set默认参数行为to可调.

  • At the command line: Useset_param(mdl,'DefaultParameterBehavior','Tunable').

See Also

|

相关话题