![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
robot
Dependencies: ADXL345 AigamozuControlPackets HMC5843 ITG3200 MBed_Adafruit-GPS-Library XBee agzIDLIST mbed agz_common
Diff: main.cpp
- Revision:
- 1:490b793b2e61
- Parent:
- 0:7d55d6ace996
- Child:
- 2:95955f38f47a
diff -r 7d55d6ace996 -r 490b793b2e61 main.cpp --- a/main.cpp Tue May 20 14:51:25 2014 +0000 +++ b/main.cpp Wed May 21 01:23:04 2014 +0000 @@ -1,6 +1,8 @@ #include "mbed.h" #include "XBee.h" #include "MBed_Adafruit_GPS.h" +#include "VNH5019.h" + ///////////////////////////////////////// // //Connection Setting @@ -25,17 +27,7 @@ ///////////////////////////////////////// //Motor & Encorder Setting -//Left -DigitalOut motorL_A(p21); -DigitalOut motorL_B(p22); -PwmOut motorL_pwm(p23); -InterruptIn encoderR_A(p15); -InterruptIn encoderR_B(p16); - -//Rignt -DigitalOut motorR_A(p24); -DigitalOut motorR_B(p25); -PwmOut motorR_pwm(p26); +VNH5019 motorShield(p21,p22,p23,p24,p25,p26); //test data Ticker axis; @@ -113,70 +105,8 @@ uint8_t b[4]; }; - - - UNI_TEST_T latH,latL,lonH,lonL; - - - - -///////////////////////////////////////// -// -//Change Motor State Processing -// -///////////////////////////////////////// -void change_speed(unsigned char L_state,unsigned char L_pwm,unsigned char R_state,unsigned char R_pwm){ - switch(L_state){ - case 0: - motorL_A = 0; - motorL_B = 0; - break; - - case 1: - motorL_A = 1; - motorL_B = 0; - break; - - case 2: - motorL_A = 0; - motorL_B = 1; - break; - - default: - motorL_A = 0; - motorL_B = 0; - break; - } - - motorL_pwm = (float)L_pwm/256.0; - - switch(R_state){ - case 0: - motorR_A = 0; - motorR_B = 0; - break; - - case 1: - motorR_A = 1; - motorR_B = 0; - break; - - case 2: - motorR_A = 0; - motorR_B = 1; - break; - - default: - motorR_A = 0; - motorR_B = 0; - break; - } - motorR_pwm = (float)R_pwm/256.0; - - } - ///////////////////////////////////////// // //Interruption processing 1: time -> 0.1s @@ -204,7 +134,7 @@ if(manual_count > 100){ - change_speed(0,0,0,0); + motorShield.changeSpeed(0,0,0,0); manual_count = 0; } @@ -225,11 +155,11 @@ void randomRenovation(){ if(count < 30){ - change_speed(1,127,1,127); + motorShield.changeSpeed(1,127,1,127); } else{ - change_speed(1,127,2,127); + motorShield.changeSpeed(1,127,2,127); if(count > 35) count = 0; } count++; @@ -282,8 +212,6 @@ //interrupt start axis.attach(&axisRenovation, 0.1); - motorL_pwm = 0.0; - motorR_pwm = 0.0; refresh_Timer.start(); @@ -301,7 +229,7 @@ //ChanegeMode case 'C':{ my_mode = buf[19]; - change_speed(0,0,0,0); + motorShield.changeSpeed(0,0,0,0); if(my_mode == 2) auth_axis.attach(&randomRenovation, 1.0); else auth_axis.detach(); @@ -312,7 +240,7 @@ case 'M':{ if(my_mode == 1){ manual_count = 0; - change_speed(buf[20],buf[21],buf[23],buf[24]); + motorShield.changeSpeed(buf[20],buf[21],buf[23],buf[24]); } break;