Skip to content

Commit 94de02b

Browse files
committed
Can changes
1 parent 0839241 commit 94de02b

File tree

6 files changed

+151
-29
lines changed

6 files changed

+151
-29
lines changed

bms/.mbed

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
ROOT=.
22
TARGET=NUCLEO_L432KC
33
TARGET_CODE=0770
4-
TARGET_SERIAL=0671FF555185754867150637

bms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ target_sources(${APP_TARGET}
2929
src/BmsThread.cpp
3030
src/EnergusTempSensor.cpp
3131
src/LTC6811.cpp
32+
src/Can.cpp
3233
)
3334

3435
target_link_libraries(${APP_TARGET}
3536
PRIVATE
3637
mbed-os
38+
mbed-events
3739
lib-mbed-ltc681x
3840
)
3941

bms/src/Can.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "Can.h"
22
#include <cstdint>
33

4-
CANMessage accBoardBootup () {
5-
const char * startupMessage = 0x00;
4+
CANMessage accBoardBootup() {
5+
uint8_t startupMessage[8];
66
return CANMessage(kNMT_ACC_HEARTBEAT, startupMessage);
77
}
88

bms/src/Can.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ constexpr uint32_t kNMT_ACC_HEARTBEAT = 0x702;
1616
constexpr uint32_t kRPDO_MAX_CURRENTS = 0x286;
1717

1818
/* Bootup message */
19-
CANMessage accBoardBootup ();
19+
CANMessage accBoardBootup();
2020

2121
/* TPDO that sends various states and information about the accumulator */
2222
CANMessage accBoardState(uint8_t glvVoltage, uint16_t tsVoltage, bool bmsFault, bool bmsBalancing, bool prechargeDone, bool charging, bool fansOn, bool shutdownClosed, bool unused_A, bool unused_B, uint8_t minCellVoltage, uint8_t maxCellVoltage, int16_t tsCurrent);

bms/src/Main.cpp

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <array>
22
#include <cstdint>
33
#include <cstdio>
4+
#include <string>
45
#include <memory>
56
#include <vector>
67
#include <iostream>
@@ -17,7 +18,26 @@ CAN* canBus;
1718

1819
void initIO();
1920
void canRX();
20-
void canTX();
21+
22+
void canBootupTX();
23+
void canBoardStateTX();
24+
void canTempTX(uint8_t seg);
25+
void canTempTX0();
26+
void canTempTX1();
27+
void canTempTX2();
28+
void canTempTX3();
29+
void canVoltTX(uint8_t seg);
30+
void canVoltTX0();
31+
void canVoltTX1();
32+
void canVoltTX2();
33+
void canVoltTX3();
34+
void canCurrentLimTX();
35+
36+
37+
38+
EventQueue queue(4*EVENTS_EVENT_SIZE); // creates an eventqueue which is thread and ISR safe. EVENTS_EVENT_SIZE is the size of the buffer allocated
39+
40+
2141

2242
CircularBuffer<CANMessage, 32> canqueue;
2343

@@ -174,9 +194,9 @@ int main() {
174194
// divided by 0.625 for how the current sensor works :/
175195
// divided by 300 because that's the nominal current reading of the sensor (ie baseline)
176196
// multiplied by 10 and cast to a uint16 for 1 decimal place
177-
tsCurrent = (uint16_t)(((current_sense_pin-current_vref_pin)/125.0)*10);
178-
197+
tsCurrent = ((uint16_t)((current_sense_pin-current_vref_pin)/125.0))*10;
179198

199+
queue.dispatch_once();
180200
ThisThread::sleep_for(50 - (t.read_ms()%50));
181201
}
182202
}
@@ -185,6 +205,22 @@ void initIO() {
185205
canBus = new CAN(BMS_PIN_CAN_RX, BMS_PIN_CAN_TX, BMS_CAN_FREQUENCY);
186206
canBus->attach(canRX);
187207

208+
// canBus->write(accBoardBootup());
209+
210+
int canBootupUD = queue.call(&canBootupTX);
211+
queue.dispatch_once();
212+
213+
int canBoardStateID = queue.call_every(100ms, &canBoardStateTX);
214+
int canCurrentLimID = queue.call_every(40ms, &canCurrentLimTX);
215+
int canVoltID0 = queue.call_every(200ms, &canVoltTX0);
216+
int canVoltID1 = queue.call_every(200ms, &canVoltTX1);
217+
int canVoltID2 = queue.call_every(200ms, &canVoltTX2);
218+
int canVoltID3 = queue.call_every(200ms, &canVoltTX3);
219+
int canTempID0 = queue.call_every(200ms, &canTempTX0);
220+
int canTempID1 = queue.call_every(200ms, &canTempTX1);
221+
int canTempID2 = queue.call_every(200ms, &canTempTX2);
222+
int canTempID3 = queue.call_every(200ms, &canTempTX3);
223+
188224

189225
fan_control_pin = 0; // turn fans off at start
190226
charge_enable_pin = 0; // charge not allowed at start
@@ -223,7 +259,7 @@ void canBoardStateTX() {
223259
));
224260
}
225261

