Skip to content

Commit 2abe65e

Browse files
author
Ezra Boley
committed
Fixed BMS data, more changes to come
1 parent d657b85 commit 2abe65e

File tree

14 files changed

+84
-47
lines changed

14 files changed

+84
-47
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ endif
2525

2626
LV_USER := "debian"
2727
HV_USER := "ezra"
28-
LV_IP := "192.168.1.106"
28+
LV_IP := "192.168.1.126"
2929
HV_IP := "192.168.1.146"
3030

3131
ifdef BB

embedded/app/include/state_machine.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <stdlib.h>
1010

1111

12-
#define NUM_STATES 10
12+
#define NUM_STATES 11
1313
#define FAULT "fault"
1414

1515
#define NON_RUN_FAULT_NAME FAULT"NonRun"
@@ -19,6 +19,7 @@
1919
#define PROPULSION_NAME "propulsion"
2020
#define BRAKING_NAME "braking"
2121
#define STOPPED_NAME "stopped"
22+
#define SERV_PRECHARGE_NAME "servicePrecharge"
2223
#define CRAWL_NAME "servicePropulsion"
2324
#define POST_RUN_NAME "postRun"
2425
#define SAFE_TO_APPROACH_NAME "safeToApproach"

embedded/app/src/state_machine.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern stateTransition_t * pumpdownAction(void);
2525
extern stateTransition_t * propulsionAction(void);
2626
extern stateTransition_t * brakingAction(void);
2727
extern stateTransition_t * stoppedAction(void);
28+
extern stateTransition_t * servPrechargeAction(void);
2829
extern stateTransition_t * crawlAction(void);
2930
extern stateTransition_t * postRunAction(void);
3031
extern stateTransition_t * safeToApproachAction(void);
@@ -177,6 +178,14 @@ static int initBraking(state_t *braking) {
177178
return 0;
178179
}
179180

