Skip to content

Commit

Permalink
Issue #191: Improve eclipse observation performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark2000 committed Sep 23, 2024
1 parent 398630d commit 011f851
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/bsk_rl/utils/orbital.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,13 @@ def _init_simulator(self) -> None:
].recorder()
self.eclipse_log = self.eclipseObject.eclipseOutMsgs[0].recorder()

self._time_log = []
self.AddModelToTask(simTaskName, self.sc_state_log)
self._r_BN_N_log = []
self.AddModelToTask(simTaskName, self.planet_state_log)
self._J20002Pfix_log = []
self.AddModelToTask(simTaskName, self.eclipse_log)
self._shadowFactor_log = []

self.InitializeSimulation()

Expand All @@ -351,7 +355,7 @@ def sim_time(self) -> float:
@property
def times(self) -> np.ndarray:
"""Recorder times in seconds."""
return np.array([macros.NANO2SEC * t for t in self.sc_state_log.times()])
return macros.NANO2SEC * np.array(self._time_log)

def extend_to(self, t: float) -> None:
"""Compute the trajectory of the satellite up to t.
Expand All @@ -363,12 +367,19 @@ def extend_to(self, t: float) -> None:
return
self.ConfigureStopTime(macros.sec2nano(t))
self.ExecuteSimulation()
self._time_log.extend(self.sc_state_log.times())
self._r_BN_N_log.extend(self.sc_state_log.r_BN_N)
self._J20002Pfix_log.extend(self.planet_state_log.J20002Pfix)
self._shadowFactor_log.extend(self.eclipse_log.shadowFactor)
self.sc_state_log.clear()
self.planet_state_log.clear()
self.eclipse_log.clear()

def _generate_eclipses(self, t: float) -> None:
self.extend_to(t + self.dt)
upcoming_times = self.times[self.times > self._eclipse_search_time]
upcoming_eclipse = (
self.eclipse_log.shadowFactor[self.times > self._eclipse_search_time] > 0
np.array(self._shadowFactor_log)[self.times > self._eclipse_search_time] > 0
).astype(float)
for i in np.where(np.diff(upcoming_eclipse) == -1)[0]:
self._eclipse_starts.append(upcoming_times[i])
Expand Down Expand Up @@ -412,7 +423,7 @@ def r_BN_N(self) -> interp1d:
self.extend_to(self.dt * 3)
return interp1d(
self.times,
self.sc_state_log.r_BN_N,
self._r_BN_N_log,
kind="cubic",
axis=0,
fill_value="extrapolate",
Expand All @@ -427,9 +438,7 @@ def r_BP_P(self) -> interp1d:
self.times,
[
np.matmul(dcm, pos)
for dcm, pos in zip(
self.planet_state_log.J20002Pfix, self.sc_state_log.r_BN_N
)
for dcm, pos in zip(self._J20002Pfix_log, self._r_BN_N_log)
],
kind="cubic",
axis=0,
Expand Down

0 comments on commit 011f851

Please sign in to comment.