forked from matthew-t-watson/Picopter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.cpp
93 lines (85 loc) · 2.38 KB
/
Logger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* File: Logger.cpp
* Author: matt
*
* Created on 01 November 2012, 22:49
*/
#include "Logger.h"
#include "Timer.h"
#include "AHRS.h"
#include "PICInterface.h"
#include "Control.h"
LoggerClass LogMan;
LoggerClass::LoggerClass() {
logging = false;
sampleno = 0;
log.str().reserve(100e6); //Allocate 100mb
}
LoggerClass::LoggerClass(const LoggerClass& orig) {
}
LoggerClass::~LoggerClass() {
logFile.close();
}
void LoggerClass::open(const char* filename) {
logFile.open(filename, std::fstream::out);
logFile.rdbuf()->pubsetbuf(0, 0); //No buffer
logging = true;
}
void LoggerClass::doWeNeedToFlush() {
if(timeSinceLastFlush > 1000) {
logFile << log.str();
log.str(std::string()); //Clear log
sync(); //Force dirty page write
timeSinceLastFlush = 0;
} else {
timeSinceLastFlush++;
}
}
void LoggerClass::update() {
if(logging) {
sampleno++;
log << sampleno << ", "
<< Timer.dt * 1000 << ", "
<< AHRS.calibratedData.x << ", "
<< AHRS.calibratedData.y << ", "
<< AHRS.calibratedData.z << ", "
<< AHRS.calibratedData.p << ", "
<< AHRS.calibratedData.q << ", "
<< AHRS.calibratedData.r << ", "
<< AHRS.calibratedData.temp << ", "
<< AHRS.calibratedData.magx << ", "
<< AHRS.calibratedData.magy << ", "
<< AHRS.calibratedData.magz << ", "
<< AHRS.calibratedData.pressure << ", "
<< AHRS.calibratedData.altitude << ", "
<< AHRS.orientation.pitch << ", "
<< AHRS.orientation.roll << ", "
<< AHRS.orientation.yaw << ", "
<< PICInterface.rx.pitchDem << ", "
<< PICInterface.rx.pitchRateDem << ", "
<< PICInterface.rx.rollDem << ", "
<< PICInterface.rx.rollRateDem << ", "
<< PICInterface.rx.throttleDem << ", "
<< PICInterface.rx.yawRateDem << ", "
<< PICInterface.rx.sw1 << ", "
<< PICInterface.rx.sw2 << ", "
<< PICInterface.pwmwidths.frontleft << ", "
<< PICInterface.pwmwidths.frontright << ", "
<< PICInterface.pwmwidths.rearleft << ", "
<< PICInterface.pwmwidths.rearright << ", "
<< Control.ratePitchPID.output << ", "
<< Control.rateRollPID.output << ", "
<< Control.rateYawPID.output << ", "
<< Control.attitudePitchPID.output << ", "
<< Control.attitudeRollPID.output << ", "
<< AHRS.quaternion.w << ", "
<< AHRS.quaternion.x << ", "
<< AHRS.quaternion.y << ", "
<< AHRS.quaternion.z
//Add additional logs below
<< std::endl;
if(PICInterface.rx.sw1 == false) {
doWeNeedToFlush();
}
}
}