Li Weiyi
/
BalanceCar
虽然移植完毕,但是不work。需要细调……
Diff: SomeTest.cpp
- Revision:
- 2:99785a1007a4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SomeTest.cpp Tue Jun 07 05:26:03 2016 +0000 @@ -0,0 +1,164 @@ +#include "SomeTest.h" +#include "mbed.h" + +extern DigitalOut myled; +Ticker myTicker; +Ticker myTicker1; +Serial mpc(P0_4,P0_0); +#if 0 +#include "RollPitch.h" + +extern MPU6050 mpu; +extern Timer g_Timer; + +float ypr[3]; //Yaw,Pitch,Roll三个轴的角度值 +void testMPU6050(void) +{ + mpc.baud(115200); + bool ret = dmpSetup(); + if (ret == true) { + mpc.printf("dmp ready\r\n"); + } else { + mpc.printf("dmp not ready\r\n"); + } + dmpGetYPR(ypr); + mpc.printf("ypr[0] = %f, ypr[1] = %f, ypr[2] = %f\r\n", ypr[0], ypr[1], ypr[2]); + while (1) { + wait(0.5); + dmpGetYPR(ypr); + mpc.printf("ypr[0] = %f, ypr[1] = %f, ypr[2] = %f\r\n", ypr[0], ypr[1], ypr[2]); +#if 0 + if (mpu.testConnection() == true) + mpc.printf("connect ok\r\n"); +#endif + } +} +#endif + +static void flip() +{ + static uint32_t c = 0; + c++; + if ((c % 2000) == 0) { + myled = !myled; + } +} +void testTicker(void) +{ + myTicker.attach_us(&flip, 25); + while (1) {} +} +#if 0 +#define PIN_EN 4 //PORTB,0 +#define PIN_DIRA A0 //PORTA,7 +#define PIN_STEPA 5 //PORTB,1 +#define PIN_DIRB A1 //PORTA,6 +#define PIN_STEPB 6 //PORTB,2 +#define PIN_DIRC A2 //PORTA,5 +#define PIN_STEPC 7 //PORTB,3 +#define PIN_DIRD A3 //PORTA,4 +#define PIN_STEPD 8 //PORTD,6 +#else +#define PIN_EN P0_25 +#define PIN_DIRA P0_7 +#define PIN_STEPA P0_24 + +#define PIN_DIRB P0_6 +#define PIN_STEPB P0_1 + +#define PIN_DIRC P0_14 +#define PIN_STEPC P0_20 +#define PIN_DIRD P0_23 +#define PIN_STEPD P0_19 +#endif +#if 0 +//Stepper stepperL(PIN_DIRB, PIN_STEPB); //左电机,使用stepper底板A接口 +//Stepper stepperR(PIN_DIRA, PIN_STEPA); //右电机,使用stepper底板D接口 +DigitalOut LdirB(PIN_DIRB); +DigitalOut LstepB(PIN_STEPB); +DigitalOut RdirB(PIN_DIRA); +DigitalOut RstepB(PIN_STEPA); +DigitalOut SteperE(PIN_EN); +static void timeHandle_left(void) +{ + //LstepB = !LstepB; + LstepB = 1; + wait_us(1); + LstepB = 0; +} + +static void timeHandle_right(void) +{ + //LstepB = !LstepB; + RstepB = 1; + wait_us(1); + RstepB = 0; +} + +void testStepper(void) +{ + SteperE = 1; + LdirB = 0; + RdirB = 0; + LstepB = 0; + RstepB = 0; + myTicker.attach_us(&timeHandle_left, 510); + myTicker1.attach_us(&timeHandle_right, 2500); + SteperE = 0; + while (1) {} +} +#endif + +#if 0 +DigitalOut SteperE(PIN_EN); +DigitalOut Rdir(PIN_DIRA); +PwmOut rstep(PIN_STEPA);//P0_24, D5 +#if 1 +DigitalOut Ldir(PIN_DIRB); +PwmOut lstep(PIN_STEPB);//P0_1, D6 +#endif + +void testStepper1(void) +{ + int widthL = 1; + int widthR = 1; + int period = 410; // 2500Hz + myled = 0; + SteperE = 0; + + Rdir = 1; + rstep.period_us(period); + rstep.pulsewidth_us(widthR); + + #if 1 + Ldir = 1; + lstep.period_us(period); + lstep.pulsewidth_us(widthL); + #endif + + //wait(2.0); + //SteperE = 0; + while (1) { + #if 0 + wait(0.1); + widthR += 50; + if (widthR >= 1500) { + widthR = 0; + } + rstep.pulsewidth_us(widthR); + + widthL += 50; + if (widthL >= 500) { + widthL = 0; + } + lstep.pulsewidth_us(widthL); + #else + period += 20; + lstep.period_us(period); + rstep.period_us(period); + //myled = !myled; + wait(0.5); + #endif + } +} +#endif \ No newline at end of file