TRR 2018 / Mbed 2 deprecated biniou-TRR2019-DLVV

Dependencies:   mbed MPU6050

Committer:
GaspardD
Date:
Fri Oct 04 09:58:51 2019 +0000
Revision:
11:2156cb77d0d6
Parent:
10:e63fe4080760
Child:
12:58ad06f9847d
version avec log et tout

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GaspardD 9:1b54bac6d9a7 1 #include "log.h"
GaspardD 9:1b54bac6d9a7 2
GaspardD 9:1b54bac6d9a7 3 Timer t_loggingTimer;
GaspardD 9:1b54bac6d9a7 4 int i_logging_duration;
GaspardD 9:1b54bac6d9a7 5 bool b_LOG_READY = false;
GaspardD 10:e63fe4080760 6 Serial rs_LOG_pc(USBTX, USBRX,9600);
GaspardD 10:e63fe4080760 7 //Serial rs_LOG_odroid(PC_10, PC_11,115200);
GaspardD 9:1b54bac6d9a7 8
GaspardD 9:1b54bac6d9a7 9
GaspardD 9:1b54bac6d9a7 10 s_Sample s_LOG_history[LOG_SIZE];
GaspardD 9:1b54bac6d9a7 11 int i_LOG_index_data = 0;
GaspardD 9:1b54bac6d9a7 12 bool b_LOG_flag = false;
GaspardD 9:1b54bac6d9a7 13
GaspardD 9:1b54bac6d9a7 14 void log_start(int duration_ms)
GaspardD 9:1b54bac6d9a7 15 {
GaspardD 9:1b54bac6d9a7 16 b_LOG_flag = true;
GaspardD 9:1b54bac6d9a7 17 b_LOG_READY = false;
GaspardD 9:1b54bac6d9a7 18 t_loggingTimer.start();
GaspardD 9:1b54bac6d9a7 19 i_logging_duration = duration_ms;
GaspardD 9:1b54bac6d9a7 20 t_loggingTimer.reset();
GaspardD 9:1b54bac6d9a7 21 }
GaspardD 9:1b54bac6d9a7 22
GaspardD 9:1b54bac6d9a7 23 void log_check()
GaspardD 9:1b54bac6d9a7 24 {
GaspardD 10:e63fe4080760 25 if(t_loggingTimer.read_ms() > i_logging_duration || i_LOG_index_data >= LOG_SIZE) {
GaspardD 9:1b54bac6d9a7 26 b_LOG_READY = true;
GaspardD 9:1b54bac6d9a7 27 b_LOG_flag = false;
GaspardD 9:1b54bac6d9a7 28 t_loggingTimer.stop();
GaspardD 9:1b54bac6d9a7 29 t_loggingTimer.reset();
GaspardD 9:1b54bac6d9a7 30 }
GaspardD 9:1b54bac6d9a7 31 if(b_LOG_flag && i_LOG_index_data < LOG_SIZE) {
GaspardD 10:e63fe4080760 32 i_LOG_index_data ++;
GaspardD 11:2156cb77d0d6 33 //rs_LOG_pc.printf("i_LOG_index_data:%d\r\n",i_LOG_index_data);
GaspardD 9:1b54bac6d9a7 34 }
GaspardD 11:2156cb77d0d6 35
GaspardD 9:1b54bac6d9a7 36 }
GaspardD 11:2156cb77d0d6 37 void log_stop()
GaspardD 11:2156cb77d0d6 38 {
GaspardD 11:2156cb77d0d6 39 b_LOG_READY = true;
GaspardD 11:2156cb77d0d6 40 b_LOG_flag = false;
GaspardD 11:2156cb77d0d6 41 t_loggingTimer.stop();
GaspardD 11:2156cb77d0d6 42 t_loggingTimer.reset();
GaspardD 11:2156cb77d0d6 43 }
GaspardD 11:2156cb77d0d6 44
GaspardD 9:1b54bac6d9a7 45 void log_pc()
GaspardD 9:1b54bac6d9a7 46 {
GaspardD 9:1b54bac6d9a7 47 rs_LOG_pc.printf("timestamp;left_90;right_90;left_45;right_45;pwm_dir;odom;speed;\r\n");
GaspardD 10:e63fe4080760 48 for(int i = 0; i<i_LOG_index_data; i++) {
GaspardD 10:e63fe4080760 49 rs_LOG_pc.printf("%d;%f;%f;%f;%f;%d;%f;%f;\r\n",s_LOG_history[i].timestamp,s_LOG_history[i].left_90,s_LOG_history[i].right_90,s_LOG_history[i].left_45,s_LOG_history[i].right_45,s_LOG_history[i].pwm_dir,s_LOG_history[i].odom,s_LOG_history[i].speed);
GaspardD 11:2156cb77d0d6 50
GaspardD 11:2156cb77d0d6 51 s_LOG_history[i].left_90 = 0.0;
GaspardD 11:2156cb77d0d6 52 s_LOG_history[i].right_90 = 0.0;
GaspardD 11:2156cb77d0d6 53 s_LOG_history[i].left_45 = 0.0;
GaspardD 11:2156cb77d0d6 54 s_LOG_history[i].right_45 = 0.0;
GaspardD 11:2156cb77d0d6 55 s_LOG_history[i].odom = 0.0;
GaspardD 11:2156cb77d0d6 56 s_LOG_history[i].speed = 0.0;
GaspardD 11:2156cb77d0d6 57 s_LOG_history[i].timestamp = 0;
GaspardD 11:2156cb77d0d6 58 s_LOG_history[i].pwm_dir = 0;
GaspardD 11:2156cb77d0d6 59
GaspardD 11:2156cb77d0d6 60
GaspardD 9:1b54bac6d9a7 61 }
GaspardD 10:e63fe4080760 62 i_LOG_index_data = 0;
GaspardD 10:e63fe4080760 63 b_LOG_READY = false;
GaspardD 9:1b54bac6d9a7 64 }