Skip to content

Commit 0e17fde

Browse files
authored
Merge pull request #27 from formulaslug/pd_logging
PD Board Current reading correction
2 parents 6787d23 + ad62698 commit 0e17fde

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

CANbus.dbc

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ NS_ :
3232
SG_MUL_VAL_
3333

3434
BS_:
35+
3536
BU_: SME ACC ETC PDB TMAIN VDM TPERIPH_FL TPERIPH_FR TPERIPH_BL TPERIPH_BR SMPC CHARGER_BOARD
37+
38+
3639
BO_ 2147483648 VECTOR__INDEPENDENT_SIG_MSG: 0 Vector__XXX
3740
SG_ ACC_STATUS_PRECARGE_DONE : 5|1@1+ (1,0) [0|0] "" Vector__XXX
3841
SG_ ACC_SEG5_VOLTS_CELL0 : 0|8@1+ (0.01,2) [2|4.55] "V" Vector__XXX
@@ -237,20 +240,20 @@ BO_ 393 ETC_TPDO_STATUS: 8 ETC
237240

238241
BO_ 410 PDB_TPDO_POWER_A: 8 PDB
239242
SG_ PDB_POWER_A_GLV_VOLTAGE : 0|16@1+ (1,0) [0|65535] "mV" Vector__XXX
240-
SG_ PDB_POWER_A_CURRENT_SHUTDOWN : 16|8@1+ (0.1,0) [0|25.5] "A" Vector__XXX
241-
SG_ PDB_POWER_A_CURRENT_ACC : 24|8@1+ (0.1,0) [0|25.5] "A" Vector__XXX
242-
SG_ PDB_POWER_A_CURRENT_ETC : 32|8@1+ (0.1,0) [0|25.5] "A" Vector__XXX
243-
SG_ PDB_POWER_A_CURRENT_BPS : 40|8@1+ (0.1,0) [0|25.5] "A" Vector__XXX
244-
SG_ PDB_POWER_A_CURRENT_TRACTIVE : 48|8@1+ (0.1,0) [0|25.5] "A" Vector__XXX
245-
SG_ PDB_POWER_A_CURRENT_BSPD : 56|8@1+ (0.1,0) [0|25.5] "A" Vector__XXX
243+
SG_ PDB_POWER_A_CURRENT_SHUTDOWN : 16|8@1+ (1,0) [0|255] "lsb" Vector__XXX
244+
SG_ PDB_POWER_A_CURRENT_ACC : 24|8@1+ (1,0) [0|255] "lsb" Vector__XXX
245+
SG_ PDB_POWER_A_CURRENT_ETC : 32|8@1+ (1,0) [0|255] "lsb" Vector__XXX
246+
SG_ PDB_POWER_A_CURRENT_BPS : 40|8@1+ (1,0) [0|255] "lsb" Vector__XXX
247+
SG_ PDB_POWER_A_CURRENT_TRACTIVE : 48|8@1+ (1,0) [0|255] "lsb" Vector__XXX
248+
SG_ PDB_POWER_A_CURRENT_BSPD : 56|8@1+ (1,0) [0|255] "lsb" Vector__XXX
246249

247250
BO_ 666 PDB_TPDO_POWER_B: 8 PDB
248-
SG_ PDB_POWER_B_CURRENT_TELEMETRY : 0|8@1+ (0.1,0) [0|25.5] "A" Vector__XXX
249-
SG_ PDB_POWER_B_CURRENT_PDB : 8|8@1+ (0.1,0) [0|25.5] "A" Vector__XXX
250-
SG_ PDB_POWER_B_CURRENT_DASH : 16|8@1+ (0.1,0) [0|25.5] "A" Vector__XXX
251-
SG_ PDB_POWER_B_CURRENT_RTML : 24|8@1+ (0.1,0) [0|25.5] "A" Vector__XXX
252-
SG_ PDB_POWER_B_CURRENT_EXTRA_1 : 32|8@1+ (0.1,0) [0|25.5] "A" Vector__XXX
253-
SG_ PDB_POWER_B_CURRENT_EXTRA_2 : 40|8@1+ (0.1,0) [0|25.5] "A" Vector__XXX
251+
SG_ PDB_POWER_B_CURRENT_TELEMETRY : 0|8@1+ (1,0) [0|255] "lsb" Vector__XXX
252+
SG_ PDB_POWER_B_CURRENT_PDB : 8|8@1+ (1,0) [0|255] "lsb" Vector__XXX
253+
SG_ PDB_POWER_B_CURRENT_DASH : 16|8@1+ (1,0) [0|255] "lsb" Vector__XXX
254+
SG_ PDB_POWER_B_CURRENT_RTML : 24|8@1+ (1,0) [0|255] "lsb" Vector__XXX
255+
SG_ PDB_POWER_B_CURRENT_EXTRA_1 : 32|8@1+ (1,0) [0|255] "lsb" Vector__XXX
256+
SG_ PDB_POWER_B_CURRENT_EXTRA_2 : 40|8@1+ (1,0) [0|255] "lsb" Vector__XXX
254257

