TRR 2018 / Mbed 2 deprecated biniou-TRR2019-DLVV

Dependencies:   mbed MPU6050

Committer:
GaspardD
Date:
Thu Oct 03 23:28:56 2019 +0000
Revision:
9:1b54bac6d9a7
Child:
10:e63fe4080760
a tester ;

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 9:1b54bac6d9a7 6 Serial rs_LOG_pc(USBTX, USBRX);
GaspardD 9:1b54bac6d9a7 7
GaspardD 9:1b54bac6d9a7 8
GaspardD 9:1b54bac6d9a7 9 s_Sample s_LOG_history[LOG_SIZE];
GaspardD 9:1b54bac6d9a7 10 int i_LOG_index_data = 0;
GaspardD 9:1b54bac6d9a7 11 bool b_LOG_flag = false;
GaspardD 9:1b54bac6d9a7 12
GaspardD 9:1b54bac6d9a7 13 void log_start(int duration_ms)
GaspardD 9:1b54bac6d9a7 14 {
GaspardD 9:1b54bac6d9a7 15 b_LOG_flag = true;
GaspardD 9:1b54bac6d9a7 16 b_LOG_READY = false;
GaspardD 9:1b54bac6d9a7 17 t_loggingTimer.start();
GaspardD 9:1b54bac6d9a7 18 i_logging_duration = duration_ms;
GaspardD 9:1b54bac6d9a7 19 t_loggingTimer.reset();
GaspardD 9:1b54bac6d9a7 20 }
GaspardD 9:1b54bac6d9a7 21
GaspardD 9:1b54bac6d9a7 22 void log_check()
GaspardD 9:1b54bac6d9a7 23 {
GaspardD 9:1b54bac6d9a7 24 if(t_loggingTimer.read_ms() > i_logging_duration) {
GaspardD 9:1b54bac6d9a7 25 b_LOG_READY = true;
GaspardD 9:1b54bac6d9a7 26 b_LOG_flag = false;
GaspardD 9:1b54bac6d9a7 27 t_loggingTimer.stop();
GaspardD 9:1b54bac6d9a7 28 t_loggingTimer.reset();
GaspardD 9:1b54bac6d9a7 29 }
GaspardD 9:1b54bac6d9a7 30 if(b_LOG_flag && i_LOG_index_data < LOG_SIZE) {
GaspardD 9:1b54bac6d9a7 31 s_LOG_history[i_LOG_index_data].timestamp = t_loggingTimer.read_ms();
GaspardD 9:1b54bac6d9a7 32 i_LOG_index_data + 1;
GaspardD 9:1b54bac6d9a7 33 }
GaspardD 9:1b54bac6d9a7 34 }
GaspardD 9:1b54bac6d9a7 35 void log_pc()
GaspardD 9:1b54bac6d9a7 36 {
GaspardD 9:1b54bac6d9a7 37 rs_LOG_pc.printf("timestamp;left_90;right_90;left_45;right_45;pwm_dir;odom;speed;\r\n");
GaspardD 9:1b54bac6d9a7 38 for(int i = 0; i<LOG_SIZE; i++) {
GaspardD 9:1b54bac6d9a7 39 rs_LOG_pc.printf("%d;%f;%f;%f;%f;%d;%f;%f;\r\n",s_LOG_history[i_LOG_index_data].timestamp,s_LOG_history[i_LOG_index_data].left_90,s_LOG_history[i_LOG_index_data].right_90,s_LOG_history[i_LOG_index_data].left_45,s_LOG_history[i_LOG_index_data].right_45,s_LOG_history[i_LOG_index_data].pwm_dir,s_LOG_history[i_LOG_index_data].odom,s_LOG_history[i_LOG_index_data].speed);
GaspardD 9:1b54bac6d9a7 40 }
GaspardD 9:1b54bac6d9a7 41 }