still homotopy @FB

Fork of 130111_YNU_MPU_4 by yal kaiyo

Committer:
higedura
Date:
Sun Jan 06 07:11:34 2013 +0000
Revision:
1:ca296cfa603b
Parent:
0:9aa9be24636a
Child:
2:30f96c159d9c
YNU_MPU

Who changed what in which revision?

UserRevisionLine numberNew contents of line
higedura 0:9aa9be24636a 1 #include "mbed.h"
higedura 0:9aa9be24636a 2 #include "SDFileSystem.h"
higedura 0:9aa9be24636a 3
higedura 0:9aa9be24636a 4 #define pi 3.1416
higedura 0:9aa9be24636a 5 #define data 6
higedura 0:9aa9be24636a 6
higedura 0:9aa9be24636a 7 Serial pc(USBTX, USBRX);
higedura 0:9aa9be24636a 8 DigitalOut led1(LED1);
higedura 0:9aa9be24636a 9 DigitalOut led2(LED2);
higedura 0:9aa9be24636a 10 DigitalOut led3(LED3);
higedura 0:9aa9be24636a 11 DigitalOut led4(LED4);
higedura 0:9aa9be24636a 12
higedura 0:9aa9be24636a 13 SDFileSystem sd(p5, p6, p7, p8, "sd");
higedura 0:9aa9be24636a 14 Serial mavc(p9, p10);
higedura 0:9aa9be24636a 15 DigitalIn stop_sd(p11);
higedura 0:9aa9be24636a 16
higedura 0:9aa9be24636a 17 int main() {
higedura 1:ca296cfa603b 18
higedura 1:ca296cfa603b 19 // ******************** TORATANI ********************
higedura 1:ca296cfa603b 20 //pc.baud(921600);
higedura 0:9aa9be24636a 21 mavc.baud(115200);
higedura 0:9aa9be24636a 22
higedura 0:9aa9be24636a 23 char buf_char;
higedura 0:9aa9be24636a 24 unsigned int buf_hex[30] = {0};
higedura 0:9aa9be24636a 25 unsigned int buf_dec[10] = {0};
higedura 0:9aa9be24636a 26
higedura 0:9aa9be24636a 27 // rx
higedura 0:9aa9be24636a 28 double acc[3] = {0};
higedura 0:9aa9be24636a 29 double gyro[3] = {0};
higedura 0:9aa9be24636a 30 double azi;
higedura 0:9aa9be24636a 31 double alt;
higedura 0:9aa9be24636a 32 double GPS[2] = {0};
higedura 0:9aa9be24636a 33
higedura 0:9aa9be24636a 34 // tx
higedura 0:9aa9be24636a 35 double com[3] = {0};
higedura 0:9aa9be24636a 36 char H;
higedura 0:9aa9be24636a 37 char D[data];
higedura 0:9aa9be24636a 38 char test[9];
higedura 0:9aa9be24636a 39 H = 0x02; // header of dateset2
higedura 0:9aa9be24636a 40 D[0] = 0xff; D[1] = 0xff; // p_com
higedura 0:9aa9be24636a 41 D[2] = 0x7f; D[3] = 0xff; // q_com
higedura 0:9aa9be24636a 42 D[4] = 0x00; D[5] = 0x00; // r_com
higedura 1:ca296cfa603b 43 // ******************** TORATANI ********************
higedura 0:9aa9be24636a 44
higedura 0:9aa9be24636a 45 FILE *fp = fopen("/sd/sdtest.txt", "w");
higedura 0:9aa9be24636a 46 if(fp == NULL) {
higedura 0:9aa9be24636a 47 error("Could not open file for write\n");
higedura 0:9aa9be24636a 48 }
higedura 0:9aa9be24636a 49
higedura 1:ca296cfa603b 50 while(1){
higedura 0:9aa9be24636a 51 //for(int j=0;j<1800;j++){ flag tukuru // for 2 minuts
higedura 0:9aa9be24636a 52
higedura 0:9aa9be24636a 53 // ******************** sequence No.1 ********************
higedura 0:9aa9be24636a 54 buf_char = mavc.getc();
higedura 0:9aa9be24636a 55 buf_hex[0] = (unsigned int)buf_char;
higedura 0:9aa9be24636a 56 for(int i=0;i<29;i++){ buf_hex[29-i] = buf_hex[28-i]; }
higedura 0:9aa9be24636a 57 // !!! switch bun ni suru
higedura 0:9aa9be24636a 58 if(buf_hex[29]==0x40 && buf_hex[28]==0x43 && buf_hex[27]==0x4D && buf_hex[26]==0x0D){
higedura 0:9aa9be24636a 59 // ******************** sequence No.1 ********************
higedura 0:9aa9be24636a 60
higedura 0:9aa9be24636a 61 // ******************** sequence No.2 ********************
higedura 0:9aa9be24636a 62 // send to mavc
higedura 0:9aa9be24636a 63 mavc.putc(H);
higedura 0:9aa9be24636a 64 for(int i=0;i<data;i++){ mavc.putc(D[i]); }
higedura 0:9aa9be24636a 65 //for(int i=0;i<9;i++){ mavc.putc(test[i]); }
higedura 0:9aa9be24636a 66 // ******************** sequence No.2 ********************
higedura 0:9aa9be24636a 67
higedura 0:9aa9be24636a 68 // ******************** sequence No.3 ********************
higedura 0:9aa9be24636a 69 // buf | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 |
higedura 0:9aa9be24636a 70 // |header| AccX | AccY | AccZ | GyroX | GyroY | GyroZ | Azimuth | Altitude| GPSX | GPSY |
higedura 0:9aa9be24636a 71 // | H | D[1] | D[2] | D[3] | D[4] | D[5] | D[6] | D[7] | D[8] | D[9] | D[10] |
higedura 0:9aa9be24636a 72 // transrating hex to dec
higedura 0:9aa9be24636a 73 for(int i=0;i<10;i++){ buf_dec[i] = buf_hex[24-i*2]*256+buf_hex[23-i*2]; }
higedura 0:9aa9be24636a 74 // wakariyasuku surutame bunnkatsu, honnrai ha matrix ga yoi
higedura 0:9aa9be24636a 75 // -> saisyuteki niha matrix ni simasu?
higedura 0:9aa9be24636a 76 for(int i=0;i<3;i++){ acc[i] = ((double)buf_dec[i]-32768)/65535*20*9.8; }
higedura 0:9aa9be24636a 77 for(int i=0;i<3;i++){ gyro[i] = ((double)buf_dec[i+3]-32768)/65535*600/180*pi; }
higedura 0:9aa9be24636a 78 azi = (double)buf_dec[6]/65535*2*pi;
higedura 0:9aa9be24636a 79 alt = ((double)buf_dec[7]-32768)*0.1;
higedura 0:9aa9be24636a 80 for(int i=0;i<2;i++){ GPS[i] = ((double)buf_dec[i+8]-32768)*0.1; }
higedura 0:9aa9be24636a 81 // ******************** sequence No.3 ********************
higedura 0:9aa9be24636a 82
higedura 0:9aa9be24636a 83 // ******************** control law ********************
higedura 0:9aa9be24636a 84 // transrating dec to hex
higedura 0:9aa9be24636a 85 //com
higedura 0:9aa9be24636a 86 // ******************** control law ********************
higedura 0:9aa9be24636a 87
higedura 1:ca296cfa603b 88 //pc.printf("%7.4f %7.4f %7.4f %7.3f %7.3f %7.3f %8.5f %8.1f %8.1f %8.1f\r\n", acc[0], acc[1], acc[2], gyro[0], gyro[1], gyro[2], azi, alt, GPS[0], GPS[1]);
higedura 1:ca296cfa603b 89 //fprintf(fp, "%7.4f %7.4f %7.4f %7.3f %7.3f %7.3f %8.5f %8.1f %8.1f %8.1f\r\n", acc[0], acc[1], acc[2], gyro[0], gyro[1], gyro[2], azi, alt, GPS[0], GPS[1]);
higedura 0:9aa9be24636a 90
higedura 0:9aa9be24636a 91 }
higedura 0:9aa9be24636a 92
higedura 0:9aa9be24636a 93 }
higedura 0:9aa9be24636a 94
higedura 0:9aa9be24636a 95 fclose(fp);
higedura 0:9aa9be24636a 96 led1 = 1; led2 = 1; led3 = 1; led4 = 1;
higedura 0:9aa9be24636a 97
higedura 0:9aa9be24636a 98 }