-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbadgerloop.cpp
More file actions
149 lines (123 loc) · 3.16 KB
/
Copy pathbadgerloop.cpp
File metadata and controls
149 lines (123 loc) · 3.16 KB
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
// Includes
#include "HVTCPSocket.h"
#include "data_dump.h"
#include "hv_iox.h"
#include "motor.h"
#include "state_machine.h"
#include <TelemetryLoop.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "hv_iox.h"
#include "state_machine.h"
#include "motor.h"
// Temp
#include <chrono>
#include <ctime>
#include <iostream>
extern "C" {
#include "NCD9830DBR2G.h"
#include "bbgpio.h"
#include "can_devices.h"
#include "connStat.h"
#include "data.h"
#include "nav.h"
#include "proc_iox.h"
#include <rms.h>
#include <signal.h>
// Software Parameter Loading
#include "load_software_parameters.h"
#include "software_parameters.h"
}
HVIox hv_iox;
void emergQuitter(int sig, siginfo_t* inf, void* nul)
{
printf("shutdown\n");
hv_iox.setMCUHVEnabled(false);
rmsCmdNoTorque();
sleep(1);
rmsDischarge();
sleep(1);
rmsInvDis();
exit(0);
}
int init(char* directory)
{
// Success status, return true by default
int success_status = 0;
/* Init Data struct */
if (initData()) {
success_status = 1;
}
/* Load Software Parameters */
if (loadParameters(directory, ACTIVE_RUN_PROFILE)) {
success_status = 1;
}
/* Init all drivers */
SetupCANDevices();
if (initProcIox(true)) {
success_status = 1;
}
if (hv_iox.init(true)) {
success_status = 1;
}
SetupMotor();
/* initMotor(); */
/* initPressureSensors();*/
/* Allocate needed memory for state machine and create graph */
buildStateMachine();
/* Init telemetry */
SetupTelemetry((char*)DASHBOARD_IP, DASHBOARD_PORT);
SetupHVTCPServer();
initNav();
struct sigaction sig;
sig.sa_sigaction = emergQuitter;
sigaction(SIGINT, &sig, NULL);
/* Start 'black box' data saving */
/* SetupDataDump(); */
return success_status;
}
int main(int argc, char* argv[])
{
/* Create the big data structures to house pod data */
int i = 0;
char buffer[100];
if (init(argv[0]) == 1) {
fprintf(stderr, "Error in initialization! Exiting...\r\n");
exit(1);
}
while (1) {
runStateMachine();
/* printf("CONN STAT: TCP - %d | UDP - %d\n", */
/* checkTCPStat(),*/
/* checkUDPStat());*/
if (getFlagsShouldBrake()) {
printf("signalling\n");
signalLV((char*)"brake");
setFlagsShouldBrake(false);
printf("signallingDone\n");
}
if (getFlagsBrakeInit()) {
printf("Cancelling brake\n");
signalLV((char*)"primBrakeOff");
usleep(1000);
signalLV((char*)"secBrakeOff");
setFlagsBrakeInit(false);
}
if (getFlagsClrMotionData()) {
resetNav();
setFlagsClrMotionData(false);
}
if (i >= 50) {
sprintf(buffer, "state%d\n", getDataState() == 1);
signalLV((char*)buffer);
i = 0;
} else {
i += 1;
}
// fprintf(stderr, "%d,%d,%d\n", getRmsActualTorque(), getRmsMotorSpeed(), getuSTimestamp());
usleep(10000);
}
return 0;
}