Skip to content

Commit 7df710c

Browse files
committed
Warn about low battery before and after moving
1 parent 69688dc commit 7df710c

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/hmi.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ void blink_collision(void)
110110
led_right_off();
111111
}
112112

113+
/**
114+
* @brief Warn low battery using speaker sounds.
115+
*/
116+
void warn_low_battery(void)
117+
{
118+
speaker_play('C', 4, 0, 0.05);
119+
sleep_ticks(50);
120+
speaker_play('C', 3, 0, 0.05);
121+
sleep_ticks(50);
122+
}
123+
113124
/**
114125
* @brief Function to read button left.
115126
*/

src/hmi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "clock.h"
77
#include "detection.h"
8+
#include "speaker.h"
89
#include "speed.h"
910

1011
void led_left_toggle(void);
@@ -18,6 +19,7 @@ void led_right_off(void);
1819
void led_bluepill_off(void);
1920
void repeat_blink(uint8_t count, uint16_t time);
2021
void blink_collision(void);
22+
void warn_low_battery(void);
2123
bool button_left_read(void);
2224
bool button_right_read(void);
2325
bool button_left_read_consecutive(uint32_t count);

src/main.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ static void user_configuration(bool run)
4747
set_speed_mode(mode, run);
4848
}
4949

50+
/**
51+
* @brief Check battery voltage and warn if the voltage is getting too low.
52+
*/
53+
static void check_battery_voltage(void)
54+
{
55+
float voltage;
56+
57+
voltage = get_battery_voltage();
58+
if (voltage < 3.6)
59+
warn_low_battery();
60+
if (voltage < 3.5)
61+
warn_low_battery();
62+
if (voltage < 3.4)
63+
warn_low_battery();
64+
if (voltage < 3.3)
65+
speaker_play('C', 3, 0, 2.);
66+
}
67+
5068
/**
5169
* @brief Includes the functions to be executed before robot starts to move.
5270
*/
@@ -56,6 +74,7 @@ static void before_moving(void)
5674
disable_walls_control();
5775
repeat_blink(10, 100);
5876
sleep_us(5000000);
77+
check_battery_voltage();
5978
led_left_on();
6079
led_right_on();
6180
wait_front_sensor_close_signal(0.12);
@@ -79,6 +98,7 @@ static void after_moving(void)
7998
repeat_blink(10, 100);
8099
}
81100
reset_motion();
101+
check_battery_voltage();
82102
}
83103

84104
/**

0 commit comments

Comments
 (0)