|
|
本帖最后由 迷你强 于 2015-12-5 10:13 编辑
这是总体的效果图
工作原理:
两轮自平衡小车在完成自身平衡的同时能够完成运动控制和适应不同环境的其它控制任务。我们利用陀螺仪和加速度传感器MPU6050来检测车体状态的变化,并利用直流光电编码电机控制驱动,精确控制电机进行相应的调整,以保持系统的平衡
小伙伴们看到这里是不是觉得心痒痒的呀~~~
材料准备:
0824双孔梁144 1
25mm直流电机连接片 2
同步带轮90T 2
轮胎68.5x22mm 2
法兰盘 4mm 2
螺丝M4*8 22
螺丝M4*16 4
尼龙柱30mm 6
塑料铆钉M4*8mm 4
亚克力板B 2
Orion主控板 1
直流编码电机扩展包(包含2个25mm直流编码电机) 1
陀螺仪传感器 1
红外接收模块 1
红外遥控器 1
18650锂电池 1
RJ25连接线20cm 3
六角扳手
十字起子
制作步骤:
搭建底盘,由一根双孔梁作为整个小车的主要支架,底两侧安装25mm编码直流电机。
一会儿就如是说
将车轮固定在编码电机输出轴上,就是下面酱紫
安装主控板和其它电子模块
将亚克力支架固定在双孔梁上的内螺纹槽中。同时压住编码电机的连接线。
安装剩余的电子模块以及连线(编码电机驱动接Port 1、陀螺仪接Port 8、红外接收器接Port 6)
用魔术贴将电池固定在小车顶部,完成搭建
使用方法:
打开电源开关,先将小车放倒在地面,待电机停止转动后,扶正小车后并复位主控板。小车将在2秒内转为平衡状态。用红外遥控器方向键控制小车前进后左右转弯。
Arduino代码
- #include "MeOrion.h"
- #include "MeEncoderMotor.h"
- #include "MeSerial.h"
- #include "MeInfraredReceiver.h"
- #include <Wire.h>
- #include <SoftwareSerial.h>
-
- #define RELAX_ANGLE 7.5 //Nature Balance Angle
- #define MOTOR_ENABLE //Enable Motor
-
- /**************Line Finder***************/
- #define LED_1 !(PINB&(1<<0)) //8
- #define LED_2 !(PIND&(1<<2)) //2
- #define LED_3 !(PINB&(1<<4)) //12
- #define LED_4 !(PINB&(1<<5)) //13
-
- /***************Regist Flags***************/
- #define COMDONE 0x0001 //Frame Command End
- #define MOVING 0x0002 //Moving
- #define TRACING 0x0004 //Tracing
- #define START 0x0008 //Start
-
- MeEncoderMotor encoder;
- MeInfraredReceiver ir(PORT_6);
-
- /***************MPU6050 Define**********************/
- double accX, accY, accZ;
- double gyroX, gyroY, gyroZ;
- double compAngleY, gyroYangle;
- int16_t tempRaw;
- uint32_t IMU_timer;
- uint8_t i2cData[14];
-
- /***************PID Define**********************/
- typedef struct
- {
- double P, I, D;
- double Setpoint, Output, Integral, last_error;
- uint32_t Timer;
- } PID;
-
- PID PID_angle, PID_speed, PID_turn;
-
- uint32_t FLAG;
- char comdata[19], data_p; //Serial Data
- float joy_x, joy_y;
-
- void setup()
- {
- /*********************Initialize********************/
- Serial.begin(115299); //Serial
- Wire.begin(); //I2C Wire
- ir.begin(); //Infred Received
- /*********************MPU6050 initialize********************/
- i2cData[0] = 7;
- i2cData[1] = 0x00;
- i2cData[2] = 0x00;
- i2cData[3] = 0x00;
- while (i2cWrite(0x19, i2cData, 4, false));
- while (i2cWrite(0x6B, 0x01, true));
- while (i2cRead(0x75, i2cData, 1));
- if (i2cData[0] != 0x68)
- while (1);
- delay(100);
-
- while (i2cRead(0x3B, i2cData, 6));
- accX = (i2cData[0] << 8) | i2cData[1];
- accY = (i2cData[2] << 8) | i2cData[3];
- accZ = (i2cData[4] << 8) | i2cData[5];
- tempRaw = (i2cData[6] << 8) | i2cData[7];
-
- double pitch = atan(-accY / sqrt(accX * accX + accZ * accZ)) * RAD_TO_DEG;
- gyroYangle = pitch;
- compAngleY = pitch;
- IMU_timer = micros();
-
- /*********************Encoder********************/
- encoder.begin();
- encoder.setMode(0, 1); //pwm mode
- encoder.setMode(1, 1);
-
- /*********************PID Initialize********************/
- PID_angle.Setpoint = RELAX_ANGLE;
- PID_angle.P = 22.0; //18
- PID_angle.I = 0.05; //0.1
- PID_angle.D = 0.001; //0.0005
-
- PID_turn.P = 10;
- PID_turn.D = 30;
-
- PID_revalue();
- IMU_fillter();
- //FLAG |= TRACING;
- PID_speed.Setpoint = 0;
- gyroYangle = RELAX_ANGLE;
- compAngleY = RELAX_ANGLE;
- FLAG |= START;
-
- }
- long receiveTime = 0;
- void loop()
- {
- if(ir.buttonState()){
- while(ir.available()){
- parseJoystick(ir.read());
- receiveTime = micros();
- }
- }
- if(micros()-receiveTime>100000){
- receiveTime = micros();
- parseJoystick(0xFA);
- }
-
- IMU_fillter();
- PID_revalue();
- PID_angle_compute();
- PID_speed_compute();
- PID_angle_compute();
- }
复制代码
想知道更多在产品上面的应用可以看我们双十二双子星淘宝众筹哦~~~欢呼雀跃~~~~
https://izhongchou.taobao.com/dr ... 4BT&id=10051221
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|