Skip to content

Commit e563d09

Browse files
author
Ezra Boley
authored
Merge branch 'embedded-statemachine-dev' into Dash-Buttons
2 parents 82c1d4d + acf9230 commit e563d09

26 files changed

+297
-106
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,4 @@ $RECYCLE.BIN/
259259
**/public/images
260260

261261
/.vscode
262+
.vscode/

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ ifdef LOCAL
2323
NOI2C := NOI2C
2424
endif
2525

26+
ifdef BB
27+
BEAGLE := ${BBCC}
28+
endif
29+
2630
# Compiler options
27-
GCC := gcc
28-
GPP := g++
31+
GCC := $(BEAGLE)gcc
32+
GPP := $(BEAGLE)g++
2933
IFLAGS := $(addprefix -I,$(INCLUDE_DIRS))
3034
WFLAGS := -Wall -Wno-deprecated -Wextra -Wno-type-limits -fdiagnostics-color
3135
CFLAGS := -std=gnu11 $(addprefix -D,$(USE_VCAN)) $(addprefix -D, $(DEBUG_MODE)) $(addprefix -D, $(NOI2C))

embedded/app/include/states.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
#define SEC_PS3_BOTTOM_LIMIT 0
4242
#define SEC_PS3_TOP_LIMIT 20
4343

44-
44+
#define PV_TOP_LIMIT 20
45+
#define PV_BOTTOM_LIMIT 10
4546

4647

4748
/* Battery Acceptable Limits */
@@ -140,6 +141,7 @@
140141
#define MIN_DISTANCE_TO_END 30 /*in m //FIXME Confirm how far from the end of the tube we need to stop */
141142

142143
#define MAX_RUN_TIME 30000000 /* in microseconds, TODO get the real number */
144+
#define MAX_CRAWL_TIME 30000000 /* in microseconds, TODO get the real number */
143145

144146

145147

embedded/app/main/badgerloop_HV.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "HVTCPSocket.h"
88
#include "HV_Telem_Recv.h"
99
#include "data_dump.h"
10+
#include "connStat.h"
1011

1112
extern "C"
1213
{
@@ -34,7 +35,7 @@ int init() {
3435
buildStateMachine();
3536

3637
/* Init telemetry */
37-
SetupHVTelemetry((char *) "192.168.1.126", 33333);
38+
SetupHVTelemetry((char *) DASHBOARD_IP, DASHBOARD_PORT);
3839
SetupHVTCPServer();
3940
SetupHVTelemRecv();
4041

embedded/app/main/badgerloop_LV.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <stdio.h>
33
#include <stdlib.h>
44
#include <unistd.h>
5-
5+
#include "connStat.h"
66
#include "LVTelemetry_Loop.h"
77
#include "LVTCPSocket.h"
88
/* ADD SENSOR INCLUDES HERE */
@@ -26,7 +26,7 @@ int init() {
2626
initProcIox(true);
2727

2828
/* Init telemetry services */
29-
SetupLVTelemetry((char *) "192.168.1.112", 33333);
29+
SetupLVTelemetry((char *) DASHBOARD_IP, DASHBOARD_PORT);
3030
SetupLVTCPServer();
3131

3232
return 0;

embedded/app/src/init.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,17 @@ int initFlagData() {
145145
data->flags->readyCommand = 0;
146146
data->flags->propulse = 0;
147147
data->flags->emergencyBrake = 0;
148-
return 0;
148+
data->flags->isConnected = false;
149+
data->flags->shouldBrake = false;
150+
data->flags->shutdown = false;
151+
return 0;
149152
}
150153

151154
int initTimerData() {
152155
int i = 0;
153156
data->timers->startTime = 0;
154157
data->timers->lastRetro = 0;
155158
for (i = 0; i < NUM_RETROS; i++) data->timers->lastRetros[i] = 0;
159+
data->timers->crawlTimer = 0;
156160
return 0;
157161
}

embedded/app/src/pressure_fault_checking.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ bool checkPrerunPressures(void) {
4343
fprintf(stderr, "Secondary primAct pressure failing\n");
4444
return false;
4545
}
46-
47-
46+
if (data->pressure->pv < PV_BOTTOM_LIMIT || data->pressure->pv > PV_TOP_LIMIT) {
47+
fprintf(stderr, "Pressure vessel depressurizing\n");
48+
return false;
49+
}
50+
4851
return true;
4952
}
5053

@@ -73,7 +76,11 @@ bool checkBrakingPressures(void) {
7376
fprintf(stderr, "Secondary primAct pressure failing\n");
7477
return false;
7578
}
76-
79+
if (data->pressure->pv < PV_BOTTOM_LIMIT || data->pressure->pv > PV_TOP_LIMIT) {
80+
fprintf(stderr, "Pressure vessel depressurizing\n");
81+
return false;
82+
}
83+
7784

7885
return true;
7986
}
@@ -103,7 +110,11 @@ bool checkCrawlPostrunPressures(void) {
103110
fprintf(stderr, "Secondary primAct pressure failing\n");
104111
return false;
105112
}
106-
113+
if (data->pressure->pv < PV_BOTTOM_LIMIT || data->pressure->pv > PV_TOP_LIMIT) {
114+
fprintf(stderr, "Pressure vessel depressurizing\n");
115+
return false;
116+
}
117+
107118

108119
return true;
109120
}