255258
BO_ 416 TMAIN_TPDO_DATA: 8 TMAIN
256259
SG_ TMAIN_DATA_BRAKES_F : 0|16@1+ (0.1,0) [0|0] "psi" Vector__XXX
@@ -375,9 +378,12 @@ BO_ 1168 SMPC_TPDO_SERIAL_PART_NUM: 8 SMPC
375378
SG_ SMPC_SER_SERIAL_NUMBER : 16|32@1+ (1,0) [0|2704] "" Vector__XXX
376379
SG_ SMPC_SER_PART_NUMBER : 0|16@1+ (1,0) [0|65535] "" Vector__XXX
377380

381+
382+
378383
BA_DEF_ "BusType" STRING ;
379384
BA_DEF_ BO_ "GenMsgBackgroundColor" STRING ;
380385
BA_DEF_ BO_ "GenMsgForegroundColor" STRING ;
381386
BA_DEF_DEF_ "BusType" "CAN";
382387
BA_DEF_DEF_ "GenMsgBackgroundColor" "#c8c8c8";
383388
BA_DEF_DEF_ "GenMsgForegroundColor" "#000000";
389+

PDB/main.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "mbed.h"
2-
#include <vector>
3-
#include <numeric>
42
#include <map>
3+
#include <numeric>
4+
#include <vector>
55

66
DigitalOut dcdc_ctrl(PB_5);
77
DigitalOut reset_ctrl(PA_1);
@@ -14,7 +14,7 @@ AnalogIn viout(PB_0);
1414

1515
CAN* can;
1616

17-
EventQueue queue(32* EVENTS_EVENT_SIZE);
17+
EventQueue queue(32 * EVENTS_EVENT_SIZE);
1818

1919
uint16_t glv;
2020

@@ -31,7 +31,6 @@ vector<uint8_t> dash_curr_vec;
3131
vector<uint8_t> ex1_curr_vec;
3232
vector<uint8_t> etc_curr_vec;
3333

34-
3534
uint8_t rtm_curr;
3635
uint8_t bps_curr;
3736
uint8_t bspd_curr;
@@ -45,7 +44,6 @@ uint8_t dash_curr;
4544
uint8_t ex1_curr;
4645
uint8_t etc_curr;
4746

48-
4947
enum DEVICES {
5048
RTM = 1,
5149
BPS = 2,
@@ -61,14 +59,12 @@ enum DEVICES {
6159
ETC = 14
6260
};
6361

64-
6562
void send_PDB_TPDO_POWER_A();
6663
void send_PDB_TPDO_POWER_B();
6764

6865
uint8_t read_current();
6966

70-
uint8_t process_current(std::vector<uint8_t> vec);
71-
67+
uint8_t process_current(std::vector<uint8_t> &vec);
7268

7369
void send_PDB_TPDO_POWER_A() {
7470
CANMessage msg;
@@ -100,13 +96,11 @@ void send_PDB_TPDO_POWER_B() {
10096
// printf("CAN B sent\n");
10197
}
10298

103-
104-
105-
int main(){
99+
int main() {
106100
printf("entering main\n");
107101

108102
can = new CAN(PA_11, PA_12, 500000);
109-
can->filter(0x188, 0xFF, CANAny); //ACC_TPDO_STATUS TODO: does this even work?
103+
can->filter(0x188, 0xFF, CANAny); // ACC_TPDO_STATUS TODO: does this even work?
110104

111105
queue.call_every(200ms, send_PDB_TPDO_POWER_A);
112106
queue.call_every(200ms, send_PDB_TPDO_POWER_B);
@@ -174,16 +168,20 @@ int main(){
174168
}
175169
}
176170

177-
uint8_t process_current(std::vector<uint8_t> vec) {
171+
uint8_t process_current(std::vector<uint8_t> &vec) {
178172
vec.push_back(read_current());
179173
if (vec.size() > 5)
180174
{
181175
vec.erase(vec.begin());
182176
}
183-
return std::accumulate(vec.begin(), vec.end(), 0)/vec.size();
177+
return std::accumulate(vec.begin(), vec.end(), 0) / vec.size();
184178
}
185179

186180
uint8_t read_current() {
187-
double current_A = ((viout.read() * 3.3) - 1.65) / 0.055;
188-
return clamp(static_cast<int>(current_A / 10), 0, 255);
181+
// Read the current sensor and store the value as a uint8 [0,255]
182+
// Could do this with .read_uint16() but the bitshift would be different
183+
// depending on the ADC bitdepth and this is guaranteed to work.
184+
185+
// TODO: Update DBC with Voltage-Current mappings for each sensor
186+
return static_cast<uint8_t>(viout.read() * 255);
189187
}

0 commit comments

Comments
 (0)