基于STC单片机的两轮平衡车设计
2021-08-26戴庆
戴庆



摘 要:本项目代码基于C语言开发,选用宏晶科技有限公司的8位单片机STC8A8K64S4A12作为主控制器,采用重力加速度陀螺仪传感器MPU-6050获取重力加速度和角度数据,通过互补滤波对获取的数据进行数据融合从而得到小车姿态。经过PID算法处理后,系统输出PWM(脉冲宽度调制)控制信号到电机驱动芯片BTN7971B,以控制小车的两个电机的正反转和转速,使小车保持平衡状态。同时,使用旋转编码器获取小车的速度信息,通过PID算法将PWM输出并加以融合,从而实现小车的速度与方向控制。
关键词:STC8A8K64S4A12;角度检测;PID算法;互补滤波
中图分类号:TP368.1;TP242 文献标识码:A 文章编号:1003-5168(2021)09-0015-03
Abstract: The code of this project is developed based on C language, the 8-bit single-chip microcomputer STC8A8K64S4A12 from STC MCU Limited is selected as the main controller, and the gravity acceleration gyroscope sensor MPU-6050 is used to obtain the gravity acceleration and angle data, and the obtained data is fused through complementary filtering to obtain the car attitude. After PID algorithm processing, the system outputs PWM (Pulse Width Modulation) control signal to the motor drive chip BTN7971B, in order to control the forward and reverse rotation and speed of the two motors of the trolley, so that the trolley maintains a balanced state. At the same time, the rotary encoder is used to obtain the speed information of the trolley, and the PWM output is combined through the PID algorithm to realize the speed and direction control of the trolley.
Keywords: STC8A8K64S4A12;angle detection;PID algorithm;complementary filtering
近年来,随着科学技术的发展,两轮平衡车逐渐进入人们的视野,以小米科技有限责任公司的产品为代表,作为一种短途的交通工具,具有极高的趣味性和便利性。平衡车研究始于日本,高速发展于美国,国内研究始于中国科学技术大学、西安交通大学等科研单位,然后研究成果逐渐被科技公司应用于日常生活中,作为短途的交通工具、物品运输载体和智能机器人等,而这都取决于其独特的驱动方式,能够使产品体积小巧,运动也更加灵活和便捷,其能够在狭窄的环境中运行。
两轮平衡车状态不稳定,人们需要通过一些外部的力使其平衡。车辆模型的直立需要不停地调节电机的转动,使本身稳定在一个状态;调节车辆模型的速度时,人们需要改变车辆模型的倾角,倾倒时,车辆模型需要一个同方向的加速度来保持稳定,倾角越大,加速度也越大,从而完成速度的控制。……
