Skip to content

Commit a1f7e39

Browse files
authored
Merge pull request #105 from badgerloop-software/devel
Update master
2 parents 7d7eeb1 + 872b305 commit a1f7e39

File tree

7 files changed

+21
-56
lines changed

7 files changed

+21
-56
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ endif
3939
GCC := $(BEAGLE)gcc
4040
GPP := $(BEAGLE)g++
4141
IFLAGS := $(addprefix -I,$(INCLUDE_DIRS))
42-
WFLAGS := -Wall -Wno-deprecated -Wextra -Wno-type-limits -fdiagnostics-color
42+
WFLAGS := -Wall -Wno-deprecated -Wextra -Wno-type-limits -fdiagnostics-color -Wno-unused-parameter
4343
CFLAGS := -std=gnu11 $(addprefix -D,$(USE_VCAN)) $(addprefix -D, $(DEBUG_MODE)) $(addprefix -D, $(NOI2C)) $(addprefix -D, $(NF))
4444
CPFLAGS := -std=c++11
4545
LDFLAGS := -Llib

embedded/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Badgerloop's Embedded Firmware
2-
*Developers: Rohan Daruwala, Ezra Boley, Ethan Link*
2+
*Developers: Rohan Daruwala, Ezra Boley*
33

44
## Platform:
5-
BeagleBone Black
6-
7-
More thorough documentation on how to use the different peripherals and drivers are available in the respective folders.
5+
BeagleBone Black
6+
7+
More thorough documentation on how to use the different peripherals and drivers are available in the respective folders.

embedded/app/src/state_machine.c

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,6 @@ state_t *findState(char *stateName) {
5353
}
5454

5555

56-
/***
57-
* findFaultState - Looks through a states transitions and finds its
58-
* appropriate fault state
59-
*
60-
* ARGS state_t *state - The state whose transitions will be searched
61-
*
62-
* RETURNS state_t * - A pointer to the fault state
63-
*/
64-
65-
static state_t * findFaultState(state_t *state) {
66-
int i = 0;
67-
for (i = 0; i < state->numTransitions; i++) {
68-
if (strncmp(state->transitions[i]->target->name, FAULT, 5) == 0) {
69-
return state->transitions[i]->target;
70-
}
71-
}
72-
fprintf(stderr, "This state has no fault? Needs to be fixed\n");
73-
return NULL; /* This should never happen, every state can fault */
74-
}
75-
7656

