LPC824

Dependencies:   mbed

Fork of CubeFine by wu le

Committer:
beian10
Date:
Mon Jul 04 07:17:39 2016 +0000
Revision:
2:7964622fb5a5
Parent:
1:54a2d380f8c7
V2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lixianyu 0:362c1482232c 1 #include "mbed.h"
lixianyu 0:362c1482232c 2 #include "MicroduinoPinNames.h"
lixianyu 0:362c1482232c 3 #include "userDef.h"
lixianyu 0:362c1482232c 4 #include "Protocol.h"
lixianyu 0:362c1482232c 5 #include "Microduino_Motor.h"
lixianyu 0:362c1482232c 6
beian10 1:54a2d380f8c7 7
lixianyu 0:362c1482232c 8 Timer g_cubeTimer;
beian10 1:54a2d380f8c7 9 //Timeout g_cubeTimeout;
beian10 2:7964622fb5a5 10
lixianyu 0:362c1482232c 11 Motor MotorLeft(motor_pin0A, motor_pin0B);
lixianyu 0:362c1482232c 12 Motor MotorRight(motor_pin1A, motor_pin1B);
lixianyu 0:362c1482232c 13 ///////////////////////////////////////////////////////////
lixianyu 0:362c1482232c 14 #define CHANNEL_NUM 8
lixianyu 0:362c1482232c 15 uint16_t channalData[CHANNEL_NUM]; //8通道数据
lixianyu 0:362c1482232c 16 bool mode = 0; //nrf或者ble模式
lixianyu 0:362c1482232c 17 int16_t throttle = 0; //油门
lixianyu 0:362c1482232c 18 int16_t steering = 0; //转向
lixianyu 0:362c1482232c 19 int safe_ms = 0;
beian10 2:7964622fb5a5 20
lixianyu 0:362c1482232c 21 static long map(long x, long in_min, long in_max, long out_min, long out_max)
lixianyu 0:362c1482232c 22 {
lixianyu 0:362c1482232c 23 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
lixianyu 0:362c1482232c 24 }
lixianyu 0:362c1482232c 25
lixianyu 0:362c1482232c 26 int main()
lixianyu 0:362c1482232c 27 {
beian10 2:7964622fb5a5 28
beian10 2:7964622fb5a5 29 g_cubeTimer.start();
lixianyu 0:362c1482232c 30
lixianyu 0:362c1482232c 31 mode = protocolSetup(); //遥控接收器初始化
lixianyu 0:362c1482232c 32
lixianyu 0:362c1482232c 33 MotorLeft.Fix(motor_fixL);
lixianyu 0:362c1482232c 34 MotorRight.Fix(motor_fixR);
beian10 2:7964622fb5a5 35
beian10 1:54a2d380f8c7 36
lixianyu 0:362c1482232c 37 while (1) {
beian10 1:54a2d380f8c7 38
lixianyu 0:362c1482232c 39 if (protocolRead(channalData, mode)) { //判断是否接收到遥控信号
lixianyu 0:362c1482232c 40 throttle = map(channalData[CHANNEL_THROTTLE], 1000, 2000, -MAX_THROTTLE, MAX_THROTTLE);
lixianyu 0:362c1482232c 41 steering = map(channalData[CHANNEL_STEERING], 1000, 2000, -MAX_STEERING, MAX_STEERING);
lixianyu 0:362c1482232c 42
lixianyu 0:362c1482232c 43 MotorLeft.Driver(MotorLeft.GetData(throttle, steering, CHAN_LEFT));
lixianyu 0:362c1482232c 44 MotorRight.Driver(MotorRight.GetData(throttle, steering, CHAN_RIGHT));
lixianyu 0:362c1482232c 45
lixianyu 0:362c1482232c 46 safe_ms = g_cubeTimer.read_ms();
lixianyu 0:362c1482232c 47 }
lixianyu 0:362c1482232c 48
lixianyu 0:362c1482232c 49 if (safe_ms > g_cubeTimer.read_ms()) {
lixianyu 0:362c1482232c 50 safe_ms = g_cubeTimer.read_ms();
lixianyu 0:362c1482232c 51 }
lixianyu 0:362c1482232c 52 if (g_cubeTimer.read_ms() - safe_ms > SAFE_TIME_OUT) {
lixianyu 0:362c1482232c 53 MotorLeft.Free();
lixianyu 0:362c1482232c 54 MotorRight.Free();
lixianyu 0:362c1482232c 55 }
beian10 1:54a2d380f8c7 56
lixianyu 0:362c1482232c 57 } // while
beian10 2:7964622fb5a5 58 }