Other

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

深度分析:Plasmatree/PID-Analyzer

项目背景与痛点

PID 控制在工业自动化、嵌入式系统及许多其他领域有着广泛的应用。优化 PID 控制的效果,不仅可以提高系统的稳定性,还能提升系统的响应速度和精确度。因此,一个高效且易于使用的 PID 分析工具至关重要。

项目 “Plasmatree/PID-Analyzer” 正是为了满足这一需求而生。它不仅提供了一个全面的 PID 控制器分析工具,还为开发者和工程师提供了一个通用的框架,用于研究 PID 控制算法的各个参数如何影响控制器的性能。借助这个工具,用户可以快速理解并优化 PID 控制系统,而不是依赖于乏味且低效的试错法。

核心技术揭秘

Plasmatree/PID-Analyzer 的核心实现采用了先进的可视化和数据流技术,简化了 PID 参数的分析过程。其关键特性包括响应曲线绘制、参数调优及实时仿真等功能。

技术架构与数据流

我们通过 Mermaid 图来深入解析其内部架构。从用户发起请求到数据处理及结果反馈的过程如下:

graph TD A[用户请求] --> B{"参数校验"} B -->|"通过"| C[执行仿真] C --> D[生成图表] D --> E[结果反馈] B -->|"失败"| F[返回错误]
  • 参数校验:接收客户端发送的 PID 参数,并进行合法性验证。
  • 执行仿真:通过仿真引擎计算 PID 响应曲线。
  • 生成图表:将仿真结果绘制在图表中,提供直观的视觉分析。
  • 结果反馈:将生成的图表和相关数据返回给客户端。

技术栈与设计模式

Plasmatree/PID-Analyzer 使用了现代 Web 开发技术栈,包括 React.js 用于前端界面、Spring Boot 用于后端服务以及 FlexCAN 库进行数据处理。其设计模式包括 MVC(模型-视图-控制器)和 Observer(观察者模式)。

  • MVC 模式:通过这种模式,实现了清晰的职责划分。数据处理逻辑位于模型层,视图层与模型层解耦,提高了代码的可维护性。
  • Observer 模式:用于实现实时更新。观察者模式使得前端界面可以实时响应后端返回的新数据,提供了更好的用户体验。

功能亮点与差异

PID-Analyzer 的优势在于其简洁直观的用户界面以及对 PID 参数追溯能力。用户可以快速配置并仿真不同参数下的控制效果,其仿真的精度和实时反馈性能远超同类工具。

差异分析

  • 可视化:提供多种可视化方式展示 PID 控制效果,使得用户能够直观理解参数调整的影响。
  • 参数优化:自动生成参数优化建议,并附有许多对应的理论知识,帮助用户深刻理解 PID 控制理论。
  • 跨平台支持:兼容多种操作系统和编程语言,为广泛的用户群体服务。

应用场景与落地建议

PID-Analyzer 适合涉及多类型控制系统的工业企业、研究机构和教育机构。例如,自动化生产线、机器人组装线以及各种闭环反馈系统,都可在生产设计和研发阶段显著受益于此工具。

使用注意事项

  • 内存消耗:在高并发情况下建议监控内存占用情况,避免过大的数据量导致资源耗竭。
  • 前台性能:高密度数据推送给客户端会导致前端界面卡顿,必须在发送大量数据时设置合理的速率限制。
  • 环境兼容性:确保宿主机系统支持所需依赖库的版本。

综合评价

优点:

  • 提供高质量的可视化反馈,有助于用户快速了解控制系统的特性;
  • 优化建议生成功能大幅降低调优难度;
  • 适用于多种场景,提供丰富的实验材料。

缺点:

  • 对于复杂系统可能需要对底层原理解更深入的了解,这或许会增加配置难度。

总的来说,Plasmatree/PID-Analyzer 是一个值得推荐的工具,尤其适合寻求自动化控制系统优化的用户。它在简化工作流程同时提供了高性能和高可视化效果,使得科学家与工程师能够专注于他们的研究,而非重复性的优化工作。

简要分析

热度分
714
价值分
299
活跃状态
活跃

语言占比

Python

Release

README

PID-Analyzer 0.52 changes:

  • Fixed the noise plot ranges for better visual comparability with option for custom or auto range
  • slight change to s/n in deconvolution: Gaussian instead of digital s/n

PID-Analyzer

This program reads Betaflight blackbox logs and calculates the PID step response. It is made as a tool for a more systematic approach to PID tuning.

The step response is a characteristic measure for PID performance and often referred to in tuning techniques. For more details read: https://en.wikipedia.org/wiki/PID_controller#Manual_tuning The program is Python based but utilizes Blackbox_decode.exe from blackbox_tools (https://github.com/cleanflight/blackbox-tools) to read logfiles.

As an example: This was the BF 3.15 stock tune (including D Setpoint weight) on my 2.5" CS110: stock tune

This a nice tune I came up with after some testing: good tune

You can even use angle mode, the result should be the same! The program calculates the system response from input (PID loop input = What the quad should do) and output (Gyro = The quad does). Mathematically this is called deconvolution, which is the invers to convolution: Input * Response = Output. A 0.5s long response is calculated from a 1.5s long windowed region of interest. The window is shifted roughly 0.2s to calculate each next response. From a mathematical point of view this is necessary, but makes each momentary response correspond to an interval of roughly ±0.75s.

Any external input (by forced movement like wind) will result in an incomplete system and thus in a corrupted response. Based on RC-input and quality the momentary response functions are weighted to reduces the impact of corruptions. Due to statistics, more data (longer logs) will further improve reliability of the result.

If D Setpoint Transition is set in Betaflight, your tune and thus the response will differ for high RC-inputs. This fact is respected by calculating separate responses for inputs above and below 500 deg/s. With just moderate input, you will get one result, if you also do flips there will be two.

Keep in mind that if you go crazy on the throttle it will cause more distortion. If throttle-PID-attenuation (TPA) is set in Betaflight there will be a different response caused by a dynamically lower P. This is the reason why the throttle and TPA threshold is additionally plotted.

The whole thing is still under development and results/input of different and more experienced pilots will be appreciated!

Requirements

To install required Python libraries, view the list of packages in requirements.txt or simply run:

sudo apt-get install python3-pip python3-tk
sudo pip3 install -r requirements.txt

How to use this program:

  1. Record your log. Logs of 20s seem to give sufficient statistics. If it’s slightly windy, longer logs can still give reasonable results. You can record multiple logs in one session: Each entry will yield a seperate plot.
  2. Place your logfiles, blackbox_decode.exe (Windows download) and PID-Analyzer.exe (Windows download) in the same folder. You can also specify where to find these executables via command-line flags.
  3. Run PID-Analyzer.exe (this takes some seconds, it sets up a complete virtual python environment). Either interactively enter your .BBL files (drop one or more logs into cmd), or pass your .BBL file(s) via flags, like PID-Analyzer --log one.BBL --log two.BBL directly when run in cli mode.
  4. The logs are separated into temp files, read, analyzed and temp files deleted again.
  5. A plot window opens and a .png image is saved automatically in the folder correspoding to you entered name (default is \tmp).

The windows executable includes a virtual python environment and only requires you to drag and drop your Betaflight blackbox logfile into the cmd window.

In case of problems (if the cmd closes for example), please report including the log file.

Tested on Win7/10 and MacOS 10.10, with 3.15/3.2/3.3 logs.

Happy tuning,

Flo

评论

暂无评论