Skip to content

Commit ac54a92

Browse files
committed
battery alert behaviour
1 parent 3979129 commit ac54a92

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

src/Arduino_AlvikCarrier.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -969,10 +969,14 @@ void Arduino_AlvikCarrier::beginBehaviours(){
969969
prev_illuminator_state = illuminator_state;
970970
behaviours = 0;
971971
first_lift = true;
972+
battery_alert_time = millis();
973+
battery_alert_wave = 100;
972974
}
973975

974976

975977
void Arduino_AlvikCarrier::updateBehaviours(){
978+
979+
// illuminator off on lift
976980
if ((1<<(LIFT_ILLUMINATOR-1)) & behaviours){
977981

978982
if (isLifted()&&first_lift){
@@ -990,11 +994,24 @@ void Arduino_AlvikCarrier::updateBehaviours(){
990994
}
991995
}
992996

993-
if ((1 << (BATTERY_ALERT-1)) & behaviours){
994-
led1->setRed(true);
995-
}
996-
else{
997-
led1->setRed(false);
997+
// battery alert
998+
if ((1<<(BATTERY_ALERT-1)) & behaviours){
999+
if (getBatteryVoltage()<BATTERY_ALERT_MINIMUM_VOLTAGE){
1000+
if (battery_alert_time-millis()>battery_alert_wave){
1001+
battery_alert_time = millis();
1002+
if (battery_alert_wave==100){
1003+
setAllLeds(COLOR_RED);
1004+
battery_alert_wave=400;
1005+
}
1006+
else{
1007+
setAllLeds(COLOR_BLACK);
1008+
battery_alert_wave=100;
1009+
}
1010+
setRpm(0,0);
1011+
motor_left->stop();
1012+
motor_right->stop();
1013+
}
1014+
}
9981015
}
9991016

10001017
}

src/Arduino_AlvikCarrier.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class Arduino_AlvikCarrier{
9494
bool prev_illuminator_state;
9595
uint8_t behaviours;
9696
bool first_lift;
97+
unsigned long battery_alert_time;
98+
unsigned long battery_alert_wave;
9799

98100

99101

src/definitions/robot_definitions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ const float MOTION_FX_PERIOD = (1000U / MOTION_FX_FREQ);
9595
#define VERSION_BYTE_MID 0
9696
#define VERSION_BYTE_LOW 3
9797

98+
// Battery stats
99+
#define BATTERY_ALERT_MINIMUM_VOLTAGE 3.4
100+
98101

99102

100103
#endif

0 commit comments

Comments
 (0)