181+
static int initServPrecharge(state_t *servPrecharge) {
182+
initTransition(servPrecharge->transitions[0], findState(CRAWL_NAME), toCrawl);
183+
initTransition(servPrecharge->transitions[1], findState(RUN_FAULT_NAME), genTranAction);
184+
addTransition(SERV_PRECHARGE_NAME, servPrecharge->transitions[0]);
185+
addTransition(SERV_PRECHARGE_NAME,
186+
servPrecharge->fault = servPrecharge->transitions[1]);
187+
}
188+
180189
static int initCrawl(state_t *crawl) {
181190

182191
initTransition(crawl->transitions[1], findState(POST_RUN_NAME), toBraking);
@@ -296,21 +305,23 @@ void buildStateMachine(void) {
296305
initState(stateMachine.allStates[1], PUMPDOWN_NAME, pumpdownAction, 2);
297306
initState(stateMachine.allStates[2], PROPULSION_NAME, propulsionAction, 2);
298307
initState(stateMachine.allStates[3], BRAKING_NAME, brakingAction, 3);
299-
initState(stateMachine.allStates[4], CRAWL_NAME, crawlAction, 3);
300-
initState(stateMachine.allStates[5], STOPPED_NAME, stoppedAction, 3);
301-
initState(stateMachine.allStates[6], POST_RUN_NAME, postRunAction, 2);
302-
initState(stateMachine.allStates[7], SAFE_TO_APPROACH_NAME, safeToApproachAction, 1);
303-
initState(stateMachine.allStates[8], NON_RUN_FAULT_NAME, nonRunFaultAction, 0);
304-
initState(stateMachine.allStates[9], RUN_FAULT_NAME, runFaultAction, 0);
308+
initState(stateMachine.allStates[4], SERV_PRECHARGE_NAME, servPrechargeAction, 2);
309+
initState(stateMachine.allStates[5], CRAWL_NAME, crawlAction, 3);
310+
initState(stateMachine.allStates[6], STOPPED_NAME, stoppedAction, 3);
311+
initState(stateMachine.allStates[7], POST_RUN_NAME, postRunAction, 2);
312+
initState(stateMachine.allStates[8], SAFE_TO_APPROACH_NAME, safeToApproachAction, 1);
313+
initState(stateMachine.allStates[9], NON_RUN_FAULT_NAME, nonRunFaultAction, 0);
314+
initState(stateMachine.allStates[10], RUN_FAULT_NAME, runFaultAction, 0);
305315

306316
initIdle( stateMachine.allStates[0]);
307317
initPumpdown(stateMachine.allStates[1]);
308318
initPropulsion(stateMachine.allStates[2]);
309319
initBraking(stateMachine.allStates[3]);
310320
initStopped(stateMachine.allStates[4]);
311-
initCrawl(stateMachine.allStates[5]);
312-
initPostRun(stateMachine.allStates[6]);
313-
initSafeToApproach(stateMachine.allStates[7]);
321+
initServPrecharge(stateMachine.allStates[5]);
322+
initCrawl(stateMachine.allStates[6]);
323+
initPostRun(stateMachine.allStates[7]);
324+
initSafeToApproach(stateMachine.allStates[8]);
314325

315326
stateMachine.currState = stateMachine.allStates[0];
316327

embedded/app/src/states.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,12 @@ stateTransition_t * stoppedAction() {
261261
return NULL;
262262
}
263263

264-
stateTransition_t * crawlAction() {
264+
stateTransition_t * servPrechargeAction() {
265+
return NULL;
265266

266-
// Start crawl timer
267-
if(data->timers->crawlTimer == 0){
268-
data->timers->crawlTimer = getuSTimestamp();
269-
}
267+
}
268+
269+
stateTransition_t * crawlAction() {
270270
data->state = 8;
271271
/* Check IMD status */
272272
if (!getIMDStatus()) {

embedded/app/src/transitions.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ int toBraking() {
2727
int toCrawl() {
2828
brakePrimaryUnactuate();
2929
brakeSecondaryUnactuate(); /* Usually doesnt do anything */
30+
31+
data->timers->crawlTimer = getuSTimestamp();
32+
3033
if (startMotor() != 0) return 1;
3134
setTorque(CRAWL_TORQUE);
3235
return 0;

embedded/data/include/data.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ typedef struct bms_t {
147147
uint16_t relayStatus;
148148
uint8_t highTemp;
149149
uint8_t lowTemp;
150-
uint16_t cellMaxVoltage;
151-
uint16_t cellMinVoltage;
150+
float cellMaxVoltage;
151+
float cellMinVoltage;
152152
uint16_t cellAvgVoltage;
153153
uint8_t maxCells;
154154
uint8_t numCells;

embedded/examples/brakingTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <string.h>
55
#include "connStat.h"
66
extern "C" {
7+
#include "imu.h"
78
#include "braking.h"
89
#include "lv_iox.h"
910
#include "data.h"
@@ -27,6 +28,7 @@ int main(int argc, char *argv[]) {
2728
initData();
2829
initPressureMonitor();
2930
initLVIox(isHard);
31+
SetupIMU();
3032
SetupLVTelemetry((char *) DASHBOARD_IP, DASHBOARD_PORT);
3133
if (argc > 1) {
3234
if (strcmp(argv[1], "-p") == 0) {

embedded/examples/navTest.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern "C"
88
#include <nav.h>
99
}
1010
#include <LVTelemetry_Loop.h>
11-
11+
#include "connStat.h"
1212
#define ROLL "roll"
1313
#define EXP "exp"
1414
#define RAW "raw"
@@ -22,9 +22,8 @@ int main(int argc, char *argv[])
2222
initRetros();
2323
initNav();
2424

25-
SetupLVTelemetry((char *)"192.168.1.120", 33333);
25+
SetupLVTelemetry((char *)DASHBOARD_IP, 33333);
2626
joinRetroThreads();
2727

28-
2928
while(1);
3029
}

embedded/examples/stateTest.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ static int hvBattSOCLowTest()
9090
return ASSERT_STATE_IS(NON_RUN_FAULT_NAME);
9191
}
9292

93+
static int bmsTest() {
94+
//min voltage, max temp, SOC, Current, packV
95+
FREEZE_SM;
96+
genericInit("BMS passes health checks");
97+
UNFREEZE_SM;
98+
99+
100+
WAIT(0.5);
101+
return 0;
102+
}
103+
93104
/* Voltage Low, pack and cell */
94105
static int hvBattLowVoltTest()
95106
{

embedded/peripherals/src/bms.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "bms.h"
55
#include "can.h"
66
#include "data.h"
7-
7+
#define DEBUG_BMS
88
extern data_t *data;
99

1010
int bmsClearFaults(void){
@@ -30,7 +30,7 @@ int bmsClearFaults(void){
3030
* Receives a CAN Message and updates global BMS_Data struct
3131
*/
3232
int bmsParseMsg(uint32_t id, uint8_t *msg) {
33-
#ifdef DEBUG_BMS
33+
#if 0 /*DEBUG_BMS*/
3434
printf("Recieved bms message\n");
3535
printf("ID: 0x%3lx\r\n", (long unsigned int) id);
3636
printf("Data: %d, %d, %d, %d, %d, %d, %d\n", msg[0], msg[1], msg[2],
@@ -45,6 +45,7 @@ int bmsParseMsg(uint32_t id, uint8_t *msg) {
4545
bms->packVoltage /= 10;
4646
bms->Soc = msg[4]/2;
4747
bms->relayStatus = msg[6] | msg[5] << 8;
48+
bms->cellMaxVoltage = (msg[5] << 8) /10000.0;
4849
#ifdef DEBUG_BMS
4950
printf("V: %f\r\n", bms->packVoltage);
5051
printf("A: %f\r\n", bms->packCurrent);
@@ -55,7 +56,7 @@ int bmsParseMsg(uint32_t id, uint8_t *msg) {
5556
case 0x6B1:
5657
bms->packDCL = msg[1] | msg[0] << 8;
5758
bms->highTemp = msg[4];
58-
bms->lowTemp = msg[5];
59+
bms->cellMinVoltage = (msg[7] | (msg[6] << 8)) / 10000.0;
5960
#ifdef DEBUG_BMS
6061
printf("DCL: %d\r\n", bms->packDCL);
6162
printf("High T: %d\r\n", bms->highTemp);
@@ -77,22 +78,22 @@ int bmsParseMsg(uint32_t id, uint8_t *msg) {
7778

7879
bms->packCCL = msg[0] | (msg[1] << 8);
7980
bms->packDCL = msg[2] | (msg[3] << 8);
80-
bms->cellMaxVoltage = msg[4] | (msg[5] << 8);
81-
bms->cellMaxVoltage /= 10000;
82-
bms->cellMinVoltage = msg[6] | (msg[7] << 8);
83-
bms->cellMinVoltage /= 10000;
81+
/* bms->cellMaxVoltage = msg[4] | (msg[5] << 8);*/
82+
/* bms->cellMaxVoltage /= 10000;*/
83+
/* bms->cellMinVoltage = msg[6] | (msg[7] << 8);*/
84+
/* bms->cellMinVoltage /= 10000;*/
8485
#ifdef DEBUG_BMS
8586
printf("DCL %d\r\n", bms->packDCL);
8687
printf("Cell Min V: %d, Cell Max V: %d\r\n", bms->cellMinVoltage, bms->cellMaxVoltage);
8788
#endif
8889
break;
8990
case 0x651:
90-
bms->cellMaxVoltage = msg[2] | (msg[3] << 8);
91-
bms->cellMinVoltage = msg[0] | (msg[1] << 8);
92-
bms->cellAvgVoltage = msg[5] | (msg[4] << 8);
93-
bms->cellAvgVoltage /= 1000;
94-
bms->cellMaxVoltage /= 1000;
95-
bms->cellMinVoltage /= 1000;
91+
/* bms->cellMaxVoltage = msg[2] | (msg[3] << 8);*/
92+
/* bms->cellMinVoltage = msg[0] | (msg[1] << 8);*/
93+
/* bms->cellAvgVoltage = msg[5] | (msg[4] << 8);*/
94+
/* bms->cellAvgVoltage /= 1000;*/
95+
/* bms->cellMaxVoltage /= 1000;*/
96+
/* bms->cellMinVoltage /= 1000;*/
9697
bms->maxCells = msg[6];
9798
bms->numCells = msg[7];
9899
#ifdef DEBUG_BMS
@@ -122,8 +123,9 @@ int bmsParseMsg(uint32_t id, uint8_t *msg) {
122123

123124
bms->packCurrent = msg[0] | (msg[1] << 8);
124125
bms->packCurrent /= 10;
125-
bms->packVoltage = msg[2] | (msg[3] << 8);
126-
bms->packVoltage /= 10;
126+
bms->cellMinVoltage = ((msg[3] << 8) | msg[4]) / 10000.0;
127+
/* bms->packVoltage = msg[2] | (msg[3] << 8);*/
128+
/* bms->packVoltage /= 10;*/
127129
bms->packAh = msg[4] | (msg[5] << 8);
128130
bms->highTemp = msg[6];
129131
bms->lowTemp = msg[7];
@@ -160,8 +162,8 @@ void bmsDump () {
160162
printf("\tRelay Status = %u\n", bms->relayStatus);
161163
printf("\tHigh Temp = %u\n", bms->highTemp);
162164
printf("\tLow Temp = %u\n", bms->lowTemp);
163-
printf("\tCell Max Voltage = %u\n", bms->cellMaxVoltage);
164-
printf("\tCell Min Voltage = %u\n", bms->cellMinVoltage);
165+
printf("\tCell Max Voltage = %f\n", bms->cellMaxVoltage);
166+
printf("\tCell Min Voltage = %f\n", bms->cellMinVoltage);
165167
printf("\tMax Cells = %u\n", bms->maxCells);
166168
printf("\tNumber of Cells = %u\n", bms->numCells);
167169
printf("---END BMS---\n");

0 commit comments

Comments
 (0)