毕业设计(论文)--基于单片机的两轮自平衡车控制系统设计 下载本文

基于单片机的两轮自平衡车控制系统设计

摘要

两轮自平衡车是一种高度不稳定的两轮机器人,就像传统的倒立摆一样,本质不稳定是两轮小车的特性,必须施加有效的控制手段才能使其稳定。本文提出了一种两轮自平衡小车的设计方案,采用重力加速度陀螺仪传感器MPU-6050检测小车姿态,使用互补滤波完成陀螺仪数据与加速度计数据的数据融合。系统选用STC公司的8位单片机STC12C5A60S2为主控制器,根据从传感器中获取的数据,经过PID算法处理后,输出控制信号至电机驱动芯片TB6612FNG,以控制小车的两个电机,来使小车保持平衡状态。

整个系统制作完成后,小车可以在无人干预的条件下实现自主平衡,并且在引入适量干扰的情况下小车能够自主调整并迅速恢复至稳定状态。通过蓝牙,还可以控制小车前进,后退,左右转。

关键词:两轮自平衡小车 加速度计 陀螺仪 数据融合 滤波 PID算法

I

Design of Control System of Two-Wheel Self-Balance Vehicle based on Microcontroller

Abstract

Two-wheel self-balance vehicle is a kind of highly unstable two-wheel robot. The characteristic of two-wheel vehicle is the nature of the instability as traditional inverted pendulum, and effective control must be exerted if we need to make it stable. This paper presents a design scheme of two-wheel self-balance vehicle. We need using gravity accelerometer gyroscope sensor MPU6050 for the inclination angle of vehicle, and using complementary filter for the data fusion of gyroscope and accelerometer. We choose an 8-bit microcontroller named STC12C5A60S2 from STC Company as main controller of the control system. The main controller output control signal, which is based on the data from the sensors, to the motor drive chip named TB6612FNG for controlling two motors of vehicle, and keeping the vehicle in balance. After the completion of the control system, the vehicle can achieve autonomous balance under the conditions of unmanned intervention, the vehicle can adjust automatically and restored to a stable state quickly in the case of giving appropriate interference as well. In addition, we can control the vehicle forward, backward and turn around.

Key words: Two-Wheel Self-Balance Vehicle; Accelerometer; Gyroscope; Data fusion; Complementary filter; PID algorithm

II

1 绪论 ....................................................................................................................................... 1 1.1 自平衡小车的研究背景 ................................................................................................ 1 1.2 自平衡小车研究意义 .................................................................................................... 1 1.3 论文的主要内容 ............................................................................................................ 2 2 课题任务与关键技术 ........................................................................................................... 2 2.1 主要任务 ........................................................................................................................ 2 2.2关键技术 ......................................................................................................................... 2 2.2.1 系统设计 ................................................................................................................. 2 2.2.2 数学建模 ................................................................................................................. 2 2.2.3姿态检测 .................................................................................................................. 3 2.2.4 控制算法 ................................................................................................................. 3 3 系统原理分析 ....................................................................................................................... 3 3.1 控制系统任务分解 ........................................................................................................ 3 3.2 控制原理 ........................................................................................................................ 4 3.3 数学模型 ........................................................................................................................ 5 4 系统硬件设计 ....................................................................................................................... 6 4.1 STC12C5A60S2单片机介绍 ............................................................................................ 7 4.2 电源管理模块 ................................................................................................................ 8 4.3 车身姿态感应模块 ........................................................................................................ 9 4.3.1 加速度计 ............................................................................................................... 10 4.3.2 陀螺仪 ................................................................................................................... 12 4.4 电机驱动模块 .............................................................................................................. 14 4.5 速度检测模块 .............................................................................................................. 16 5 系统软件设计 ..................................................................................................................... 16 5.1 软件系统总体结构 ...................................................................................................... 17 5.2 单片机的硬件资源配置 .............................................................................................. 18 5.2.1定时/计数器设置 .................................................................................................. 18 5.2.2 PWM输出设置 ...................................................................................................... 20 5.2.3 串行通信设置 ....................................................................................................... 23

III