自平衡小车设计
摘要
这些年来,两轮自平衡车的应用获得了十分快速的应用和发展。本文提出了一种两轮的自平衡小车的设计,采用陀螺仪ENC-03以及MEMS加速度传感器MMA7260构成小车姿态检测装置,使用卡尔曼滤波完成陀螺仪数据与加速度计数据的数据融合。系统选用飞思卡尔16位单片机MC9S12XS128为控制核心,完成了传感器信号的处理,滤波算法的实现及车身控制,人机交互等。
整个系统在制作完成后,各个模块之间能够协调工作,小车也可以在无人干预的条件下达到自主平衡。同时在引入适量的干扰情况下小车也能够自主调整状态并迅速恢复稳定的状态。小车可以被控制实现前进、后退、左右转向等动作。
关键词:自平衡 stm32 姿态 滤波
I
Design of Self-Balance Vehicle
Abstract
In recent years, the application of two wheeled self balancing vehicle has been very rapid application and development. In this paper, we propose a two rounds of self balance car design, car attitude detection device by gyroscope enc-03 and MEMS accelerometer MMA7260 and Kalman filtering is used to complete data of a gyroscope and accelerometer meter data fusion. The system selects the flying thought Carle 16 bit single chip microcomputer MC9S12XS128 as the control core, completed the sensor signal processing, the filter algorithm realization and the vehicle body control, human computer interaction and so on.
After the completion of the entire system, the various modules can work in coordination, the car can also be under the conditions of unmanned intervention to achieve self balancing. At the same time in the introduction of the amount of interference in the case of the car can also adjust the state and quickly return to a stable state. The car can be controlled to achieve forward, backward, left and right steering and so on.
Key Words: Two-Wheel Self-Balance; Gyroscope; Gesture detection; Kalman filter; Data fusion
II
目 录
1.绪论 ························································································· 1
1.1研究背景与意义 ······················································································· 1 1.3本文主要研究目标与内容 ··········································································· 1 1.4论文章节安排 ·························································································· 2
2.系统原理分析 ············································································· 3
2.1控制系统要求分析 ···················································································· 3 2.2平衡控制原理分析 ···················································································· 3 2.3自平衡小车数学模型 ················································································· 4 2.3.1两轮自平衡小车受力分析 ····································································· 4 2.3.2自平衡小车运动微分方程 ····································································· 7 2.4 PID控制器设计 ······················································································· 8 2.4.1 PID控制器原理 ·················································································· 8 2.4.2 PID控制器设计 ·················································································· 9 2.5姿态检测系统 ························································································ 10 2.5.1陀螺仪 ···························································································· 10 2.5.2加速度计 ························································································· 11 2.5.3基于卡尔曼滤波的数据融合 ································································ 12 2.6本章小结 ······························································································ 14
3.系统硬件电路设计 ······································································ 15
3.1 MC9SXS128单片机介绍 ·········································································· 15 3.2单片机最小系统设计 ··············································································· 17 3.3 电源管理模块设计 ················································································· 19 3.4倾角传感器信号调理电路 ········································································· 20 3.4.1加速度计电路设计 ············································································ 20 3.4.2陀螺仪放大电路设计 ········································································· 20 3.5电机驱动电路设计 ·················································································· 21 3.5.1驱动芯片介绍 ··················································································· 22 3.5.2 驱动电路设计 ·················································································· 22
III
3.6速度检测模块设计 ·················································································· 23 3.6.1编码器介绍 ······················································································ 23 3.6.2 编码器电路设计 ··············································································· 24 3.7辅助调试电路 ························································································ 25 3.8本章小结 ······························································································ 25
4.系统软件设计 ············································································ 26
4.1软件系统总体结构 ·················································································· 26 4.2单片机初始化软件设计 ············································································ 26 4.2.1锁相环初始化 ··················································································· 26 4.2.2模数转换模块(ATD)初始化 ····························································· 27 4.2.3串行通信模块(SCI)初始化设置 ························································· 28 4.2.4测速模块初始化················································································ 29 4.2.5 PWM模块初始化 ·············································································· 30 4.3姿态检测系统软件设计 ············································································ 30 4.3.1陀螺仪与加速度计输出值转换 ····························································· 30 4.3.2卡尔曼滤波器的软件实现 ··································································· 32 4.4平衡PID控制软件实现 ··········································································· 34 4.5两轮自平衡车的运动控制 ········································································· 35 4.6本章小结 ······························································································ 37
5. 系统调试 ················································································· 38
5.1系统调试工具 ························································································ 38 5.2系统硬件电路调试 ·················································································· 38 5.3姿态检测系统调试 ·················································································· 39 5.4控制系统PID参数整定 ··········································································· 41 5.5两轮自平衡小车动态调试 ········································································· 42 5.6本章小结 ······························································································ 43
6. 总结与展望 ·············································································· 44
6.1 总结 ··································································································· 44 6.2 展望 ··································································································· 44
参考文献 ···················································································· 45
IV
附 录 ······················································································· 46
附录一 系统电路原理图 ··············································································· 46 附录二 系统核心源代码 ··············································································· 47
致谢 ·························································································· 50
V