Skip to content

Commit debad7c

Browse files
committed
feat_ updateBMS if config is different from expected. feat: STOP_ON_UVP behaviour
1 parent 45aae84 commit debad7c

File tree

6 files changed

+65
-2
lines changed

6 files changed

+65
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.DS_Store
33
.AppleDouble
44
.LSOverride
5+
.vscode
56

67
# Icon must end with two \r
78
Icon

examples/firmware/firmware.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ void loop(){
213213
case 1:
214214
alvik.setBehaviour(LIFT_ILLUMINATOR, true);
215215
break;
216+
case STOP_ON_UVP:
217+
alvik.setBehaviour(STOP_ON_UVP, true);
218+
break;
216219
default:
217220
alvik.setBehaviour(ALL_BEHAVIOURS, false);
218221
}

src/Arduino_AlvikCarrier.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "Arduino_AlvikCarrier.h"
1313
#include "./utilities/HAL_custom_init.h"
14-
14+
#include "INR18650_config.h"
1515

1616

1717
Arduino_AlvikCarrier::Arduino_AlvikCarrier(){
@@ -271,6 +271,11 @@ void Arduino_AlvikCarrier::disconnectExternalI2C(){
271271
int Arduino_AlvikCarrier::beginBMS(){
272272
while(digitalRead(NANO_CHK)==HIGH){}
273273
bms->begin();
274+
275+
if (!bms->compareWithMem(inr18650_config)){
276+
upgradeBMS();
277+
}
278+
274279
return 0;
275280
}
276281

@@ -288,6 +293,15 @@ float Arduino_AlvikCarrier::getBatteryChargePercentage(){
288293
return state_of_charge;
289294
}
290295

296+
void Arduino_AlvikCarrier::upgradeBMS(){
297+
298+
bms->writeShadowMem(inr18650_config);
299+
300+
// MAX17332_Programmer bmsProgrammer(*bms);
301+
// bmsProgrammer.writeNVM(inr18650_config);
302+
303+
return;
304+
}
291305

292306

293307
/******************************************************************************************************/
@@ -1007,6 +1021,19 @@ void Arduino_AlvikCarrier::updateBehaviours(){
10071021
}
10081022
}
10091023
}
1024+
1025+
if ((bool) behaviours & STOP_ON_UVP){
1026+
1027+
if (bms->readSoc() < BATTERY_CHARGE_MIN && !bms->isCharging()){
1028+
setLedLeftRed(1);
1029+
setLedRightRed(0);
1030+
delay(500);
1031+
setLedLeftRed(0);
1032+
setLedRightRed(1);
1033+
delay(500);
1034+
// TODO MEMORIZE A STATE VARIABLE TO STOP MOTORS ETC...
1035+
}
1036+
}
10101037
}
10111038

10121039
void Arduino_AlvikCarrier::setBehaviour(const uint8_t behaviour, const bool enable){

src/Arduino_AlvikCarrier.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "motion_fx.h"
2828
#include "./robotics/kinematics.h"
2929

30+
#define BATTERY_CHARGE_MIN 10.0
31+
3032

3133

3234
class Arduino_AlvikCarrier{
@@ -156,7 +158,7 @@ class Arduino_AlvikCarrier{
156158
void updateBMS(); // update the BMS
157159
float getBatteryVoltage(); // get Voltage
158160
float getBatteryChargePercentage(); // get battery percentage
159-
161+
void upgradeBMS();
160162

161163

162164
// Motors

src/INR18650_config.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
/*
3+
4+
Arduino INR18650 config for MAX17332 BMS
5+
6+
Copyright (c) 2023 Arduino SA
7+
8+
This Source Code Form is subject to the terms of the Mozilla Public
9+
License, v. 2.0. If a copy of the MPL was not distributed with this
10+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
11+
12+
*/
13+
14+
#ifndef _INR18650_H_
15+
#define _INR18650_H_
16+
17+
18+
const uint8_t inr18650_config[] = {
19+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x5F, 0xA0, 0x00, 0x00,
21+
0x80, 0x29, 0x00, 0x14, 0x02, 0x09, 0x83, 0x07, 0x00, 0x00, 0xA8, 0x16, 0xCC, 0x08, 0x3E, 0x22, 0x00, 0x00, 0x88, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
22+
0x00, 0x00, 0x04, 0x02, 0x00, 0x00, 0x83, 0x3E, 0x00, 0x00, 0x85, 0x07, 0x00, 0x00, 0x41, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
23+
0x09, 0x42, 0x6D, 0x04, 0x06, 0x14, 0x72, 0xE2, 0xA7, 0x00, 0x00, 0xAA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x88, 0x51, 0xBE, 0x71, 0x3F, 0x3E, 0x05, 0x50, 0x66, 0x66, 0x28, 0x2E, 0x55, 0x55,
24+
0x4C, 0x3D, 0x38, 0x20, 0x00, 0x70, 0x00, 0x51, 0x28, 0xA0, 0x05, 0x30, 0x28, 0x7A, 0x00, 0x30, 0xE0, 0x00, 0x02, 0x01, 0x81, 0xFA, 0x0A, 0xBE, 0x3D, 0x9B, 0xAF, 0x0E, 0x55, 0x43, 0x5F, 0x00,
25+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
26+
};
27+
28+
29+
#endif

src/definitions/robot_definitions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const float MOTOR_RATIO = MOTOR_CPR*MOTOR_GEAR_RATIO;
6868

6969
#define ALL_BEHAVIOURS 255
7070
#define LIFT_ILLUMINATOR 1
71+
#define STOP_ON_UVP 2
7172

7273

7374

0 commit comments

Comments
 (0)