-
Notifications
You must be signed in to change notification settings - Fork 0
/
VescLogging.ino
163 lines (117 loc) · 3.27 KB
/
VescLogging.ino
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// VESC LOGGING FUNCTION
// ---- Use VescLogData() in the programme
void VescLogData(){
slowFindName();
SdFile::dateTimeCallback(dateTime);
if (!file.open(fileName, O_CREAT | O_WRITE | O_EXCL)) { // We attemp to open the file
error("file.open");
DEBUGSERIAL.println(" Slow file.open error");
}
else{
Aquisition("VESC LOGGING",fileName); // Diplsay the screen of aquisition data
VescsdHeaderPrint();
while (!rightButtonPressed){
VescUartGetValue(measuredVal);
SavingVescDataSd(measuredVal);
if (!file.sync() || file.getWriteError()) {
error("write error");
DEBUGSERIAL.println(" Slow write error error");
}
}
file.close();
ResetButton();
SlowSavingStats(fileName);
while (!rightButtonPressed){
delay(10);
}
ResetButton();
}
}
void VescsdHeaderPrint(){
// Print header in text file
file.print("Time");
file.print(";");
file.print("tempFetFiltered");
file.print(";");
file.print("tempMotorFiltered");
file.print(";");
file.print("avgMotorCurrent");
file.print(";");
file.print("avgInputCurrent");
file.print(";");
file.print("avgId");
file.print(";");
file.print("avgIq");
file.print(";");
file.print("dutyNow");
file.print(";");
file.print("rpm");
file.print(";");
file.print("inpVoltage");
file.print(";");
file.print("ampHours");
file.print(";");
file.print("ampHoursCharged");
file.print(";");
file.print("tachometer");
file.print(";");
file.print("tachometerAbs");
file.print(";");
file.print("Analog Input 1");
file.print(";");
file.print("Analog Input 2");
file.print(";");
file.println("faultCode");
}
void SavingVescDataSd(const struct bldcMeasure& data){
// float tempFetFiltered;
// float tempMotorFiltered;
// float avgMotorCurrent;
// float avgInputCurrent;
// float avgId;
// float avgIq;
// float dutyNow;
// long rpm;
// float inpVoltage;
// float ampHours;
// float ampHoursCharged;
// float wattHours;
// float watthoursCharged;
// long tachometer;
// long tachometerAbs;
// int faultCode;
// if the file is available, write to it:
file.print(millis());
file.print(";");
file.print(data.tempFetFiltered);
file.print(";");
file.print(data.tempMotorFiltered);
file.print(";");
file.print(data.avgMotorCurrent);
file.print(";");
file.print(data.avgInputCurrent);
file.print(";");
file.print(data.avgId);
file.print(";");
file.print(data.avgIq);
file.print(";");
file.print(data.dutyNow);
file.print(";");
file.print(data.rpm);
file.print(";");
file.print(data.inpVoltage);
file.print(";");
file.print(data.ampHours);
file.print(";");
file.print(data.ampHoursCharged);
file.print(";");
file.print(data.tachometer);
file.print(";");
file.print(data.tachometerAbs);
file.print(";");
file.print(analogRead(ANALOG_ONE_PIN));
file.print(";");
file.print(analogRead(ANALOG_TWO_PIN));
file.print(";");
file.println(data.faultCode);
}