diff --git a/.gitignore b/.gitignore index e7bcaed..608a9a8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .DS_Store .AppleDouble .LSOverride +.vscode # Icon must end with two \r Icon diff --git a/examples/firmware/firmware.ino b/examples/firmware/firmware.ino index df7ffa5..4fd57d3 100644 --- a/examples/firmware/firmware.ino +++ b/examples/firmware/firmware.ino @@ -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); } diff --git a/src/Arduino_AlvikCarrier.cpp b/src/Arduino_AlvikCarrier.cpp index 139089a..ae09f54 100644 --- a/src/Arduino_AlvikCarrier.cpp +++ b/src/Arduino_AlvikCarrier.cpp @@ -11,7 +11,7 @@ #include "Arduino_AlvikCarrier.h" #include "./utilities/HAL_custom_init.h" - +#include "INR18650_config.h" Arduino_AlvikCarrier::Arduino_AlvikCarrier(){ @@ -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; } @@ -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; +} /******************************************************************************************************/ @@ -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){ diff --git a/src/Arduino_AlvikCarrier.h b/src/Arduino_AlvikCarrier.h index 9d683aa..fcc5b62 100644 --- a/src/Arduino_AlvikCarrier.h +++ b/src/Arduino_AlvikCarrier.h @@ -27,6 +27,8 @@ #include "motion_fx.h" #include "./robotics/kinematics.h" +#define BATTERY_CHARGE_MIN 10.0 + class Arduino_AlvikCarrier{ @@ -156,7 +158,7 @@ class Arduino_AlvikCarrier{ void updateBMS(); // update the BMS float getBatteryVoltage(); // get Voltage float getBatteryChargePercentage(); // get battery percentage - + void upgradeBMS(); // Motors diff --git a/src/INR18650_config.h b/src/INR18650_config.h new file mode 100644 index 0000000..bfffd2f --- /dev/null +++ b/src/INR18650_config.h @@ -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 diff --git a/src/definitions/robot_definitions.h b/src/definitions/robot_definitions.h index 54540ab..088db1f 100644 --- a/src/definitions/robot_definitions.h +++ b/src/definitions/robot_definitions.h @@ -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