Skip to content

Commit 3779f3c

Browse files
author
Ezra Boley
committed
Pushing for rohan
1 parent 9a4fbfe commit 3779f3c

27 files changed

+432
-592
lines changed

embedded/app/include/motor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void setTorque(uint16_t val);
1616
uint16_t getTorque(void);
1717

1818
void setMotorIsOn(bool val);
19-
19+
void setMotorCrawl(void);
2020
bool getMotorIsOn(void);
2121

2222
int startMotor(void);

embedded/app/include/state_machine.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#define PROPULSION_NAME "propulsion"
2020
#define BRAKING_NAME "braking"
2121
#define STOPPED_NAME "stopped"
22-
#define SERV_PRECHARGE_NAME "servicePrecharge"
23-
#define CRAWL_NAME "servicePropulsion"
22+
#define SERV_PRECHARGE_NAME "crawlPrecharge"
23+
#define CRAWL_NAME "crawl"
2424
#define POST_RUN_NAME "postRun"
2525
#define SAFE_TO_APPROACH_NAME "safeToApproach"
2626

@@ -35,6 +35,7 @@ typedef struct stateTransition_t stateTransition_t;
3535
typedef struct stateMachine_t stateMachine_t;
3636

3737

38+
extern stateTransition_t *runFault, *nonRunFault;
3839
state_t *getCurrState(void);
3940

4041
state_t *setCurrState(state_t *state);
@@ -66,7 +67,8 @@ typedef struct state_t {
6667
char *name; // FIXME Thinking about switching this to a number
6768
stateTransition_t **transitions;
6869
stateTransition_t *fault;
69-
int (*intro)(void);
70+
stateTransition_t *next;
71+
int (*begin)(void);
7072
int numTransitions;
7173
int transitionCounter;
7274
} state_t;
@@ -75,6 +77,7 @@ typedef struct stateMachine_t {
7577
state_t *currState;
7678
char * overrideStateName;
7779
state_t **allStates;
80+
uint64_t start;
7881
} stateMachine_t;
7982

8083
#endif

embedded/app/include/states.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,39 @@
88

99
/* Pressure sensor acceptable limits (in PSI) */
1010
#define PS1_BOTTOM_LIMIT_IDLE -50
11-
#define PS1_BOTTOM_LIMIT_PRE 500
11+
#define PS1_BOTTOM_LIMIT_PRE 0
1212
#define PS1_BOTTOM_LIMIT_CRAWLPOST 300
1313
#define PS1_TOP_LIMIT_PRE 1300
14-
#define PS1_TOP_LIMIT_CRAWLPOST 50
14+
#define PS1_TOP_LIMIT_CRAWLPOST 1000
1515
#define PS1_TOP_LIMIT_IDLE 1300
1616

1717
#define PS2_BOTTOM_LIMIT_IDLE -15
18-
#define PS2_BOTTOM_LIMIT_PRE 125
18+
#define PS2_BOTTOM_LIMIT_PRE -5
1919
#define PS2_BOTTOM_LIMIT_CRAWLPOST -15
2020
#define PS2_TOP_LIMIT_IDLE 150
2121
#define PS2_TOP_LIMIT_PRE 300
22-
#define PS2_TOP_LIMIT_CRAWLPOST 20
22+
#define PS2_TOP_LIMIT_CRAWLPOST 100
2323

2424

2525
#define PS3_BOTTOM_LIMIT_IDLE -10
2626
#define PS3_BOTTOM_LIMIT_PRE -15
27-
#define PS3_BOTTOM_LIMIT_BRAKING 120
27+
#define PS3_BOTTOM_LIMIT_BRAKING -10
2828
#define PS3_BOTTOM_LIMIT_CRAWLPOST -15
2929
#define PS3_TOP_LIMIT_IDLE 15
30-
#define PS3_TOP_LIMIT_PRE 15
30+
#define PS3_TOP_LIMIT_PRE 150
3131
#define PS3_TOP_LIMIT_BRAKING 150
3232
#define PS3_TOP_LIMIT_CRAWLPOST 150
3333

3434
#define SEC_PS1_BOTTOM_LIMIT_IDLE -50
35-
#define SEC_PS1_BOTTOM_LIMIT_PRE 600
35+
#define SEC_PS1_BOTTOM_LIMIT_PRE 300
3636
#define SEC_PS1_BOTTOM_LIMIT_CRAWLPOST 300
3737
#define SEC_PS1_TOP_LIMIT_PRE 1400
3838
#define SEC_PS1_TOP_LIMIT_CRAWLPOST 1400
3939
#define SEC_PS1_TOP_LIMIT_IDLE 1400
4040

4141

4242
#define SEC_PS2_BOTTOM_LIMIT_IDLE -15
43-
#define SEC_PS2_BOTTOM_LIMIT_PRE 120
43+
#define SEC_PS2_BOTTOM_LIMIT_PRE 0
4444
#define SEC_PS2_BOTTOM_LIMIT_CRAWLPOST 0
4545
#define SEC_PS2_TOP_LIMIT_PRE 150
4646
#define SEC_PS2_TOP_LIMIT_CRAWLPOST 20
@@ -113,18 +113,18 @@
113113
#define DC_BUS_VOLTAGE_MAX 360
114114