embedded/app/src/state_machine.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static int initPumpdown(state_t *pumpdown) {
171171
static int initReadyForLaunch(state_t *ready) {
172172

173173
initTransition(ready->transitions[0], findState(PROPULSION_NAME), toPropulsion);
174-
initTransition(ready->transitions[1], findState(RUN_FAULT_NAME), genTranAction);
174+
initTransition(ready->transitions[1], findState(PRE_RUN_FAULT_NAME), genTranAction);
175175
addTransition(READY_NAME, ready->transitions[0]);
176176
addTransition(READY_NAME, ready->transitions[1]);
177177
return 0;

embedded/app/src/states.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ stateTransition_t * readyForLaunchAction() {
185185

186186

187187
// CHECK PRESSURE
188-
if(!checkPrerunPressures()){
188+
if(!checkPrerunPressures())
189+
{
189190
return findTransition(stateMachine.currState, PRE_RUN_FAULT_NAME);
190191
}
191192

@@ -321,23 +322,23 @@ stateTransition_t * stoppedAction() {
321322
// CHECK FAULT CRITERIA
322323

323324
if(!checkBrakingPressures()){ // Still unchanged
324-
return findTransition(stateMachine.currState, POST_RUN_FAULT_NAME);
325+
return findTransition(stateMachine.currState, RUN_FAULT_NAME);
325326
}
326327

327328
// TODO check LV Power
328329
// TODO check LV Temp
329330

330331
if(!checkBrakingBattery()){ // Still unchanged
331-
return findTransition(stateMachine.currState, POST_RUN_FAULT_NAME);
332+
return findTransition(stateMachine.currState, RUN_FAULT_NAME);
332333
}
333334

334335
if(!checkStoppedRMS()){ // Still unchanged
335-
return findTransition(stateMachine.currState, POST_RUN_FAULT_NAME);
336+
return findTransition(stateMachine.currState, RUN_FAULT_NAME);
336337
}
337338

338339
// FIXME FIX ALL TIME CHECKS!
339340
if (getuSTimestamp() - data->timers->startTime > MAX_RUN_TIME){
340-
return findTransition(stateMachine.currState, POST_RUN_FAULT_NAME);
341+
return findTransition(stateMachine.currState, RUN_FAULT_NAME);
341342
}
342343

343344
// CHECK TRANSITION CRITERIA
@@ -351,38 +352,44 @@ stateTransition_t * stoppedAction() {
351352
}
352353

353354
stateTransition_t * crawlAction() {
355+
356+
// Start crawl timer
357+
if(data->timers->crawlTimer == 0){
358+
data->timers->crawlTimer = getuSTimestamp();
359+
}
354360
data->state = 8;
355361
/* Check IMD status */
356362
if (!getIMDStatus()) {
357-
return findTransition(stateMachine.currState, POST_RUN_FAULT_NAME);
363+
return findTransition(stateMachine.currState, RUN_FAULT_NAME);
358364
}
359365

360366
/* Check HV Indicator light */
361367
if (!isHVIndicatorEnabled()) {
362-
return findTransition(stateMachine.currState, POST_RUN_FAULT_NAME);
368+
return findTransition(stateMachine.currState, RUN_FAULT_NAME);
363369
}
364370

365371

366372
if(!checkCrawlPostrunPressures()){
367-
return findTransition(stateMachine.currState, POST_RUN_FAULT_NAME);
373+
return findTransition(stateMachine.currState, RUN_FAULT_NAME);
368374
}
369375

370376
// TODO check LV Power
371377
// TODO check LV Temp
372378

373379
if(!checkCrawlBattery()){
374-
return findTransition(stateMachine.currState, POST_RUN_FAULT_NAME);
380+
return findTransition(stateMachine.currState, RUN_FAULT_NAME);
375381
}
376382

377383
if(!checkCrawlRMS()){ // Still unchanged
378-
return findTransition(stateMachine.currState, POST_RUN_FAULT_NAME);
379-
}
380-
381-
if (getuSTimestamp() - data->timers->startTime > MAX_RUN_TIME){
382-
return findTransition(stateMachine.currState, POST_RUN_FAULT_NAME);
384+
return findTransition(stateMachine.currState, RUN_FAULT_NAME);
383385
}
384386

385387
// CHECK TRANSITION CRITERIA
388+
389+
if (getuSTimestamp() - data->timers->crawlTimer > MAX_CRAWL_TIME){
390+
return findTransition(stateMachine.currState, BRAKING_NAME);
391+
}
392+
386393
if(data->flags->shouldStop){
387394
return findTransition(stateMachine.currState, BRAKING_NAME);
388395
}

embedded/data/include/data.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef struct flags_t {
4242
int shouldStop;
4343
int shutdown;
4444
bool shouldBrake;
45+
bool isConnected;
4546
} flags_t;
4647

4748

@@ -75,6 +76,7 @@ typedef struct timers_t {
7576
uint64_t oldRetro;
7677
uint64_t lastRetro;
7778
uint64_t lastRetros[NUM_RETROS];
79+
uint64_t crawlTimer;
7880
} timers_t;
7981

8082

0 commit comments

Comments
 (0)