[Learning record] Learning of simscape of matlab - modeling and simulation of single-stage inverted pendulum model under PID control

Preface

Always in the learning process. The content of the completion of the worker will use this part of the content, so here is a blog to make a small summary.

If simulink can help you do any simulation (yes, any simulation!), then simscape can help you complete simulations involving physics, mechanical engineering and other fields more quickly.

In the words of my teacher - semi-physical simulation?

This article aims to record some basic modules in simscape and build an application example of a single-stage inverted pendulum under PID control. I hope it will be helpful to friends who read this content!

text

First of all, there are actually simscape learning and using tutorials built into matlab, as shown in the figure below:

But, this tutorial is raw meat (English and no subtitles). So I found cooked meat on station b:

[Simscape Getting Started Tour] Familiar with the interface of Simscape Getting Started Tour_哔哩哔哩_bilibili

(Not just this one, there are several tutorials)

I haven't finished reading this tutorial yet, because my primary purpose is to use simscape to build a single-stage inverted pendulum model, so I found a treasure tutorial. Although it is faster and not too detailed, it is familiar enough for me. Simscape and build a simulation model of a stand-alone inverted pendulum (the link is at the end).


First create a simulink window, where you can choose to create a Multibody (multibody model) directly under simscape.

After opening, you will find some modules:

From top to bottom: the first one can be understood as a solver (controller?), the second one can be understood as a world coordinate, and the third one can be understood as the setting of the overall global parameters (gravity, x, y, z etc.)

This arrow is a signal converter. My understanding is to convert the input physical signal into a Simulink output signal. (The other arrow is to convert Simulink input signal to physical output signal).

This module is a coordinate conversion module. In the system, the reference system of the X, Y, and Z axes is determined by default, and many motion simulation modules can only move on the specified axes as required. Therefore, if you need to change the relative position of the module, you need to translate in space and move in the space. Rotation in space. This function can be implemented in the above module.

This is the rigid body module, which can set a rigid body with a certain size and length in space.

然后具体需要使用的物理模型,可以在Simulink Library Browser里面找到,具体路径如下图:

每个模型通过图标示意,以及具体的解释,就可以知道具体的使用方法、指代何种物理模型。并且每个模块都内置了很多功能,比如内置各种传感器。

以下为单级倒立摆的一个简单的一个搭建。

注意一下每个物理模型的使用的方向,以及需要使用的参数。

滑块模块:它只能在Z轴上平移,如果我们想让它在x轴上做平移运动,则需要提前进行坐标变换。考虑到滑块的输入端是由我们人为控制的,则需要设置Actuation中的力设置为自动计算,并且由输入端提供。

转动模块:只能在x,y平面绕着z轴旋转。由于需要检测倒立摆转动的角度,在这里选择一个角度传感器作为反馈信号。考虑到倒立摆竖直状态下,处于平衡状态,所以在这个地方可以给予它一个小的角度(10°)来让他摆动起来。

然后点击运行,则可以在隔壁matlab窗口看到一个这样的模型。

(emmm,实际状态是他在不受控制的转动,这里无法体现出来)

这里还会发现摆杆的运动会有些卡顿,可以在Model Settings里面调整求解器的步长(这里将最大步长设置为0.1)。重新启动后发现运动变得丝滑了。


接下来就是加入PID控制模块。这里直接接入了一个非常简单的PID模型。

将各模块连接后,一个简单的对PID控制下的单级倒立摆模型建模就完成了。

然后就是对参数P、I、D进行调整,这里随便输入了几个参数,得到以下结果。

可以看到窗口中倒立摆的运动是趋于平稳的,打开scope,可以看到系统是趋于稳定的。这和仿真结果相符。

结语

在学习过程中我只能感叹matlab功能的强大。学习的路还很长,还希望和各位技术人多多交流!

应用实例搭建源视频教程:matlab的simscape对PID控制下的倒立摆模型建模_哔哩哔哩_bilibili

Guess you like

Origin blog.csdn.net/weixin_47723114/article/details/129169751