226-
void canBoardTempTX(uint8_t segment) {
262+
void canTempTX(uint8_t segment) {
227263
int8_t temps[7] = {
228264
allTemps[(segment * BMS_BANK_CELL_COUNT)],
229265
allTemps[(segment * BMS_BANK_CELL_COUNT) + 1],
@@ -236,7 +272,7 @@ void canBoardTempTX(uint8_t segment) {
236272
canBus->write(accBoardTemp(segment, temps));
237273
}
238274

239-
void canBoardVoltTX(uint8_t segment) {
275+
void canVoltTX(uint8_t segment) {
240276
uint16_t volts[7] = {
241277
allVoltages[(segment * BMS_BANK_CELL_COUNT)],
242278
allVoltages[(segment * BMS_BANK_CELL_COUNT) + 1],
@@ -249,8 +285,40 @@ void canBoardVoltTX(uint8_t segment) {
249285
canBus->write(accBoardVolt(segment, volts));
250286
}
251287

288+
void canVoltTX0() {
289+
canVoltTX(0);
290+
}
291+
292+
void canVoltTX1() {
293+
canVoltTX(1);
294+
}
295+
296+
void canVoltTX2() {
297+
canVoltTX(2);
298+
}
299+
300+
void canVoltTX3() {
301+
canVoltTX(3);
302+
}
303+
304+
void canTempTX0() {
305+
canTempTX(0);
306+
}
307+
308+
void canTempTX1() {
309+
canTempTX(1);
310+
}
311+
312+
void canTempTX2() {
313+
canTempTX(2);
314+
}
315+
316+
void canTempTX3() {
317+
canTempTX(3);
318+
}
319+
252320
void canCurrentLimTX() {
253321
uint16_t chargeCurrentLimit = 0x0000;
254-
uint16_t dischargeCurrentLimit = (uint16_t)(CAR_MAX_POWER/tsVoltage)*CAR_POWER_PERCENT;
322+
uint16_t dischargeCurrentLimit = (uint16_t)(CAR_MAX_POWER/117.6)*CAR_POWER_PERCENT;
255323
canBus->write(motorControllerCurrentLim(chargeCurrentLimit, dischargeCurrentLimit));
256324
}

mainCANbus.dbc

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ BO_ 3221225472 VECTOR__INDEPENDENT_SIG_MSG: 0 Vector__XXX
6060
SG_ TEMP_4 : 32|8@1+ (1,-40) [-40|215] "" Vector__XXX
6161
SG_ TEMP_5 : 40|8@1+ (1,-40) [-40|215] "" Vector__XXX
6262
SG_ TEMP_6 : 48|8@1+ (1,-40) [-40|215] "" Vector__XXX
63+
SG_ Volt_Segment : 0|8@1+ (1,0) [0|0] "" Vector__XXX
64+
SG_ Temp_Segment : 0|8@1+ (1,0) [0|255] "" Vector__XXX
6365

6466
BO_ 386 TPDO_ACC_BOARD_State: 8 Vector__XXX
6567
SG_ GLV_Voltage : 0|8@1+ (0.1,0) [0|25.5] "Volts" Vector__XXX
@@ -76,15 +78,41 @@ BO_ 386 TPDO_ACC_BOARD_State: 8 Vector__XXX
7678
SG_ Max_Cell_Voltage : 40|8@1+ (0.02,0) [0|5.1] "Volts" Vector__XXX
7779
SG_ TS_Current : 48|16@1- (0.1,0) [-3276.8|3276.7] "Amps" Vector__XXX
7880

79-
BO_ 642 TPDO_ACC_BOARD_Temp: 8 Vector__XXX
80-
SG_ TEMP_0 : 8|8@1+ (1,-40) [-40|215] "" Vector__XXX
81-
SG_ TEMP_1 : 16|8@1+ (1,-40) [-40|215] "" Vector__XXX
82-
SG_ TEMP_2 : 24|8@1+ (1,-40) [-40|215] "" Vector__XXX
83-
SG_ TEMP_3 : 32|8@1+ (1,-40) [-40|215] "" Vector__XXX
84-
SG_ TEMP_4 : 40|8@1+ (1,-40) [-40|215] "" Vector__XXX
85-
SG_ TEMP_5 : 48|8@1+ (1,-40) [-40|215] "" Vector__XXX
86-
SG_ TEMP_6 : 56|8@1+ (1,-40) [-40|215] "" Vector__XXX
87-
SG_ Temp_Segment : 0|8@1+ (1,0) [0|255] "" Vector__XXX
81+
BO_ 393 TPDO_ACC_BOARD_Temp_0: 8 Vector__XXX
82+
SG_ Seg0_TEMP_0 : 0|8@1+ (1,-40) [-40|215] "" Vector__XXX
83+
SG_ Seg0_TEMP_1 : 8|8@1+ (1,-40) [-40|215] "" Vector__XXX
84+
SG_ Seg0_TEMP_2 : 16|8@1+ (1,-40) [-40|215] "" Vector__XXX
85+
SG_ Seg0_TEMP_3 : 24|8@1+ (1,-40) [-40|215] "" Vector__XXX
86+
SG_ Seg0_TEMP_4 : 32|8@1+ (1,-40) [-40|215] "" Vector__XXX
87+
SG_ Seg0_TEMP_5 : 40|8@1+ (1,-40) [-40|215] "" Vector__XXX
88+
SG_ Seg0_TEMP_6 : 48|8@1+ (1,-40) [-40|215] "" Vector__XXX
89+
90+
BO_ 649 TPDO_ACC_BOARD_Temp_1: 8 Vector__XXX
91+
SG_ Seg1_TEMP_0 : 0|8@1+ (1,-40) [-40|215] "" Vector__XXX
92+
SG_ Seg1_TEMP_1 : 8|8@1+ (1,-40) [-40|215] "" Vector__XXX
93+
SG_ Seg1_TEMP_2 : 16|8@1+ (1,-40) [-40|215] "" Vector__XXX
94+
SG_ Seg1_TEMP_3 : 24|8@1+ (1,-40) [-40|215] "" Vector__XXX
95+
SG_ Seg1_TEMP_4 : 32|8@1+ (1,-40) [-40|215] "" Vector__XXX
96+
SG_ Seg1_TEMP_5 : 40|8@1+ (1,-40) [-40|215] "" Vector__XXX
97+
SG_ Seg1_TEMP_6 : 48|8@1+ (1,-40) [-40|215] "" Vector__XXX
98+
99+
BO_ 905 TPDO_ACC_BOARD_Temp_2: 8 Vector__XXX
100+
SG_ Seg2_TEMP_0 : 0|8@1+ (1,-40) [-40|215] "" Vector__XXX
101+
SG_ Seg2_TEMP_1 : 8|8@1+ (1,-40) [-40|215] "" Vector__XXX
102+
SG_ Seg2_TEMP_2 : 16|8@1+ (1,-40) [-40|215] "" Vector__XXX
103+
SG_ Seg2_TEMP_3 : 24|8@1+ (1,-40) [-40|215] "" Vector__XXX
104+
SG_ Seg2_TEMP_4 : 32|8@1+ (1,-40) [-40|215] "" Vector__XXX
105+
SG_ Seg2_TEMP_5 : 40|8@1+ (1,-40) [-40|215] "" Vector__XXX
106+
SG_ Seg2_TEMP_6 : 48|8@1+ (1,-40) [-40|215] "" Vector__XXX
107+
108+
BO_ 1161 TPDO_ACC_BOARD_Temp_3: 8 Vector__XXX
109+
SG_ Seg3_TEMP_0 : 0|8@1+ (1,-40) [-40|215] "" Vector__XXX
110+
SG_ Seg3_TEMP_1 : 8|8@1+ (1,-40) [-40|215] "" Vector__XXX
111+
SG_ Seg3_TEMP_2 : 16|8@1+ (1,-40) [-40|215] "" Vector__XXX
112+
SG_ Seg3_TEMP_3 : 24|8@1+ (1,-40) [-40|215] "" Vector__XXX
113+
SG_ Seg3_TEMP_4 : 32|8@1+ (1,-40) [-40|215] "" Vector__XXX
114+
SG_ Seg3_TEMP_5 : 40|8@1+ (1,-40) [-40|215] "" Vector__XXX
115+
SG_ Seg3_TEMP_6 : 48|8@1+ (1,-40) [-40|215] "" Vector__XXX
88116

89117
BO_ 1794 NMT_ACC_HEARTBEAT: 8 Vector__XXX
90118
SG_ Status : 0|8@1+ (1,0) [0|255] "" Vector__XXX
@@ -97,15 +125,41 @@ BO_ 644 TPDO_BSPD_BOARD_Brake: 8 Vector__XXX
97125
SG_ IMD_Fault : 25|1@1+ (1,0) [0|1] "" Vector__XXX
98126
SG_ BSPD_Fault : 26|1@1+ (1,0) [0|1] "" Vector__XXX
99127

100-
BO_ 899 TPDO_ACC_BOARD_Volt: 8 Vector__XXX
101-
SG_ Volt_Segment : 0|8@1+ (1,0) [0|0] "" Vector__XXX
102-
SG_ VOLT_0 : 8|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
103-
SG_ VOLT_1 : 16|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
104-
SG_ VOLT_2 : 24|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
105-
SG_ VOLT_3 : 32|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
106-
SG_ VOLT_4 : 40|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
107-
SG_ VOLT_5 : 48|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
108-
SG_ VOLT_6 : 56|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
128+
BO_ 392 TPDO_ACC_BOARD_Volt_0: 8 Vector__XXX
129+
SG_ Seg0_VOLT_0 : 0|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
130+
SG_ Seg0_VOLT_1 : 8|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
131+
SG_ Seg0_VOLT_2 : 16|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
132+
SG_ Seg0_VOLT_3 : 24|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
133+
SG_ Seg0_VOLT_4 : 32|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
134+
SG_ Seg0_VOLT_5 : 40|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
135+
SG_ Seg0_VOLT_6 : 48|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
136+
137+
BO_ 648 TPDO_ACC_BOARD_Volt_1: 8 Vector__XXX
138+
SG_ Seg1_VOLT_0 : 0|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
139+
SG_ Seg1_VOLT_1 : 8|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
140+
SG_ Seg1_VOLT_2 : 16|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
141+
SG_ Seg1_VOLT_3 : 24|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
142+
SG_ Seg1_VOLT_4 : 32|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
143+
SG_ Seg1_VOLT_5 : 40|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
144+
SG_ Seg1_VOLT_6 : 48|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
145+
146+
BO_ 904 TPDO_ACC_BOARD_Volt_2: 8 Vector__XXX
147+
SG_ Seg2_VOLT_0 : 0|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
148+
SG_ Seg2_VOLT_1 : 8|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
149+
SG_ Seg2_VOLT_2 : 16|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
150+
SG_ Seg2_VOLT_3 : 24|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
151+
SG_ Seg2_VOLT_4 : 32|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
152+
SG_ Seg2_VOLT_5 : 40|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
153+
SG_ Seg2_VOLT_6 : 48|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
154+
155+
BO_ 1160 TPDO_ACC_BOARD_Volt_3: 8 Vector__XXX
156+
SG_ Seg3_VOLT_0 : 0|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
157+
SG_ Seg3_VOLT_1 : 8|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
158+
SG_ Seg3_VOLT_2 : 16|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
159+
SG_ Seg3_VOLT_3 : 24|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
160+
SG_ Seg3_VOLT_4 : 32|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
161+
SG_ Seg3_VOLT_5 : 40|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
162+
SG_ Seg3_VOLT_6 : 48|8@1+ (0.02,0) [0|5.1] "V" Vector__XXX
109163

110164

111165

@@ -125,6 +179,5 @@ BA_DEF_DEF_ "BusType" "";
125179
BA_DEF_DEF_ "ECU" "";
126180
BA_DEF_DEF_ "VFrameFormat" "StandardCAN";
127181
BA_ "BusType" "CAN FD";
128-
VAL_ 642 Temp_Segment 1 "Segment 0" 2 "Segment 1" 3 "Segment 2" 4 "Segment 3" ;
129182
VAL_ 1794 Status 0 "Boot up" 4 "Stopped" 5 "Operational" 127 "Pre-operational" ;
130183

0 commit comments

Comments
 (0)