Skip to content

Commit

Permalink
Merge pull request #40 from monocle-h2020/20240617_stsi_escape-TPR-re…
Browse files Browse the repository at this point in the history
…ad-errors

20240617 stsi escape tpr read errors
  • Loading branch information
StefanSimis authored Nov 14, 2024
2 parents 3cccb04 + 28f9614 commit f488337
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bin/tests/test_TPR.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from initialisation import tpr_init
from main_app import parse_args
import functions.config_functions as cf
test_duration_single_reads = 60 # seconds
test_duration_single_reads = 5 # seconds
test_duration_monitor_average = 300 # seconds


Expand Down
22 changes: 19 additions & 3 deletions bin/thread_managers/tpr_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ def __init__(self, tpr):
self.zindex = tpr['zindex'] # 0
self.xindex = tpr['xindex'] # 1
self.sampling_time = tpr['sampling_time'] # sampling cycle in seconds, default 10 seconds
self.update_pitch_roll_single() # init with first reading
self.errorcount = 0
try:
self.update_pitch_roll_single() # init with first reading
except OSError:
log.warning("Ignored error reading TPR sensor")
self.errorcount += 1

self.buffer_time = [self.updated]
self.buffer_tilt = [self.tilt]
self.buffer_pitch = [self.pitch]
Expand Down Expand Up @@ -131,7 +137,17 @@ def run(self):
"""
log.info("Starting TPR monitor thread")
while not self.stop_monitor:
timestamp, tilt, pitch, roll, x, y, z = self.update_pitch_roll_single()
try:
timestamp, tilt, pitch, roll, x, y, z = self.update_pitch_roll_single()
except OSError:
if self.errorcount < 10:
log.warning("Ignored error reading TPR sensor")
elif self.errorcount == 10:
log.warning("Ignored error reading TPR sensor - suppressing further warnings")
self.errorcount += 1
time.sleep(self.sleep_interval)
continue

if len(self.buffer_time)<10:
self.buffer_time.append(timestamp)
self.buffer_tilt.append(tilt)
Expand All @@ -142,14 +158,14 @@ def run(self):
else:
# housekeeping, purge old entries from buffer
time_cutoff = datetime.datetime.now() - datetime.timedelta(seconds=self.sampling_time)

current_keep = argwhere(array(self.buffer_time) >= time_cutoff)
current_keep = array([k[0] for k in current_keep]) # flatten, not sure why this is needed

self.buffer_time = list(array(self.buffer_time)[current_keep])
self.buffer_tilt = list(array(self.buffer_tilt)[current_keep])
self.buffer_pitch = list(array(self.buffer_pitch)[current_keep])
self.buffer_roll = list(array(self.buffer_roll)[current_keep])

self.buffer_time.append(timestamp)
self.buffer_tilt.append(tilt)
self.buffer_pitch.append(pitch)
Expand Down

0 comments on commit f488337

Please sign in to comment.