亮 菅野 / Mbed 2 deprecated Test_sensor_program

Dependencies:   mbed Servo MPU6050 BMX055 HMC5883L GPS_Interface

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "HMC5883L.h"
00002 #include "main.h"
00003 #include "MPU6050.h"
00004 #include "BMX055.h"
00005 #include "Servo.h"
00006 #include "GPS.h"
00007 #include "mbed.h"
00008 //#include "SDFileSystem.h"
00009 
00010 Serial pc(USBTX, USBRX,115200);    // tx, rx
00011 
00012 Serial twelite(A7,A2,115200);
00013 
00014 #ifdef SDCARD
00015 SDFileSystem sd(A6,A5,A4,A3, "sd"); // the pinout on the mbed Cool Components workshop board
00016 //              mosi,miso,sck,ss(io)
00017 #endif
00018 
00019 GPS michibiki(GPSTX,GPSRX);//通常のシリアル通信同じく、gpsのtxをマイコンのrxにつなげる。
00020 
00021 #ifdef AXIS_NINE
00022 BMX055 bmx(D4,D5);
00023 #endif
00024 
00025 
00026 HMC5883L compass(D4,D5);    //SDA,SCL
00027 
00028 MPU6050 mpu(D4,D5);
00029 
00030 /*==================servo_test======================*/
00031 DigitalOut myled(D12);
00032 DigitalOut myled2(A0);
00033 Servo myservo(D6);
00034 Servo myservo2(D10);
00035 /*                                                  */
00036 /*                                                  */
00037 /*==================================================*/
00038 
00039 float mpu_acce[3];
00040 float mpu_gyro[3];
00041 int16_t hmc_data[3] = {0};
00042 double heading = 0.0f;
00043 
00044 void pc_tx()//シリアル割り込み
00045 {
00046         mpu.setAcceleroRange(MPU6050_ACCELERO_RANGE_4G);
00047         mpu.getAccelero(mpu_acce);
00048         mpu.getAcceleroRawZ();
00049         int a = 0x58;
00050         for(int l = 0; l < 3; l++) 
00051         {
00052             printf("%c%c%c%c%c %c  %f\t",0x61,0x63,0x63,0x65,0x6c,a,mpu_acce[l]);
00053             a++;
00054         }
00055         a = 0x58;
00056         mpu.getGyro(mpu_gyro);
00057         for(int l = 0; l < 3; l++) 
00058         {
00059             printf("%c%c%c%c %c  %f\t",0x67,0x79,0x72,0x6f,a,mpu_gyro[l]);
00060             a++;
00061         }
00062         printf("\r\n");
00063         
00064         //        printf("gy_271start\r\n"); //debug
00065         compass.getXYZ(hmc_data);
00066         heading = compass.getHeadingXYDeg();
00067         printf("x: %4d, y: %4d, z: %4d\n", hmc_data[0], hmc_data[1], hmc_data[2]);
00068         printf("heading: %3.2f\r\n", heading);
00069         
00070         printf("%f %f\r\n",michibiki.latitude,michibiki.longtitude);    
00071 }
00072 
00073 
00074 int main()
00075 {
00076     pc.attach(pc_tx,Serial::TxIrq);
00077     /*===================SDcard=========================*/
00078     /*                                                  */
00079     /*                                                  */
00080 #ifdef SDCARD
00081     printf("Hello World!\n");
00082 
00083     mkdir("/sd/mydir", 0777);
00084 
00085     FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
00086     if(fp == NULL) {
00087         error("Could not open file for write\n");
00088     }
00089     fprintf(fp, "Hello fun SD Card World!");
00090     fclose(fp);
00091 
00092     printf("Goodbye World!\n");
00093 
00094 #endif
00095     /*                                                  */
00096     /*                                                  */
00097     /*==================================================*/
00098 
00099     /*===================MPU6050========================*/
00100     /*                                                  */
00101     /*                                                  */
00102     /*                                                  */
00103 #ifdef MPU6050_START
00104     mpu.setAcceleroRange(0);
00105 #endif
00106     /*                                                  */
00107     /*                                                  */
00108     /*==================================================*/
00109 
00110 
00111     /*============================================*/
00112     /*                                                  */
00113     /*                                                  */
00114     /*                                                  */
00115 
00116 #ifdef GY_271
00117     compass.init();
00118 #endif
00119     /*                                                  */
00120     /*                                                  */
00121     /*                                                  */
00122     /*==================================================*/
00123 
00124 
00125 
00126 
00127     /*===================GY_271=========================*/
00128     /*                                                  */
00129     /*                                                  */
00130     /*                                                  */
00131 
00132     while(1) {
00133         //printf("while start\r\n"); //debug
00134 
00135 
00136 #ifdef GY_271
00137         
00138 #endif
00139         /*                                                  */
00140         /*                                                  */
00141         /*                                                  */
00142         /*==================================================*/
00143 
00144 
00145         /*===================MPU6050========================*/
00146         /*                                                  */
00147         /*                                                  */
00148         /*                                                  */
00149 #ifdef MPU6050_START
00150 #endif
00151         /*                                                  */
00152         /*                                                  */
00153         /*==================================================*/
00154 
00155         /*=================servo_test=======================*/
00156 #ifdef servo_test
00157         myservo = 0.833;
00158         myservo2 = 0.833;
00159         wait(1.0);
00160         myservo = 0.1666;
00161         myservo2 = 0.1666;
00162         wait(1.0);
00163 #endif
00164         /*==================================================*/
00165 
00166 #ifdef TWELITE
00167         /*=====================TWELITE======================*/
00168 //        twelite.printf("main\r\n");
00169         wait_ms(1);
00170         /*==================================================*/
00171 #endif
00172         
00173         #ifdef MICHIBIKI
00174         /*=====================MICHIBIKI======================*/
00175         printf("%f %f\n",michibiki.latitude,michibiki.longtitude);
00176         wait_ms(1);
00177         /*==================================================*/
00178         
00179         #endif
00180     }
00181 
00182 
00183 }