115115
#define DC_BUS_CURRENT_MIN -5
116-
#define DC_BUS_CURRENT_MAX_IDLE 319
117-
#define DC_BUS_CURRENT_MAX_PUMPDOWN 2
116+
#define DC_BUS_CURRENT_MAX_IDLE 10
117+
#define DC_BUS_CURRENT_MAX_PUMPDOWN 319
118118
#define DC_BUS_CURRENT_MAX_PROP 319
119-
#define DC_BUS_CURRENT_MAX_BRAKING 0.01
120-
#define DC_BUS_CURRENT_MAX_POST 0.01
119+
#define DC_BUS_CURRENT_MAX_BRAKING 319
120+
#define DC_BUS_CURRENT_MAX_POST 319
121121
#define DC_BUS_CURRENT_MAX_CRAWL 200
122122

123-
#define LV_VOLTAGE_MIN 10
123+
#define LV_VOLTAGE_MIN 8
124124
#define LV_VOLTAGE_MAX 14
125125

126126
#define CMD_TORQUE_MIN 0
127-
#define CMD_TORQUE_MAX_PRE 0
127+
#define CMD_TORQUE_MAX_PRE 5
128128
#define CMD_TORQUE_MAX_RUN 90
129129
#define CMD_TORQUE_MAX_POST 0
130130
#define CMD_TORQUE_MAX_CRAWL 40

embedded/app/include/transitions.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
#ifndef __TRANSITIONS_H__
22
#define __TRANSITIONS_H__
33

4+
int genIdle(void);
5+
46
int genTranAction(void);
57

6-
int toPropulsion(void);
8+
int genPropulsion(void);
9+
10+
int genPumpdown(void);
11+
12+
int genBraking(void);
13+
14+
int genCrawl(void);
715

8-
int toPumpdown(void);
16+
int genRunFault(void);
917

10-
int toBraking(void);
18+
int genServPrecharge(void);
1119

12-
int toCrawl(void);
20+
int genPostRun(void);
1321

14-
int toRunFault(void);
22+
int genStopped(void);
1523

16-
int toServPrecharge(void);
1724
#endif

