Skip to content

Commit

Permalink
feat_ updateBMS if config is different from expected. feat: STOP_ON_U…
Browse files Browse the repository at this point in the history
…VP behaviour
  • Loading branch information
eigen-value committed Oct 4, 2024
1 parent 45aae84 commit debad7c
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.DS_Store
.AppleDouble
.LSOverride
.vscode

# Icon must end with two \r
Icon
Expand Down
3 changes: 3 additions & 0 deletions examples/firmware/firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ void loop(){
case 1:
alvik.setBehaviour(LIFT_ILLUMINATOR, true);
break;
case STOP_ON_UVP:
alvik.setBehaviour(STOP_ON_UVP, true);
break;
default:
alvik.setBehaviour(ALL_BEHAVIOURS, false);
}
Expand Down
29 changes: 28 additions & 1 deletion src/Arduino_AlvikCarrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "Arduino_AlvikCarrier.h"
#include "./utilities/HAL_custom_init.h"

#include "INR18650_config.h"


Arduino_AlvikCarrier::Arduino_AlvikCarrier(){
Expand Down Expand Up @@ -271,6 +271,11 @@ void Arduino_AlvikCarrier::disconnectExternalI2C(){
int Arduino_AlvikCarrier::beginBMS(){
while(digitalRead(NANO_CHK)==HIGH){}
bms->begin();

if (!bms->compareWithMem(inr18650_config)){
upgradeBMS();
}

return 0;
}

Expand All @@ -288,6 +293,15 @@ float Arduino_AlvikCarrier::getBatteryChargePercentage(){
return state_of_charge;
}

void Arduino_AlvikCarrier::upgradeBMS(){

bms->writeShadowMem(inr18650_config);

// MAX17332_Programmer bmsProgrammer(*bms);
// bmsProgrammer.writeNVM(inr18650_config);

return;
}


/******************************************************************************************************/
Expand Down Expand Up @@ -1007,6 +1021,19 @@ void Arduino_AlvikCarrier::updateBehaviours(){
}
}
}

if ((bool) behaviours & STOP_ON_UVP){

if (bms->readSoc() < BATTERY_CHARGE_MIN && !bms->isCharging()){
setLedLeftRed(1);
setLedRightRed(0);
delay(500);
setLedLeftRed(0);
setLedRightRed(1);
delay(500);
// TODO MEMORIZE A STATE VARIABLE TO STOP MOTORS ETC...
}
}
}

void Arduino_AlvikCarrier::setBehaviour(const uint8_t behaviour, const bool enable){
Expand Down
4 changes: 3 additions & 1 deletion src/Arduino_AlvikCarrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "motion_fx.h"
#include "./robotics/kinematics.h"

#define BATTERY_CHARGE_MIN 10.0



class Arduino_AlvikCarrier{
Expand Down Expand Up @@ -156,7 +158,7 @@ class Arduino_AlvikCarrier{
void updateBMS(); // update the BMS
float getBatteryVoltage(); // get Voltage
float getBatteryChargePercentage(); // get battery percentage

void upgradeBMS();


// Motors
Expand Down
29 changes: 29 additions & 0 deletions src/INR18650_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

/*
Arduino INR18650 config for MAX17332 BMS
Copyright (c) 2023 Arduino SA
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#ifndef _INR18650_H_
#define _INR18650_H_


const uint8_t inr18650_config[] = {
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,
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,
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,
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,
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,
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,
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,
};


#endif
1 change: 1 addition & 0 deletions src/definitions/robot_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const float MOTOR_RATIO = MOTOR_CPR*MOTOR_GEAR_RATIO;

#define ALL_BEHAVIOURS 255
#define LIFT_ILLUMINATOR 1
#define STOP_ON_UVP 2



Expand Down

0 comments on commit debad7c

Please sign in to comment.