Skip to content

Commit 58bd417

Browse files
committed
Switched battery charging print out to use navigator info and print once every percent increase
1 parent cadcb6c commit 58bd417

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

turtlebot4_python_tutorials/turtlebot4_python_tutorials/patrol_loop.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#
1717
# @author Hilary Luo ([email protected])
1818

19+
from math import floor
1920
from threading import Lock, Thread
2021
from time import sleep
2122

@@ -117,11 +118,16 @@ def main(args=None):
117118

118119
# Wait until charged
119120
navigator.info('Charging...')
121+
battery_percent_prev = 0
120122
while (battery_percent < BATTERY_HIGH):
121123
sleep(15)
124+
battery_percent_prev = floor(battery_percent*100)/100
122125
with lock:
123126
battery_percent = battery_monitor.battery_percent
124-
print(f'Battery is at {(battery_percent*100):.2f}% charge', end='\r')
127+
128+
# Print charge level every time it increases a percent
129+
if battery_percent > (battery_percent_prev + 0.01):
130+
navigator.info(f'Battery is at {(battery_percent*100):.2f}% charge')
125131

126132
# Undock
127133
navigator.undock()

0 commit comments

Comments
 (0)