![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
201708能代のメインマイコンの保存データ送信用プログラム(データ送信部分を繰り返しタイマー割り込みにした)
Dependencies: MPU6050 MS5607 mbed
Fork of data_sousin by
main.cpp@4:918ea47cc35c, 2017-08-16 (annotated)
- Committer:
- oichan
- Date:
- Wed Aug 16 08:46:37 2017 +0000
- Revision:
- 4:918ea47cc35c
- Parent:
- 3:660279be8484
- Child:
- 5:a81dd9b6962a
fix bug
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
oichan | 3:660279be8484 | 1 | |
oichan | 4:918ea47cc35c | 2 | /********************************************************** |
oichan | 4:918ea47cc35c | 3 | データ取得&送信するプログラム |
oichan | 4:918ea47cc35c | 4 | 各データの終わりの印として'$'を送信 |
oichan | 4:918ea47cc35c | 5 | ************************************************************/ |
oichan | 3:660279be8484 | 6 | |
mbed_official | 0:bdbd3d6fc5d5 | 7 | #include "mbed.h" |
oichan | 3:660279be8484 | 8 | #include "MPU6050.h" |
mikawataru | 2:1dbaef45ae46 | 9 | |
oichan | 3:660279be8484 | 10 | #define ACC 16384 |
oichan | 4:918ea47cc35c | 11 | #define BUFFNUM 100 /*受信側のBUFFNUMと同値*/ |
oichan | 3:660279be8484 | 12 | #define CHARANUM 30 |
oichan | 4:918ea47cc35c | 13 | #define RATE 100.0 /*RATE[Hz]でデータ取得*/ |
mikawataru | 2:1dbaef45ae46 | 14 | |
oichan | 3:660279be8484 | 15 | MPU6050 mpu(p9,p10); |
oichan | 3:660279be8484 | 16 | Serial subCP(p28, p27); |
oichan | 3:660279be8484 | 17 | Ticker log_timer; |
oichan | 3:660279be8484 | 18 | Timer t; |
mikawataru | 2:1dbaef45ae46 | 19 | |
oichan | 3:660279be8484 | 20 | float Time[2][BUFFNUM] = {}; |
oichan | 3:660279be8484 | 21 | float Data[2][BUFFNUM] = {}; |
oichan | 3:660279be8484 | 22 | char Moji[2][BUFFNUM][CHARANUM] = {}; |
oichan | 3:660279be8484 | 23 | bool Row = false; |
oichan | 3:660279be8484 | 24 | int8_t Col = 0; |
oichan | 3:660279be8484 | 25 | int Send_cnt = 0; |
oichan | 3:660279be8484 | 26 | int Moji_cnt = 0; |
mikawataru | 2:1dbaef45ae46 | 27 | |
mikawataru | 2:1dbaef45ae46 | 28 | void _log(); |
mikawataru | 2:1dbaef45ae46 | 29 | |
oichan | 3:660279be8484 | 30 | int main(){ |
oichan | 3:660279be8484 | 31 | t.start(); |
oichan | 3:660279be8484 | 32 | log_timer.attach(_log,1.0/RATE); |
oichan | 4:918ea47cc35c | 33 | while(1){ |
oichan | 4:918ea47cc35c | 34 | if(Moji_cnt==0){ |
oichan | 4:918ea47cc35c | 35 | sprintf(&Moji[Row][Send_cnt][0],"%f, %f",Time[!Row][Send_cnt],Data[!Row][Send_cnt]); |
oichan | 4:918ea47cc35c | 36 | } |
oichan | 4:918ea47cc35c | 37 | subCP.putc(Moji[Row][Send_cnt][Moji_cnt]); |
oichan | 4:918ea47cc35c | 38 | Moji_cnt++; |
oichan | 4:918ea47cc35c | 39 | if(Moji_cnt==CHARANUM || Moji[Row][Send_cnt][Moji_cnt]=='\0'){ |
oichan | 4:918ea47cc35c | 40 | Moji_cnt = 0; |
oichan | 4:918ea47cc35c | 41 | subCP.putc('$'); |
oichan | 4:918ea47cc35c | 42 | Send_cnt++; |
oichan | 4:918ea47cc35c | 43 | if(Send_cnt==BUFFNUM){ |
oichan | 4:918ea47cc35c | 44 | Send_cnt = 0; |
oichan | 4:918ea47cc35c | 45 | } |
oichan | 4:918ea47cc35c | 46 | } |
oichan | 4:918ea47cc35c | 47 | } |
mikawataru | 2:1dbaef45ae46 | 48 | } |
mikawataru | 2:1dbaef45ae46 | 49 | |
oichan | 4:918ea47cc35c | 50 | /* データ取得関数 */ |
oichan | 3:660279be8484 | 51 | void _log(){ |
oichan | 3:660279be8484 | 52 | //TODO: 高度データの取得 |
oichan | 3:660279be8484 | 53 | //TODO: 取得する加速度を合成加速度に変更 |
oichan | 3:660279be8484 | 54 | Data[Row][Col] = (float)mpu.getAcceleroRawZ()/ACC; |
oichan | 3:660279be8484 | 55 | Time[Row][Col] = t.read(); |
oichan | 3:660279be8484 | 56 | Col++; |
oichan | 3:660279be8484 | 57 | if(Col == BUFFNUM){ |
oichan | 3:660279be8484 | 58 | Col = 0; |
oichan | 3:660279be8484 | 59 | Row = !Row; |
oichan | 3:660279be8484 | 60 | } |
oichan | 3:660279be8484 | 61 | } |
mikawataru | 2:1dbaef45ae46 | 62 |