Skip to content

Commit

Permalink
Issue #144: Body-fixed point mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark2000 committed Dec 12, 2024
1 parent 4ef3ca4 commit d16821d
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 249 deletions.
294 changes: 61 additions & 233 deletions examples/continuous_orbit_manuevers.ipynb

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions src/bsk_rl/data/rso_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def get_log_state(self) -> list[list[bool]]:

inspected_logs = []
for recorder in self.point_access_recorders:
# inspected = np.logical_and(imaging_req, recorder.hasAccess)
inspected = recorder.hasAccess
inspected_logs.append(list(inspected))
inspected = np.logical_and(imaging_req, recorder.hasAccess)
# inspected = recorder.hasAccess
inspected_logs.append(list(np.array(inspected)))

self.clear_recorders()

Expand All @@ -103,7 +103,6 @@ def compare_log_states(self, _, inspected_logs) -> Data:
self.data.point_inspect_status.keys(), inspected_logs
):
if any(log):
print(log)
point_inspect_status[rso_point] = True

if len(point_inspect_status) > 0:
Expand Down
6 changes: 6 additions & 0 deletions src/bsk_rl/gym.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ def reset(
time_limit=self.time_limit,
)

self.scenario.reset_during_sim_init()
self.rewarder.reset_during_sim_init()
self.communicator.reset_during_sim_init()

self.simulator.finish_init()

self.scenario.reset_post_sim_init()
self.rewarder.reset_post_sim_init()
self.communicator.reset_post_sim_init()
Expand Down
11 changes: 5 additions & 6 deletions src/bsk_rl/scene/rso_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

import numpy as np
import pandas as pd
from Basilisk.utilities import orbitalMotion

from bsk_rl.scene import Scenario
from bsk_rl.sim.dyn import RSODynModel, RSOImagingDynModel
from bsk_rl.sim.fsw import RSOImagingFSWModel
from bsk_rl.utils.orbital import lla2ecef

if TYPE_CHECKING: # pragma: no cover
from bsk_rl.data.base import Data
Expand Down Expand Up @@ -40,11 +38,9 @@ def reset_overwrite_previous(self) -> None:

def reset_pre_sim_init(self) -> None:
self.rso_points = self.generate_points()
return super().reset_pre_sim_init()

def reset_post_sim_init(self) -> None:
# Check for RSOs and observers
rsos = [sat for sat in self.satellites if isinstance(sat.dynamics, RSODynModel)]
rsos = [sat for sat in self.satellites if issubclass(sat.dyn_type, RSODynModel)]
if len(rsos) == 0:
logger.warning("No RSODynModel satellites found in scenario.")
return
Expand All @@ -54,12 +50,15 @@ def reset_post_sim_init(self) -> None:
self.observers = [
sat
for sat in self.satellites
if isinstance(sat.dynamics, RSOImagingDynModel)
if issubclass(sat.dyn_type, RSOImagingDynModel)
]
if len(self.observers) == 0:
logger.warning("No RSOImagingDynModel satellites found in scenario.")
return

return super().reset_pre_sim_init()

def reset_during_sim_init(self) -> None:
# Add points to dynamics and fsw of RSO
assert isinstance(self.rso.dynamics, RSODynModel)
logger.debug("Adding inspection points to RSO and observers")
Expand Down
22 changes: 16 additions & 6 deletions src/bsk_rl/sim/dyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,22 +1252,32 @@ def __init__(self, *args, **kwargs) -> None:

def _setup_dynamics_objects(self, **kwargs) -> None:
super()._setup_dynamics_objects(**kwargs)

rso_dyn_proc_name = "RSODynProcess"
self.rso_dyn_proc = self.simulator.CreateNewProcess(rso_dyn_proc_name, 1)
self.rso_task_name = "RSODynTask"
self.rso_dyn_proc.addTask(
self.simulator.CreateNewTask(
self.rso_task_name, macros.sec2nano(self.dyn_rate)
)
)

self.rso_points = []

def add_rso_point(self, r_LB_B, aHat_B, theta, range):
rso_point_model = spacecraftLocation.SpacecraftLocation()
rso_point_model.primaryScStateInMsg.subscribeTo(self.scObject.scStateOutMsg)
rso_point_model.planetInMsg.subscribeTo(
self.world.gravFactory.spiceObject.planetStateOutMsgs[self.world.body_index]
)
rso_point_model.rEquator = self.simulator.world.planet.radEquator
rso_point_model.rPolar = self.simulator.world.planet.radEquator * 0.98
# rso_point_model.planetInMsg.subscribeTo(
# self.world.gravFactory.spiceObject.planetStateOutMsgs[self.world.body_index]
# )
rso_point_model.rEquator = 1.0 # self.simulator.world.planet.radEquator
rso_point_model.rPolar = 1.0 # self.simulator.world.planet.radEquator * 0.98
rso_point_model.r_LB_B = r_LB_B
rso_point_model.aHat_B = aHat_B
rso_point_model.theta = theta
rso_point_model.maximumRange = range
self.simulator.AddModelToTask(
self.task_name, rso_point_model, ModelPriority=2000
self.rso_task_name, rso_point_model, ModelPriority=1
)

self.rso_points.append(rso_point_model)
Expand Down
2 changes: 2 additions & 0 deletions src/bsk_rl/sim/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def __init__(
self.dynamics_list[satellite.name] = satellite.set_dynamics(self.sim_rate)
self.fsw_list[satellite.name] = satellite.set_fsw(self.sim_rate)

def finish_init(self) -> None:
"""Finish simulator initialization."""
self.InitializeSimulation()
self.ConfigureStopTime(0)
self.ExecuteSimulation()
Expand Down
4 changes: 4 additions & 0 deletions src/bsk_rl/utils/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ def reset_pre_sim_init(self) -> None:
"""Reset before simulator initialization."""
pass

def reset_during_sim_init(self) -> None:
"""Reset after simulator models have been created but before the simulator is initialized."""
pass

def reset_post_sim_init(self) -> None:
"""Reset after simulator initialization."""
pass
Expand Down

0 comments on commit d16821d

Please sign in to comment.