Skip to content

Commit

Permalink
progress, not rm container while debugging to keep logs
Browse files Browse the repository at this point in the history
  • Loading branch information
slowrunner committed Sep 5, 2024
1 parent 0d64762 commit 485f696
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 23 deletions.
32 changes: 21 additions & 11 deletions plib/safetyShutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ def main():
str_to_log = "'Starting safetyShutdown.py at {:.2f} volts.'".format(egpg.volt()+battery.REV_PROTECT_DIODE)
os.system("/home/pi/GoPi5Go/utils/logMaintenance.py " + str_to_log)

try:
while True:
doloop = True

while doloop:
try:
status.printStatus(egpg)
if (battery.too_low(egpg)):
batteryLowCount += 1
Expand Down Expand Up @@ -109,15 +111,23 @@ def main():
sys.exit(0)
time.sleep(10) # check battery status every 10 seconds
# important to make four checks low V quickly
#end while
except SystemExit:
print("safetyShutdown.py: exiting")

except Exception as e:
print("safetyShutdown.py exiting with exception: ",type(e).__name__,",",str(e))
str_to_log="Exiting with Exception "+type(e).__name__+": "+str(e)+"\n"
print(str_to_log)
lifeLog.logger.info(str_to_log)
except SystemExit:
doloop = False

except Exception as e:
print("safetyShutdown.py exception: ",type(e).__name__,",",str(e))
str_to_log="Continuing after Exception "+type(e).__name__+": "+str(e)
print(str_to_log)
lifeLog.logger.info(str_to_log)

#end try
#end while
print("safetyShutdown.py: exiting")
str_to_log="Normal Exit"
lifeLog.logger.info(str_to_log)



if __name__ == "__main__":
main()

Expand Down
3 changes: 1 addition & 2 deletions ros2ws/run_docker_detached_gopi5goROS2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


cd /home/pi/GoPi5Go/ros2ws
# --rm remove container after running
# --rm \ remove container after running
# Prob not need
# --device /dev/gpiochip4 \

Expand All @@ -18,6 +18,5 @@ docker run -dt --net=host \
-e TZ=America/New_York \
-w /home/pi/GoPi5Go/ros2ws \
--privileged \
--rm \
--name gopi5goROS2 \
gopi5gor2hdp
4 changes: 2 additions & 2 deletions ros2ws/src/gopi5go_dave/gopi5go_dave/dave_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def dave_main_cb(self):
try:
# Announce Undocking with say service
if self.say_svc_client.service_is_ready():
sayMsg = "charging at {:.0f} mA, calling undock service ".format(self.battery_state.milliamps)
sayMsg = "charging at {:d} milliamps, calling undock service ".format(int(abs(self.battery_state.milliamps)))
self.send_say_svc_req(sayMsg)
except Exception as e:
dtstr = dt.datetime.now().strftime(DT_FORMAT)
Expand Down Expand Up @@ -340,7 +340,7 @@ def dave_main_cb(self):
try:
# Announce Docking with say service
if self.say_svc_client.service_is_ready():
sayMsg = "battery_status.volts {:.1f}v calling dock service ".format(self.battery_state.volts)
sayMsg = "battery at {:.1f} volts, calling dock service ".format(self.battery_state.volts)
self.send_say_svc_req(sayMsg)
except Exception as e:
dtstr = dt.datetime.now().strftime(DT_FORMAT)
Expand Down
21 changes: 13 additions & 8 deletions ros2ws/src/gopi5go_dave/gopi5go_dave/say_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,26 @@ def say_cb(self, request, response):
audio = voice.synthesize(text,wav_file)
if DEBUG:
dtstr = dt.datetime.now().strftime(DT_FORMAT)
print(dtstr,"say_node: file written, speaking phrase")
print(dtstr,"say_node: file written, calling aplay")

# subprocess.check_output(['aplay -D plughw:2,0 -r 22050 -f S16_LE ' + filename], stderr=subprocess.STDOUT, shell=True)
os.system('aplay -D plughw:2,0 -r 22050 -f S16_LE ' + filename)

try:
os.system('aplay -D plughw:2,0 -r 22050 -f S16_LE ' + filename)
response.spoken = True
except Exception as e:
logStr = "Exception: {}".format(str(e))
self.get_logger().info(logStr)
response.spoken = False
if DEBUG:
dtstr = dt.datetime.now().strftime(DT_FORMAT)
print(dtstr,"say_node: after aplay")

os.remove(filename)
if DEBUG:
dtstr = dt.datetime.now().strftime(DT_FORMAT)
print(dtstr,"say_node: file removed")
if os.path.isfile(filename):
os.remove(filename)
if DEBUG:
dtstr = dt.datetime.now().strftime(DT_FORMAT)
print(dtstr,"say_node: file removed")

response.spoken = True
self.logger.info(text + " - spoken: " + str(response.spoken) )

return response
Expand Down
11 changes: 11 additions & 0 deletions utils/what_uses.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# FILE: what_uses.sh
# USAGE: ./what_uses.sh "pattern"

if [ "$#" -ne 1 ] ;
then echo "Usage: ./what_uses.sh \"import xyz\" "
exit
fi
echo "Searching to find what Python files use \"$1\" "
grep -r --include "*.py" "$1" .

0 comments on commit 485f696

Please sign in to comment.