embedded/app/main/badgerloop_HV.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ int init() {
6666

6767
int main() {
6868
/* Create the big data structures to house pod data */
69-
70-
if (init() == 1) {
69+
int i = 0;
70+
char buffer[100];
71+
72+
if (init() == 1) {
7173
fprintf(stderr, "Error in initialization! Exiting...\r\n");
7274
exit(1);
7375
}
74-
/* signal(SIGINT, shutdown);*/
75-
printf("Here\n");
7676

7777
while(1) {
7878
runStateMachine();
@@ -81,8 +81,10 @@ int main() {
8181
/* checkTCPStat(),*/
8282
/* checkUDPStat());*/
8383
if (data->flags->shouldBrake) {
84+
printf("signalling\n");
8485
signalLV((char *)"brake");
8586
data->flags->shouldBrake = false;
87+
printf("signallingDone\n");
8688
}
8789
if (data->flags->brakeInit) {
8890
signalLV((char *)"primBrakeOff");
@@ -96,6 +98,13 @@ int main() {
9698
data->flags->clrMotionData = false;
9799
}
98100

101+
if (i >= 50) {
102+
sprintf(buffer, "state%d\n", data->state == 1);
103+
signalLV((char *) buffer);
104+
i = 0;
105+
} else {
106+
i += 1;
107+
}
99108
usleep(10000);
100109

101110
// Control loop

embedded/app/main/badgerloop_LV.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int init() {
2828
initLVIox(true);
2929

3030
/* Init all peripherals */
31-
SetupIMU();
31+
/* SetupIMU(); GOODBYE MY SWEET SUMMER CHILD */
3232
initRetros();
3333
initPressureMonitor();
3434
initNav();
@@ -37,7 +37,7 @@ int init() {
3737

3838
SetupLVTelemetry((char *) DASHBOARD_IP, DASHBOARD_PORT);
3939
SetupLVTCPServer();
40-
40+
data->state = 1;
4141
return 0;
4242
}
4343

@@ -50,7 +50,7 @@ int main() {
5050
int errs = 0;
5151
while(1) {
5252
usleep(100000);
53-
/* if (errs > 100) brake();*/
53+
if (errs > 50) brake();
5454

5555
if (data->flags->shouldBrake) {
5656
brake();
@@ -72,11 +72,14 @@ int main() {
7272
brakeSecondaryUnactuate();
7373
data->flags->brakeSecRetr = false;
7474
}
75-
if (!checkUDPStat() || !checkTCPStat())
75+
76+
77+
if (data->state != 1 && (!checkTCPStatHV() || !checkTCPStat())) {
78+
printf("ERRS: %d\n", errs);
7679
errs += 1;
77-
else
80+
} else {
7881
errs = 0;
79-
82+
}
8083

8184

8285
// Control loop

embedded/app/src/motor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ void SetupMotor() {
5656
static void motorHbLoop() {
5757
while(1) {
5858
if (motorEnabled)
59-
rmsInvEn();
59+
rmsSendHbMsg(2);
6060
else if (lowTorqueMode)
61-
rmsInvEnNoTorque();
61+
rmsSendHbMsg(2);
6262
else
6363
rmsIdleHb();
6464
usleep(10000);

embedded/app/src/nav.c

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,6 @@
1515
#define TOTAL_RUN_TIME 30 /* s */
1616
#define EXPECTED_DECEL 9.8 /* m/s/s */
1717

18-
/* Just for test */
19-
#define X_DIR 0
20-
#define Y_DIR 1
21-
#define Z_DIR 2
22-
23-
/* Change this to change which direction the IMU thinks is right */
24-
#define CURR_DIR X_DIR
25-
26-
struct dirFn_t {
27-
float (*getPos)(void);
28-
void (*setPos)(float val);
29-
};
30-
31-
static struct dirFn_t imuDirFn[] =
32-
{
33-
{getPosX, setPosX},
34-
{getPosY, setPosY},
35-
{getPosZ, setPosZ}
36-
};
37-
3818
#define WINDOW_SIZE 2
3919

4020
static pthread_t navThread;
@@ -149,14 +129,13 @@ void filterMotion(int filterType) {
149129
data->motion->pos = pos;
150130
data->motion->vel = vel;
151131
data->motion->accel = accel;
152-
imuDirFn[CURR_DIR].setPos(0);
153132
}
133+
154134
void resetNav();
155135
void resetNav() {
156136
data->motion->pos = 0;
157137
data->motion->vel = 0;
158138
data->motion->accel = 0;
159-
imuDirFn[CURR_DIR].setPos(0);
160139
data->motion->retroCount = 0;
161140

162141
/* reset rest */
@@ -176,17 +155,6 @@ void navLoop(void *unused) {
176155
filterMotion(FILTER_NONE);
177156
}
178157

179-
if ((imuDirFn[CURR_DIR].getPos() > ((float)STRIP_DISTANCE * 1.5))) {
180-
/* If it is that different, we likely missed a strip */
181-
data->motion->missedRetro += 1;
182-
fprintf(stderr, "MISSED A TAPESTRIP\n"); //FIXME All we do rn is notify, to be adjusted in test
183-
imuDirFn[CURR_DIR].setPos(0);
184-
}
185-
186-
/* if ((getuSTimestamp() - data->timers->startTime) > TOTAL_RUN_TIME) {*/
187-
/* data->flags->shouldStop = true;*/
188-
/* }*/
189-
190158
lastRetroCount = data->motion->retroCount;
191159
/* showNavData(); */
192160
/* csvFormatShow(); */

embedded/app/src/pressure_fault_checking.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "pressure_fault_checking.h"
1818

1919
bool checkIdlePressures(void) {
20-
if (data->pressure->primTank < PS1_BOTTOM_LIMIT_IDLE || data->pressure->primTank > PS1_TOP_LIMIT_IDLE) {
20+
if (data->pressure->primTank < PS1_BOTTOM_LIMIT_IDLE || data->pressure->primTank > PS1_TOP_LIMIT_IDLE) {
2121
fprintf(stderr, "primTank pressure failing\n");
2222
return false;
2323
}
@@ -50,7 +50,7 @@ bool checkIdlePressures(void) {
5050
}
5151

5252
bool checkPrerunPressures(void) {
53-
if (data->pressure->primTank < PS1_BOTTOM_LIMIT_PRE || data->pressure->primTank > PS1_TOP_LIMIT_PRE) {
53+
if (data->pressure->primTank < PS1_BOTTOM_LIMIT_PRE || data->pressure->primTank > PS1_TOP_LIMIT_PRE) {
5454
fprintf(stderr, "primTank pressure failing\n");
5555
return false;
5656
}
@@ -83,7 +83,7 @@ bool checkPrerunPressures(void) {
8383
}
8484

8585
bool checkBrakingPressures(void) {
86-
if (data->pressure->primTank < PS1_BOTTOM_LIMIT_PRE || data->pressure->primTank > PS1_TOP_LIMIT_PRE) {
86+
if (data->pressure->primTank < PS1_BOTTOM_LIMIT_PRE || data->pressure->primTank > PS1_TOP_LIMIT_PRE) {
8787
fprintf(stderr, "primTank pressure failing\n");
8888
return false;
8989
}
@@ -117,7 +117,7 @@ bool checkBrakingPressures(void) {
117117
}
118118

119119
bool checkCrawlPostrunPressures(void) {
120-
if (data->pressure->primTank < PS1_BOTTOM_LIMIT_CRAWLPOST || data->pressure->primTank > PS1_TOP_LIMIT_CRAWLPOST) {
120+
if (data->pressure->primTank < PS1_BOTTOM_LIMIT_CRAWLPOST || data->pressure->primTank > PS1_TOP_LIMIT_CRAWLPOST) {
121121
fprintf(stderr, "primTank pressure failing\n");
122122
return false;
123123
}

0 commit comments

Comments
 (0)