diff --git a/socs/agents/acu/avoidance.py b/socs/agents/acu/avoidance.py index 55144decb..0d171c1f2 100644 --- a/socs/agents/acu/avoidance.py +++ b/socs/agents/acu/avoidance.py @@ -635,36 +635,3 @@ def get_traj(self, res=0.5): xx.append(np.linspace(x0, x1, n)) yy.append(np.linspace(y0, y1, n)) return np.hstack(tuple(xx)), np.hstack(tuple(yy)) - - -class RollingMinimum: - def __init__(self, window, fallback=None): - self.window = window - self.subwindow = window / 10 - self.fallback = fallback - self.records = [] - - def append(self, val, t=None): - if t is None: - t = time.time() - # Remove old data - while len(self.records) and (t - self.records[0][0]) > self.window: - self.records.pop(0) - # Add this to existing subwindow? - if len(self.records): - # Consider values up to subwindow ago. - _t, _val = self.records[-1] - if t - _t < self.subwindow: - if val <= _val: - self.records[-1] = (t, val) - return - # Or start a new subwindow. - self.records.append((t, val)) - - def get(self, lookback=None): - if lookback is None: - lookback = self.window - recs = [v for t, v in self.records if (time.time() - t < lookback)] - if len(recs): - return min(recs) - return self.fallback diff --git a/tests/agents/test_acu_agent.py b/tests/agents/test_acu_agent.py index 921fe550c..9afa6f280 100644 --- a/tests/agents/test_acu_agent.py +++ b/tests/agents/test_acu_agent.py @@ -1 +1,37 @@ +from socs.agents.acu import avoidance as av from socs.agents.acu.agent import ACUAgent # noqa: F401 + + +def test_avoidance(): + az0, el0 = 72, 67 + t0 = 1698850000 + + sun = av.SunTracker(fake_now=t0) + pos = sun.get_sun_pos() + az, el = pos['sun_azel'] + assert abs(az - az0) < .5 and abs(el - el0) < .5 + + # Zenith should be about 23 deg away. + assert abs(sun.get_sun_pos(0, 90)['sun_dist'] - 23) < 0.5 + + # Unsafe positions. + assert sun.check_trajectory([90], [60])['sun_time'] == 0 + + # Safe positions + assert sun.check_trajectory([90], [20])['sun_time'] > 0 + assert sun.check_trajectory([270], [60])['sun_time'] > 0 + + # No safe moves to Sun position. + paths = sun.analyze_paths(180, 20, az0, el0) + path, analysis = sun.select_move(paths) + assert path is None + + # Escape paths. + path = sun.find_escape_paths(az0, el0 - 5) + assert path is not None + path = sun.find_escape_paths(az0, el0 + 5) + assert path is not None + path = sun.find_escape_paths(az0 - 10, el0) + assert path is not None + path = sun.find_escape_paths(az0 + 10, el0) + assert path is not None