Skip to content

Commit 3c071e6

Browse files
author
Ezra Boley
committed
Working on being ready to do nav
1 parent c6afc07 commit 3c071e6

27 files changed

+394
-198
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ endif
2525

2626
LV_USER := "debian"
2727
HV_USER := "ezra"
28-
LV_IP := "192.168.1.126"
29-
HV_IP := "192.168.1.147"
28+
LV_IP := "192.168.0.6"
29+
HV_IP := "192.168.0.7"
3030

3131
ifdef BB
3232
BEAGLE := ${BBCC}

embedded/app/include/states.h

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,49 @@
77

88

99
/* Pressure sensor acceptable limits (in PSI) */
10-
#define PS1_BOTTOM_LIMIT_PRE 1000
11-
#define PS1_BOTTOM_LIMIT_CRAWLPOST 0
12-
#define PS1_TOP_LIMIT_PRE 3000
13-
#define PS1_TOP_LIMIT_CRAWLPOST 20
14-
15-
#define PS2_BOTTOM_LIMIT_PRE 150
16-
#define PS2_BOTTOM_LIMIT_CRAWLPOST 0
17-
#define PS2_TOP_LIMIT_PRE 275
10+
#define PS1_BOTTOM_LIMIT_IDLE -50
11+
#define PS1_BOTTOM_LIMIT_PRE 500
12+
#define PS1_BOTTOM_LIMIT_CRAWLPOST -50
13+
#define PS1_TOP_LIMIT_PRE 1300
14+
#define PS1_TOP_LIMIT_CRAWLPOST 50
15+
#define PS1_TOP_LIMIT_IDLE 1300
16+
17+
#define PS2_BOTTOM_LIMIT_IDLE -15
18+
#define PS2_BOTTOM_LIMIT_PRE 120
19+
#define PS2_BOTTOM_LIMIT_CRAWLPOST -15
20+
#define PS2_TOP_LIMIT_IDLE 150
21+
#define PS2_TOP_LIMIT_PRE 300
1822
#define PS2_TOP_LIMIT_CRAWLPOST 20
1923

2024

21-
#define PS3_BOTTOM_LIMIT_PRE 0
25+
#define PS3_BOTTOM_LIMIT_IDLE -10
26+
#define PS3_BOTTOM_LIMIT_PRE -15
2227
#define PS3_BOTTOM_LIMIT_BRAKING 150
23-
#define PS3_BOTTOM_LIMIT_CRAWLPOST 0
24-
#define PS3_TOP_LIMIT_PRE 20
25-
#define PS3_TOP_LIMIT_BRAKING 275
26-
#define PS3_TOP_LIMIT_CRAWLPOST 20
27-
28+
#define PS3_BOTTOM_LIMIT_CRAWLPOST -15
29+
#define PS3_TOP_LIMIT_IDLE 15
30+
#define PS3_TOP_LIMIT_PRE 15
31+
#define PS3_TOP_LIMIT_BRAKING 300
32+
#define PS3_TOP_LIMIT_CRAWLPOST 15
2833

34+
#define SEC_PS1_BOTTOM_LIMIT_IDLE -50
2935
#define SEC_PS1_BOTTOM_LIMIT_PRE 1000
3036
#define SEC_PS1_BOTTOM_LIMIT_CRAWLPOST 0
3137
#define SEC_PS1_TOP_LIMIT_PRE 3000
3238
#define SEC_PS1_TOP_LIMIT_CRAWLPOST 20
39+
#define SEC_PS1_TOP_LIMIT_IDLE 50
3340

3441

42+
#define SEC_PS2_BOTTOM_LIMIT_IDLE -15
3543
#define SEC_PS2_BOTTOM_LIMIT_PRE 150
3644
#define SEC_PS2_BOTTOM_LIMIT_CRAWLPOST 0
3745
#define SEC_PS2_TOP_LIMIT_PRE 275
3846
#define SEC_PS2_TOP_LIMIT_CRAWLPOST 20
47+
#define SEC_PS2_TOP_LIMIT_IDLE 15
3948

40-
49+
#define SEC_PS3_BOTTOM_LIMIT_IDLE -15
4150
#define SEC_PS3_BOTTOM_LIMIT 0
4251
#define SEC_PS3_TOP_LIMIT 20
52+
#define SEC_PS3_TOP_LIMIT_IDLE 15
4353

4454
#define PV_TOP_LIMIT 20
4555
#define PV_BOTTOM_LIMIT 10

embedded/app/include/transitions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ int toBraking(void);
99

1010
int toCrawl(void);
1111

12+
int toRunFault(void);
1213
#endif

