倒立摆演示和数学原理分析
1 前言和资料
倒立摆(Inverted Pendulum)是机器人和控制工程领域一个非常经典的模型,火箭、导弹、独轮车、双足机器人等,包括杂技演员的很多表演,都是倒立摆的变种。由于倒立摆的重心高于转动轴,本身属于不稳定系统,需要外界持续的干涉,不然摆杆就会掉下来。来个动图,大家直观感受一下:
除此之外,倒立摆本身也是研究实时性编程的经典样例:摆杆要想保持垂直,需要电机驱动小车不停地移动,而电机的反应依赖控制器,并要求控制器必须以更快的频率(比电机快)可靠不间断地更新数据。如果控制器运算出现了较大的延迟,那么摆杆就会不稳定甚至倒下。
本系列文章我们不研究如何实现一个真正的倒立摆项目(类似上图),而是研究 ros2 开源库里的 pendulum 倒立摆,其使用了 rviz 对倒立摆进行了仿真,并作为样例展示了如何基于 ros2 进行实时性编程。
本文的重点有两个,一是 pendulum 倒立摆 演示,二是研究倒立摆的数学原理。
本文参考资料如下:
(0)wikipedia Inverted pendulum (需要翻墙)
(1)pendulum 倒立摆
(2)pendulum 倒立摆 design
(3)一级倒立摆控制 —— ROS2 仿真
(4)Modeling an Inverted Pendulum
(5)Inverted Pendulum: System Modeling
(6)线性系统大作业——1.一阶倒立摆建模与控制系统设计
(7)Inverted Pendulum: Control Theory and Dynamics
(8)倒立摆状态反馈控制——分析、建模与仿真(matlab)
本系列文章汇总:Ros2 实时性编程实践系列 – 倒立摆 Inverted Pendulum
2 正文
2.1 倒立摆演示
(1)本人的基础环境:
硬件:Thinkpad T14 i7 + Nvidia MX450。
操作系统:物理机安装 ubuntu22.04 ,不搞虚拟机,不搞双系统,运行效率最高。
ros2 版本:ros2 humble 。
(2)拉取 pendulum 倒立摆 源码并编译
mkdir -p ~/colcon_ws/src
cd ~/colcon_ws/src
git clone https://github.com/Jieshoudaxue/pendulum.git -b rolling
cd ~/colcon_ws
colcon build --packages-select pendulum pendulum2_msgs pendulum_utils pendulum_controller pendulum_driver pendulum_state_publisher pendulum_demo pendulum_bringup
(3)pendulum 倒立摆项目里面有多个软件包,其中在编译 pendulum_driver 时,遇到如下报错:
Starting >>> pendulum_driver
--- stderr: pendulum_driver
CMake Error at CMakeLists.txt:59 (find_package):
By not providing "Findapex_test_tools.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"apex_test_tools", but CMake did not find one.
Could not find a package configuration file provided by "apex_test_tools"
with any of the following names:
apex_test_toolsConfig.cmake
apex_test_tools-config.cmake
Add the installation prefix of "apex_test_tools" to CMAKE_PREFIX_PATH or
set "apex_test_tools_DIR" to a directory containing one of the above files.
If "apex_test_tools" provides a separate development package or SDK, be
sure it has been installed.
---
Failed <<< pendulum_driver [0.53s, exited with code 1]
原因是缺少 apex_test_tools 依赖,可以使用 rosdep 统一安装 pendulum 的所有依赖,然后继续编译。
cd ~/colcon_ws
rosdep install -q -y --from-paths src --ignore-src --rosdistro humble
colcon build --packages-select pendulum pendulum2_msgs pendulum_utils pendulum_controller pendulum_driver pendulum_state_publisher pendulum_demo pendulum_bringup
(4)编译完成后,运行 pendulum 倒立摆
cd ~/colcon_ws
source install/local_setup.bash
# 启动 rviz 查看
ros2 launch pendulum_bringup pendulum_bringup.launch.py rviz:=True
# 再开一个窗口,移动小车(别忘再次设置环境变量)
ros2 topic pub -1 /teleop pendulum2_msgs/msg/PendulumTeleop "cart_position: 5.0"
2.2 倒立摆数学原理
找了几篇博客,还没有推导明白,晚点补充!
3 总结
本文主要为大家引入倒立摆和 ros2 pendulum 倒立摆 项目,只剥了洋葱最外面那层。