7757
/***
7858
* initState - fills in the fields of the state_t struct.
@@ -263,31 +243,26 @@ void runStateMachine(void) {
263243
if (strcmp(stateMachine.overrideStateName, BLANK_NAME) != 0) {
264244
state_t *tempState = findState(stateMachine.overrideStateName);
265245
if (tempState != NULL) {
266-
printf("TEMP STATE NAME: %s\n", tempState->name);
267246
stateTransition_t *trans = findTransition(stateMachine.currState, stateMachine.overrideStateName);
268247
if (trans != NULL) {
269248
trans->action();
270249
} else {
271-
printf("begin func\n");
272250
tempState->begin();
273251
}
274252
stateMachine.currState = tempState;
275253
}
276254
strcpy(stateMachine.overrideStateName, BLANK_NAME);
277-
printf("leaving run\n");
278255
return;
279256
}
280257
/* execute the state and check if we should be transitioning */
281258
stateTransition_t *transition = stateMachine.currState->action();
282259
if (transition != NULL) {
283260
/* printf("transAction->%s\n", transition->target->name);*/
284261
if (transition->action() == 0) {
285-
printf("here we are\n");
286262
stateMachine.currState = transition->target;
287263
} else {
288-
stateMachine.currState = stateMachine.currState->fault;
264+
stateMachine.currState = stateMachine.currState->fault->target;
289265
}
290-
printf("BEGIN!\n");
291266
if (transition->target->begin != NULL) {
292267
transition->target->begin();
293268
}
@@ -333,10 +308,8 @@ void buildStateMachine(void) {
333308
initPostRun(stateMachine.allStates[7]);
334309
initSafeToApproach(stateMachine.allStates[8]);
335310

336-
nonRunFault = stateMachine.allStates[9];
337-
runFault = stateMachine.allStates[10];
338-
339311
stateMachine.currState = stateMachine.allStates[0];
312+
stateMachine.currState->begin();
340313

341314
stateMachine.overrideStateName = malloc(21); // Longest state name is "readyForPropulsion" -- 18 char
342315
strcpy(stateMachine.overrideStateName, BLANK_NAME);

embedded/app/src/states.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
#include "pressure_fault_checking.h"
2525
#include "rms.h"
2626
#include "connStat.h"
27+
#include "motor.h"
2728
/*#define NO_FAULT*/
29+
2830
#define NUM_FAIL 10
2931
#define LV_BATT_SOC_CALC(x) (pow(-1.1142 * (x), 6) + \
3032
pow(78.334 * (x), 5) - \
@@ -37,11 +39,10 @@
3739
/* Imports/Externs */
3840
extern int internalCount;
3941
extern stateMachine_t stateMachine;
40-
stateTransition_t *runFault, *nonRunFault;
4142
extern stateTransition_t *findTransition(state_t *currState, char *name);
4243
int bErrs, pErrs, rErrs;
4344
int checkNetwork() {
44-
static errs = 0;
45+
static int errs = 0;
4546
if(!checkUDPStat() || !checkTCPStat()) {
4647
if (checkUDPStat() == 0) fprintf(stderr, "UDP ");
4748
if (checkTCPStat() == 0) fprintf(stderr, "TCP ");
@@ -62,30 +63,23 @@ int checkNetwork() {
6263
*
6364
* RETURNS: true if stopped, false if moving
6465
*/
65-
66+
/* DEPRECATED
6667
static bool checkStopped(void) {
6768
return fabs(data->motion->vel) < MAX_STOPPED_VEL && (getuSTimestamp() - data->timers->lastRetro) > TIME_SINCE_LAST_RETRO;
6869
}
69-
70+
*/
7071
/***
7172
* Actions for all the states.
7273
* They perform transition and error condition
7374
* checking and perform the functionality of the state: e.g. brake if in
7475
* braking.
7576
*
7677
*/
77-
static bool first = true;
7878

7979
stateTransition_t * idleAction() {
8080
data->state = 1;
8181

82-
if (checkUDPStat() && first) {
83-
genIdle();
84-
first = false;
85-
}
86-
8782
if (data->flags->emergencyBrake) {
88-
printf("run fault: %p\n", runFault);
8983
return findTransition(stateMachine.currState, RUN_FAULT_NAME);
9084
}
9185

@@ -115,14 +109,12 @@ stateTransition_t * pumpdownAction() {
115109
fprintf(stderr, "prerun batt fault\n");
116110
bErrs += 1;
117111
} else bErrs = 0;
118-
119-
/* if ((data->rms->faultCode1 << 8) & )*/
120112

121113
if(!checkPrerunRMS()){
122114
fprintf(stderr, "prerun rms fault\n");
123115
rErrs += 1;
124116
} else rErrs = 0;
125-
117+
/* FIXME, need to fix robust failure cases */
126118
if (pErrs >= NUM_FAIL || bErrs >= NUM_FAIL || rErrs >= NUM_FAIL)
127119
return stateMachine.currState->fault;
128120

@@ -227,7 +219,7 @@ stateTransition_t * brakingAction() {
227219
}
228220

229221
if (pErrs >= NUM_FAIL || bErrs >= NUM_FAIL || rErrs >= NUM_FAIL) {
230-
printf("NUM FAILS: pErrs - %d | bErrs - %d | rErrs - %d\n");
222+
fprintf(stderr,"NUM FAILS: pErrs - %d | bErrs - %d | rErrs - %d\n", pErrs, bErrs, rErrs);
231223

232224
return stateMachine.currState->fault;
233225
}

embedded/peripherals/src/bms.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ int bmsParseMsg(uint32_t id, uint8_t *msg) {
149149
case 0x36:
150150
if (msg[0] >= 0 && msg[0] < 72)
151151
cells[msg[0]] = (msg[2] | (msg[1] << 8)) / 10000.0;
152-
152+
break;
153153

154154
default:
155155
return 0;

embedded/peripherals/src/retro.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static bool blockInts = true;
3535
static int onTapeStrip (int retroNum);
3636
static void * waitForStrip (void * retroNum);
3737
static int getPin(int retroNum);
38-
static void * blockSpuriousInts(int timeout);
38+
static void * blockSpuriousInts(void *unused);
3939

4040

4141
/***
@@ -54,7 +54,7 @@ int initRetros() {
5454
return -1;
5555
}
5656

57-
if (pthread_create(&spuriousThread, NULL, blockSpuriousInts, SPURIOUS_BLOCK_TIMEOUT) != 0)
57+
if (pthread_create(&spuriousThread, NULL, blockSpuriousInts, NULL) != 0)
5858
return -1;
5959

6060
return 0;
@@ -192,9 +192,9 @@ static int getPin(int retroNum) {
192192
return -1; /* Will never get here */
193193
}
194194

195-
static void *blockSpuriousInts(int timeout) {
196-
blockInts = true;
197-
usleep(timeout);
195+
static void *blockSpuriousInts(void *null) {
196+
blockInts = true;
197+
usleep(SPURIOUS_BLOCK_TIMEOUT);
198198
blockInts = false;
199199
return NULL;
200200
}

middleware/src/data_dump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void *DataLoop(void *arg){
7070
fprintf(fp, "%f,%f,%f,%i,", data->motion->pos, data->motion->vel, data->motion->accel, data->motion->retroCount);
7171

7272
// BMS
73-
fprintf(fp, "%f,%f,%hu,%hx,%hu,%hu,%f,%hu,%hu,%f,%hu,%hu,%hu,%hu,%hu,%hu,%f,%f,%hu,", data->bms->packCurrent, data->bms->packVoltage, data->bms->packDCL, data->bms->packCCL, data->bms->packResistance, data->bms->packHealth, data->bms->packOpenVoltage, data->bms->packCycles, data->bms->packAh, data->bms->inputVoltage, data->bms->Soc, data->bms->relayStatus, data->bms->highTemp, data->bms->lowTemp, data->bms->cellMaxVoltage, data->bms->cellMinVoltage, data->bms->cellAvgVoltage, data->bms->maxCells, data->bms->numCells);
73+
fprintf(fp, "%f,%f,%hu,%hx,%hu,%hu,%f,%hu,%hu,%f,%hu,%hu,%hu,%hu,%f,%f,%hu,%hu,%hu,", data->bms->packCurrent, data->bms->packVoltage, data->bms->packDCL, data->bms->packCCL, data->bms->packResistance, data->bms->packHealth, data->bms->packOpenVoltage, data->bms->packCycles, data->bms->packAh, data->bms->inputVoltage, data->bms->Soc, data->bms->relayStatus, data->bms->highTemp, data->bms->lowTemp, data->bms->cellMaxVoltage, data->bms->cellMinVoltage, data->bms->cellAvgVoltage, data->bms->maxCells, data->bms->numCells);
7474

7575
// RMS
7676
fprintf(fp, "%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%lu,%lu,%lu,%lu,%hu,%hu,%hu,%hu,%hu,%hu\n", data->rms->igbtTemp, data->rms->gateDriverBoardTemp, data->rms->controlBoardTemp, data->rms->motorTemp, data->rms->motorSpeed, data->rms->phaseACurrent, data->rms->phaseBCurrent, data->rms->phaseCCurrent, data->rms->dcBusVoltage, data->rms->lvVoltage, data->rms->canCode1, data->rms->canCode2, data->rms->faultCode1, data->rms->faultCode2, data->rms->commandedTorque, data->rms->actualTorque, data->rms->relayState, data->rms->electricalFreq, data->rms->dcBusCurrent, data->rms->outputVoltageLn);

0 commit comments

Comments
 (0)