Skip to content

Commit c6afc07

Browse files
author
Ezra Boley
committed
Made changes to the state machine, its been a late night, most data live
1 parent 2abe65e commit c6afc07

File tree

15 files changed

+182
-71
lines changed

15 files changed

+182
-71
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ endif
2626
LV_USER := "debian"
2727
HV_USER := "ezra"
2828
LV_IP := "192.168.1.126"
29-
HV_IP := "192.168.1.146"
29+
HV_IP := "192.168.1.147"
3030

3131
ifdef BB
3232
BEAGLE := ${BBCC}

embedded/app/main/badgerloop_HV.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int init() {
4040
SetupHVTelemRecv();
4141

4242
/* Start 'black box' data saving */
43-
SetupDataDump();
43+
/* SetupDataDump();*/
4444

4545
return 0;
4646
}
@@ -50,7 +50,6 @@ void shutdown() {
5050
data->flags->shutdown = true;
5151
return;
5252
}
53-
5453
int main() {
5554
/* Create the big data structures to house pod data */
5655

@@ -68,7 +67,6 @@ int main() {
6867
exit(0);
6968
}
7069
runStateMachine();
71-
7270
if (data->flags->shouldBrake)
7371
signalLV((char *)"brake");
7472
usleep(10000);

embedded/app/main/badgerloop_LV.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
extern "C"
1010
{
1111
#include "lv_iox.h"
12+
#include "nav.h"
1213
#include "braking.h"
1314
#include "proc_iox.h"
1415
#include "imu.h"
@@ -20,20 +21,23 @@ int init() {
2021
/* Init Data */
2122
initData();
2223

24+
initProcIox(true);
25+
initLVIox(true);
2326
/* Init all peripherals */
2427
SetupIMU();
25-
initLVIox(true);
26-
initProcIox(true);
27-
28-
/* Init telemetry services */
29-
SetupLVTelemetry((char *) DASHBOARD_IP, DASHBOARD_PORT);
28+
initRetros();
29+
initPressureMonitor();
30+
initNav();
31+
/* Init telemetry services */
32+
SetupLVTelemetry((char *) DASHBOARD_IP, LV_TELEM_PORT);
3033
SetupLVTCPServer();
3134

3235
return 0;
3336
}
3437

3538
int main() {
3639

40+
3741
if (init() == 1) {
3842
printf("Error in initialization! Exiting...\r\n");
3943
exit(1);

embedded/app/src/state_machine.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ void runStateMachine(void) {
277277
}
278278
/* execute the state and check if we should be transitioning */
279279
stateTransition_t *transition = stateMachine.currState->action();
280+
printf("curr: %s\n", stateMachine.currState->name);
280281
if (transition != NULL) {
281282
if (transition->action() == 0)
282283
stateMachine.currState = transition->target;

embedded/app/src/states.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,25 @@ stateTransition_t * idleAction() {
5353

5454

5555
// CHECK PRESSURE
56-
if(!checkPrerunPressures()){
57-
return stateMachine.currState->fault;
58-
}
56+
/* if(!checkPrerunPressures()){*/
57+
/* return stateMachine.currState->fault;*/
58+
/* }*/
5959

6060
// CHECK STOPPED (MOTION)
61-
if(!checkStopped()){
62-
return stateMachine.currState->fault;
63-
}
61+
/* if(!checkStopped()){*/
62+
/* return stateMachine.currState->fault;*/
63+
/* }*/
6464

6565
// TODO check LV Power
6666
// TODO check LV Temp
6767

68-
if(!checkPrerunBattery()){
69-
return stateMachine.currState->fault;
70-
}
68+
/* if(!checkPrerunBattery()){*/
69+
/* return stateMachine.currState->fault;*/
70+
/* }*/
7171

72-
if(!checkPrerunRMS()){
73-
return stateMachine.currState->fault;
74-
}
72+
/* if(!checkPrerunRMS()){*/
73+
/* return stateMachine.currState->fault;*/
74+
/* }*/
7575

7676
// TRANSITION CRITERIA
7777
if(data->flags->readyPump){

embedded/data/include/data.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ typedef struct bms_t {
147147
uint16_t relayStatus;
148148
uint8_t highTemp;
149149
uint8_t lowTemp;
150+
uint8_t avgTemp;
150151
float cellMaxVoltage;
151152
float cellMinVoltage;
152153
uint16_t cellAvgVoltage;

embedded/examples/brakingTest.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ extern "C" {
1414

1515
void showBrakingInfo() {
1616
int i = 0;
17-
showPressures();
18-
for (i = 0; i < NUM_LIM_SWITCHES; i++)
19-
printf("Limit switch %d: %d\n", i, limSwitchGet(i));
17+
pressure_t *p = data->pressure;
18+
//showPressures();
19+
fprintf(stderr,"%f,%f,%f,%f,%f,%f\n", p->primTank, p->primLine, p->primAct,
20+
p->secTank, p->secLine, p->secAct);
21+
printf("%f,%f,%f,%f,%f,%f\n", p->primTank, p->primLine, p->primAct,
22+
p->secTank, p->secLine, p->secAct);
2023
}
2124

2225

@@ -49,7 +52,8 @@ int main(int argc, char *argv[]) {
4952
}
5053
}
5154
}
52-
55+
fprintf(stderr, "primTank,primLine,primAct,secTank,secLine,secAct\n");
56+
printf("primTank,primLine,primAct,secTank,secLine,secAct\n");
5357
FOREVER {
5458
showBrakingInfo();
5559
usleep(100000);

embedded/peripherals/include/bms.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
int bmsClearFaults();
77
int bmsParseMsg(uint32_t id, uint8_t *msg);
88
void bmsDump();
9-
9+
void dumpCells();
1010
#endif

embedded/peripherals/src/batt.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
#include "NCD9830DBR2G.h"
33

44
#define SCALE(x) ((x) * 2.96636085627)
5-
// - 2.5 / 2.5 * 50)
65

7-
/*double getLVBattVoltage() {*/
8-
/* readPressureSensor(ADC_0)*/
9-
/*}*/
6+
double getLVBattVoltage() {
7+
return 0;
8+
}
9+
10+
double getLVCurrent() {
11+
return 0;
12+
}

embedded/peripherals/src/bms.c

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
#include "bms.h"
55
#include "can.h"
66
#include "data.h"
7-
#define DEBUG_BMS
7+
88
extern data_t *data;
9+
float cells[72] = {0};
910

1011
int bmsClearFaults(void){
1112

@@ -45,7 +46,7 @@ int bmsParseMsg(uint32_t id, uint8_t *msg) {
4546
bms->packVoltage /= 10;
4647
bms->Soc = msg[4]/2;
4748
bms->relayStatus = msg[6] | msg[5] << 8;
48-
bms->cellMaxVoltage = (msg[5] << 8) /10000.0;
49+
bms->cellMaxVoltage = ((msg[5] << 8)| msg[6]) /10000.0;
4950
#ifdef DEBUG_BMS
5051
printf("V: %f\r\n", bms->packVoltage);
5152
printf("A: %f\r\n", bms->packCurrent);
@@ -56,15 +57,15 @@ int bmsParseMsg(uint32_t id, uint8_t *msg) {
5657
case 0x6B1:
5758
bms->packDCL = msg[1] | msg[0] << 8;
5859
bms->highTemp = msg[4];
59-
bms->cellMinVoltage = (msg[7] | (msg[6] << 8)) / 10000.0;
60+
/* bms->cellMinVoltage = (msg[7] | (msg[6] << 8)) / 10000.0;*/
6061
#ifdef DEBUG_BMS
6162
printf("DCL: %d\r\n", bms->packDCL);
6263
printf("High T: %d\r\n", bms->highTemp);
6364
printf("Low T: %d\r\n", bms->lowTemp);
6465
#endif
6566
break;
6667
case 0x653:
67-
printf("ID: 0x%3lx\r\n", (long unsigned int) id);
68+
/* printf("ID: 0x%3lx\r\n", (long unsigned int) id);*/
6869
bms->relayStatus = msg[1] | msg[0] << 8;
6970
bms->relayStatus = msg[0];
7071
bms->inputVoltage = msg[2] | (msg[3] << 8);
@@ -121,9 +122,9 @@ int bmsParseMsg(uint32_t id, uint8_t *msg) {
121122
break;
122123
case 0x150:
123124

124-
bms->packCurrent = msg[0] | (msg[1] << 8);
125+
/* bms->avgTemp = msg[0];*/
125126
bms->packCurrent /= 10;
126-
bms->cellMinVoltage = ((msg[3] << 8) | msg[4]) / 10000.0;
127+
/* bms->cellMinVoltage = ((msg[3] << 8) | msg[4]) / 10000.0;*/
127128
/* bms->packVoltage = msg[2] | (msg[3] << 8);*/
128129
/* bms->packVoltage /= 10;*/
129130
bms->packAh = msg[4] | (msg[5] << 8);
@@ -136,12 +137,23 @@ int bmsParseMsg(uint32_t id, uint8_t *msg) {
136137
printf("High Temp %d\r\n", bms->highTemp);
137138
printf("Low Temp %d\r\n", bms->lowTemp);
138139
#endif
140+
break;
141+
case 0x6b2:
142+
data->bms->cellMinVoltage = ((msg[0] << 8) | msg[1]) / 10000.0;
143+
/* data->bms->cellMaxVoltage = ((msg[2] << 8) | msg[3]) / 10000;*/
144+
bms->avgTemp = msg[2];
139145
break;
140146
case 0x80:
141147
break;
142-
default:
148+
case 0x36:
149+
if (msg[0] >= 0 && msg[0] < 72)
150+
cells[msg[0]] = (msg[2] | (msg[1] << 8)) / 10000.0;
151+
152+
153+
default:
143154
return 0;
144-
}
155+
156+
}
145157
return 1;
146158
}
147159

@@ -162,9 +174,21 @@ void bmsDump () {
162174
printf("\tRelay Status = %u\n", bms->relayStatus);
163175
printf("\tHigh Temp = %u\n", bms->highTemp);
164176
printf("\tLow Temp = %u\n", bms->lowTemp);
177+
printf("\tAvg Temp = %d\n", bms->avgTemp);
165178
printf("\tCell Max Voltage = %f\n", bms->cellMaxVoltage);
166179
printf("\tCell Min Voltage = %f\n", bms->cellMinVoltage);
167180
printf("\tMax Cells = %u\n", bms->maxCells);
168181
printf("\tNumber of Cells = %u\n", bms->numCells);
169182
printf("---END BMS---\n");
170183
}
184+
float *getCellArray();
185+
float *getCellArray() {
186+
return cells;
187+
}
188+
189+
void dumpCells() {
190+
printf("BATTERY CELLS: \n");
191+
for (int i = 0; i < 72; i++) {
192+
printf("CELL: %d : %f V\n", i , cells[i]);
193+
}
194+
}

0 commit comments

Comments
 (0)