> For the complete documentation index, see [llms.txt](https://songyibiao.gitbook.io/design-self-balancing-robot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://songyibiao.gitbook.io/design-self-balancing-robot/yuan-li-fen-xi-pian/a44.md).

# Simulink仿真

通过对两轮自平衡小车系统进行动力学分析和数学建模，在理论上设计出了控制方法。下面，调用 Matlab 软件的Simulink 仿真工具包对两轮自平衡小车的控制系统数学模型进行仿真验证，观察角度在干扰信号的作用下的自恢复情况。

在 Simulink 文件中，建立两轮自平衡小车的数学模型，调用 PID 控制器构成控制系统的主要部分。设定输入信号值为 0，代表角度初始值为 0，小车初始在平衡位置。对输出节点，调用两个 Step 模块，通过设定 Step Time，使之构成宽度为 1s 的脉冲信号作为小车的外力干扰作用信号。整体系统构成负反馈形式。

![两轮自平衡小车控制系统数学模型的 Simulink 仿真 alt ><](/files/-M67lYN0NAeM31PECDJN)

仿真系统中示波器 Angle 与 f 分别表示角度变化波形与外力作用信号波形。点击运行，可以看到外力作用为标准的脉冲信号。

![外界干扰信号波形图 alt ><](/files/-M67lYN1xtJZ5vQTnkUI)

此时，在脉冲信号作为干扰的情况下，Angle 示波器中显示了车体角度的变化值。

![车体角度自恢复过程仿真波形 alt ><](/files/-M67lYN2TRn7HSUWDK90)

通过波形可以看出，角度在外界干扰的情况下，能够在一定时间内自动恢复到稳定状态。这证明了前文建立的两轮自平衡小车控制系统的数学模型是有效的，也为接下来设计小车的软硬件系统提供了坚实的控制理论基础。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://songyibiao.gitbook.io/design-self-balancing-robot/yuan-li-fen-xi-pian/a44.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