embedded/app/main/badgerloop_HV.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "data_dump.h"
1010
#include "connStat.h"
1111

12+
1213
extern "C"
1314
{
1415
#include <signal.h>
@@ -19,6 +20,7 @@ extern "C"
1920
#include "data.h"
2021
#include "can_devices.h"
2122
#include "state_machine.h"
23+
#include "NCD9830DBR2G.h"
2224
}
2325

2426
int init() {
@@ -30,7 +32,7 @@ int init() {
3032
initProcIox(true);
3133
initHVIox(true);
3234
initMotor();
33-
35+
initPressureSensors();
3436
/* Allocate needed memory for state machine and create graph */
3537
buildStateMachine();
3638

@@ -67,8 +69,17 @@ int main() {
6769
exit(0);
6870
}
6971
runStateMachine();
70-
if (data->flags->shouldBrake)
72+
if (data->flags->shouldBrake) {
7173
signalLV((char *)"brake");
74+
data->flags->shouldBrake = false;
75+
}
76+
if (data->flags->brakeInit) {
77+
signalLV((char *)"primBrakeOff");
78+
signalLV((char *)"secBrakeOff");
79+
data->flags->brakeInit = false;
80+
}
81+
82+
7283
usleep(10000);
7384

7485
// Control loop

embedded/app/main/badgerloop_LV.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
#include "connStat.h"
66
#include "LVTelemetry_Loop.h"
77
#include "LVTCPSocket.h"
8+
9+
810
/* ADD SENSOR INCLUDES HERE */
911
extern "C"
1012
{
1113
#include "lv_iox.h"
1214
#include "nav.h"
1315
#include "braking.h"
16+
1417
#include "proc_iox.h"
1518
#include "imu.h"
1619
#include <data.h>
@@ -29,23 +32,44 @@ int init() {
2932
initPressureMonitor();
3033
initNav();
3134
/* Init telemetry services */
32-
SetupLVTelemetry((char *) DASHBOARD_IP, LV_TELEM_PORT);
35+
SetupLVTelemetry((char *) DASHBOARD_IP, DASHBOARD_PORT);
3336
SetupLVTCPServer();
3437

3538
return 0;
3639
}
3740

3841
int main() {
3942

40-
4143
if (init() == 1) {
4244
printf("Error in initialization! Exiting...\r\n");
4345
exit(1);
4446
}
45-
while(1) {
47+
flags_t *f = data->flags;
48+
if (f == NULL) printf("its null\n");
49+
while(1) {
4650
usleep(100000);
47-
51+
if (f->shouldBrake) {
52+
brake();
53+
f->shouldBrake = false;
54+
}
55+
if (f->brakePrimAct) {
56+
brakePrimaryActuate();
57+
f->brakePrimAct = false;
58+
}
59+
if (f->brakePrimRetr) {
60+
brakePrimaryUnactuate();
61+
f->brakePrimRetr = false;
62+
}
63+
if (f->brakeSecAct) {
64+
brakeSecondaryActuate();
65+
f->brakeSecAct = false;
66+
}
67+
if (f->brakeSecRetr) {
68+
brakeSecondaryUnactuate();
69+
f->brakeSecRetr = false;
70+
}
4871
// Control loop
4972
}
5073
return 0;
74+
5175
}

embedded/app/src/motor.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,19 @@ bool getMotorIsOn() {
9393
int startMotor() {
9494
static bool isMCULatched = false;
9595
if (!isMCULatched) {
96-
setMCULatch(true);
96+
/* setMCULatch(true);*/
9797
/* usleep(1000000); //FIXME Not sure what to make this, .5 s for now*/
9898
/* setMCULatch(false);*/
9999
/* isMCULatched = true;*/
100100
}
101-
if (rmsEnHeartbeat() != 0) return 1;
102-
if (rmsClrFaults() != 0) return 1;
103-
if (rmsInvDis() != 0) return 1;
101+
rmsEnHeartbeat();
102+
rmsClrFaults();
103+
rmsInvDis();
104104
/* idleMotor();*/
105105
sleep(3); /* Not ideal, but unless we have a way to check status this stays */
106-
rmsInvEnNoTorque();
107106
setMotorIsOn(true);
107+
usleep(100000);
108+
rmsInvEnNoTorque();
108109
return 0;
109110
}
110111

@@ -122,8 +123,6 @@ int stopMotor() {
122123
if (rmsDischarge() != 0) return 1;
123124
if (rmsInvDis() != 0) return 1;
124125

125-
usleep(500000);
126-
data->flags->shouldBrake = true;
127126
return 0;
128127
}
129128

embedded/app/src/nav.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
#define FEET_TO_METERS(x) ((x) * 0.3048)
1111
#define USEC_TO_SEC(x) ((x) / 1000000)
12-
#define STRIP_DISTANCE FEET_TO_METERS(100) /*m*/
13-
#define TOTAL_DISTANCE FEET_TO_METERS(1000) /*m, not real TODO change*/
12+
#define STRIP_DISTANCE FEET_TO_METERS(10) /*m*/
13+
#define TOTAL_DISTANCE FEET_TO_METERS(100) /*m, not real TODO change*/
1414
#define TOTAL_RUN_TIME 30 /* s */
1515
#define EXPECTED_DECEL 9.8 /* m/s/s */
1616

@@ -148,26 +148,38 @@ void filterMotion(int filterType) {
148148
data->motion->pos = pos;
149149
data->motion->vel = vel;
150150
data->motion->accel = accel;
151-
/* imuDirFn[CURR_DIR].setPos(data->motion->pos);*/
151+
imuDirFn[CURR_DIR].setPos(0);
152152
}
153153

154+
void resetNav() {
155+
data->motion->pos = 0;
156+
data->motion->vel = 0;
157+
data->motion->accel = 0;
158+
imuDirFn[CURR_DIR].setPos(0);
159+
data->motion->retroCount = 0;
160+
161+
/* reset rest */
162+
}
154163

155164
/* TODO Open Qs
156165
* 1. Find out how bad drift is
157166
* 2. Are we going in X or Y plane
158167
*/
159168
void navLoop(void *unused) {
160169
int lastRetroCount = 0;
170+
data->motion->missedRetro = 0;
161171
csvFormatHeader();
162172
while (1) {
163173
if (lastRetroCount != data->motion->retroCount) {
164174
updateRawMotionData();
165175
filterMotion(FILTER_NONE);
166176
}
167177

168-
if ((imuDirFn[CURR_DIR].getPos() - data->motion->pos) > STRIP_DISTANCE * 2) {
178+
if ((imuDirFn[CURR_DIR].getPos() > ((float)STRIP_DISTANCE * 1.5))) {
169179
/* If it is that different, we likely missed a strip */
180+
data->motion->missedRetro += 1;
170181
fprintf(stderr, "MISSED A TAPESTRIP\n"); //FIXME All we do rn is notify, to be adjusted in test
182+
imuDirFn[CURR_DIR].setPos(0);
171183
}
172184

173185
if ((getuSTimestamp() - data->timers->startTime) > TOTAL_RUN_TIME) {

embedded/app/src/pressure_fault_checking.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,38 @@
1616

1717
#include "pressure_fault_checking.h"
1818

19-
extern data_t *data;
19+
bool checkIdlePressures(void) {
20+
if (data->pressure->primTank < PS1_BOTTOM_LIMIT_IDLE || data->pressure->primTank > PS1_TOP_LIMIT_IDLE) {
21+
fprintf(stderr, "primTank pressure failing\n");
22+
return false;
23+
}
24+
if (data->pressure->primLine < PS2_BOTTOM_LIMIT_IDLE || data->pressure->primLine > PS2_TOP_LIMIT_IDLE) {
25+
fprintf(stderr, "primLine pressure failing\n");
26+
return false;
27+
}
28+
if (data->pressure->primAct < PS3_BOTTOM_LIMIT_IDLE || data->pressure->primAct > PS3_TOP_LIMIT_IDLE) {
29+
fprintf(stderr, "primAct pressure failing\n");
30+
return false;
31+
}
32+
if (data->pressure->secTank < SEC_PS1_BOTTOM_LIMIT_IDLE || data->pressure->secTank > SEC_PS1_TOP_LIMIT_IDLE) {
33+
fprintf(stderr, "Secondary primTank pressure failing\n");
34+
return false;
35+
}
36+
if (data->pressure->secLine < SEC_PS2_BOTTOM_LIMIT_IDLE || data->pressure->secLine > SEC_PS2_TOP_LIMIT_IDLE) {
37+
fprintf(stderr, "Secondary primLine pressure failing\n");
38+
return false;
39+
}
40+
if (data->pressure->secAct < SEC_PS3_BOTTOM_LIMIT_IDLE || data->pressure->secAct > SEC_PS3_TOP_LIMIT_IDLE) {
41+
fprintf(stderr, "Secondary primAct pressure failing\n");
42+
return false;
43+
}
44+
if (data->pressure->pv < PV_BOTTOM_LIMIT || data->pressure->pv > PV_TOP_LIMIT) {
45+
fprintf(stderr, "Pressure vessel depressurizing\n");
46+
return false;
47+
}
48+
49+
return true;
50+
}
2051

2152
bool checkPrerunPressures(void) {
2253
if (data->pressure->primTank < PS1_BOTTOM_LIMIT_PRE || data->pressure->primTank > PS1_TOP_LIMIT_PRE) {

embedded/app/src/state_machine.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ static int initIdle(state_t *idle) {
134134

135135
initTransition(idle->transitions[0], findState(PUMPDOWN_NAME), genTranAction);
136136
initTransition(idle->transitions[1], findState(NON_RUN_FAULT_NAME), genTranAction);
137+
initTransition(idle->transitions[2], findState(RUN_FAULT_NAME), toRunFault);
137138
addTransition(IDLE_NAME, idle->transitions[0]);
138139
addTransition(IDLE_NAME, idle->transitions[1]);
139-
140+
addTransition(IDLE_NAME, idle->transitions[2]);
140141
idle->fault = idle->transitions[1];
141142

142143
return 0;
@@ -167,13 +168,11 @@ static int initPropulsion(state_t *propulsion) {
167168

168169
static int initBraking(state_t *braking) {
169170

170-
initTransition(braking->transitions[0], findState(CRAWL_NAME), toCrawl);
171-
initTransition(braking->transitions[1], findState(STOPPED_NAME), genTranAction);
172-
initTransition(braking->transitions[2], findState(RUN_FAULT_NAME), genTranAction);
171+
initTransition(braking->transitions[0], findState(STOPPED_NAME), genTranAction);
172+
initTransition(braking->transitions[1], findState(RUN_FAULT_NAME), genTranAction);
173173
addTransition(BRAKING_NAME, braking->transitions[0]);
174-
addTransition(BRAKING_NAME, braking->transitions[1]);
175174
addTransition(BRAKING_NAME,
176-
braking->fault = braking->transitions[2]);
175+
braking->fault = braking->transitions[1]);
177176

178177
return 0;
179178
}
@@ -201,7 +200,7 @@ static int initStopped(state_t *stopped) {
201200

202201

203202
initTransition(stopped->transitions[0], findState(POST_RUN_NAME), genTranAction);
204-
initTransition(stopped->transitions[1], findState(CRAWL_NAME), toCrawl);
203+
/* initTransition(stopped->transitions[1], findState(SERV_PRECHARGE_NAME), toServPrecharge);*/
205204
initTransition(stopped->transitions[2], findState(RUN_FAULT_NAME), genTranAction);
206205
addTransition(STOPPED_NAME, stopped->transitions[0]);
207206
addTransition(STOPPED_NAME, stopped->transitions[1]);
@@ -227,6 +226,7 @@ static int initSafeToApproach(state_t *safeToApproach) {
227226
return 0;
228227
}
229228

229+
230230
/***
231231
* findTransition - Looks through a passed in states list of transitions
232232
* and identifies the one that leads to a specified target
@@ -245,11 +245,14 @@ stateTransition_t *findTransition(state_t *srcState, char *targName) {
245245
}
246246
return NULL;
247247
}
248-
249-
state_t *getCurrState(void) {
248+
state_t *getCurrState(void);
249+
state_t *getCurrState() {
250250
return stateMachine.currState;
251251
}
252-
252+
void setCurrState(state_t *state);
253+
void setCurrState(state_t *state) {
254+
stateMachine.currState = state;
255+
}
253256
/***
254257
* runStateMachine -
255258
* Executes the current states action. A mini control loop
@@ -277,7 +280,6 @@ void runStateMachine(void) {
277280
}
278281
/* execute the state and check if we should be transitioning */
279282
stateTransition_t *transition = stateMachine.currState->action();
280-
printf("curr: %s\n", stateMachine.currState->name);
281283
if (transition != NULL) {
282284
if (transition->action() == 0)
283285
stateMachine.currState = transition->target;
@@ -302,7 +304,7 @@ void buildStateMachine(void) {
302304
stateMachine.allStates[i] = malloc(sizeof(state_t));
303305
}
304306

305-
initState(stateMachine.allStates[0], IDLE_NAME, idleAction, 2);
307+
initState(stateMachine.allStates[0], IDLE_NAME, idleAction, 4);
306308
initState(stateMachine.allStates[1], PUMPDOWN_NAME, pumpdownAction, 2);
307309
initState(stateMachine.allStates[2], PROPULSION_NAME, propulsionAction, 2);
308310
initState(stateMachine.allStates[3], BRAKING_NAME, brakingAction, 3);

0 commit comments

Comments
 (0)