-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relative Motion #214
Draft
Mark2000
wants to merge
22
commits into
develop
Choose a base branch
from
feature/144-relative-motion
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Relative Motion #214
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5b436f7
Issue #66: Rewarder composition
Mark2000 1800813
Issue #144: Relative motion utilities
Mark2000 cc7cdf5
Issue #144: Conjunction checking
Mark2000 4c63ad0
Issue #144: Continuous actions
Mark2000 ff38b57
Issue #144: TEMP ipynb example
Mark2000 e6e0578
Issue #144: Relative observation with TODO
Mark2000 bf83650
FSW and dynamics w.i.p.
Mark2000 4ff9df9
Issue #144: Body-fixed point mapping
Mark2000 55637d6
Delta V tracking
Mark2000 cfa990d
Issue #144: Fuel use penalty
Mark2000 d861f97
Issue #144: Rewards for RSO inspection
Mark2000 f686acf
Issue #144: Update composed reward
Mark2000 ba869b9
Issue #144: Relative motion tweaks
Mark2000 49762c9
Issue #0: Nan checking wrapper
Mark2000 b79d239
Issue #144: configurable max coast duration
Mark2000 e1ca657
Issue #144: Completion bonus
Mark2000 e198544
Issue #4: Enable Vizard
Mark2000 04101bf
Issue #4: Vizard documentation.
Mark2000 aec6665
Issue #0: Fix sat_arg overrides for matrices
Mark2000 482ecd9
Bugfixes and vizard
Mark2000 dd39583
Fixes to data composition
Mark2000 201219a
Support for lighting conditions
Mark2000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
"""Continuous actions set satellite behavior based on some continuous value.""" | ||
|
||
import logging | ||
from abc import abstractmethod | ||
from typing import TYPE_CHECKING, Optional | ||
|
||
import numpy as np | ||
from gymnasium import spaces | ||
|
||
from bsk_rl.act.actions import Action, ActionBuilder | ||
|
||
if TYPE_CHECKING: # pragma: no cover | ||
from bsk_rl.sats import Satellite | ||
from bsk_rl.scene.targets import Target | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ContinuousActionBuilder(ActionBuilder): | ||
def __init__(self, satellite: "Satellite") -> None: | ||
"""Processes actions for a continuous action space. | ||
|
||
Args: | ||
satellite: Satellite to create actions for. | ||
""" | ||
self.action_spec: list[ContinuousAction] | ||
super().__init__(satellite) | ||
assert len(self.action_spec) == 1, "Only one continuous action is supported." | ||
|
||
@property | ||
def _action(self) -> "ContinuousAction": | ||
return self.action_spec[0] | ||
|
||
@property | ||
def action_space(self) -> spaces.Box: | ||
"""Continuous action space.""" | ||
return self._action.space | ||
|
||
@property | ||
def action_description(self) -> list[str]: | ||
"""Return a human-readable description of the continuous action space.""" | ||
return self._action.action_description() | ||
|
||
def set_action(self, action: np.ndarray) -> None: | ||
"""Activate the action by setting the continuous value.""" | ||
self._action.set_action(action) | ||
|
||
|
||
class ContinuousAction(Action): | ||
builder_type = ContinuousActionBuilder | ||
|
||
def __init__(self, name: str = "discrete_act") -> None: | ||
"""Base class for discrete, integer-indexable actions. | ||
|
||
Args: | ||
name: Name of the action. | ||
""" | ||
super().__init__(name=name) | ||
|
||
@property | ||
@abstractmethod | ||
def space(self) -> spaces.Box: | ||
"""Return the action space.""" | ||
pass | ||
|
||
@property | ||
@abstractmethod | ||
def action_description(self) -> list[str]: | ||
"""Return a description of the action space.""" | ||
pass | ||
|
||
@abstractmethod | ||
def set_action(self, action: np.ndarray) -> None: | ||
"""Activate an action by a continuous value.""" | ||
pass | ||
|
||
|
||
class MagicThrust(ContinuousAction): | ||
# TODO set the fsw mode to carry out after action | ||
def __init__( | ||
self, | ||
name: str = "thrust_act", | ||
max_dv: float = float("inf"), | ||
max_duration: float = float("inf"), | ||
fsw_action: Optional[str] = None, | ||
) -> None: | ||
"""Instantaneously change the satellite's velocity, and drift for some duration. | ||
|
||
TODO: Support specifying frame of thrust. | ||
|
||
Args: | ||
name: Name of the action. | ||
max_dv: Maximum delta-V that can be applied. [m/s] | ||
""" | ||
super().__init__(name) | ||
self.max_dv = max_dv | ||
self.max_duration = max_duration | ||
self.fsw_action = fsw_action | ||
|
||
@property | ||
def space(self) -> spaces.Box: | ||
"""Return the action space.""" | ||
return spaces.Box( | ||
low=np.array( | ||
[-self.max_dv, -self.max_dv, -self.max_dv, self.simulator.sim_rate] | ||
), | ||
high=np.array([self.max_dv, self.max_dv, self.max_dv, self.max_duration]), | ||
shape=(4,), | ||
dtype=np.float32, | ||
) | ||
|
||
@property | ||
def action_description(self) -> list[str]: | ||
"""Description of the continuous action space.""" | ||
return ["dV_N_x", "dV_N_y", "dV_N_z", "duration"] | ||
|
||
def set_action(self, action: np.ndarray) -> None: | ||
"""Thrust the satellite with a given inertial delta-V and drift for some duration.""" | ||
assert len(action) == 4, "Action must have 4 elements." | ||
dv_N = action[0:3] | ||
dt = action[3] | ||
|
||
self.satellite.log_info( | ||
f"Thrusting with inertial dV {dv_N} with {dt} second drift." | ||
) | ||
self.satellite.fsw.action_magic_thrust(dv_N) | ||
self.satellite.update_timed_terminal_event( | ||
self.satellite.simulator.sim_time + dt | ||
) | ||
|
||
# Activate the FSW action for the drift period | ||
getattr(self.satellite.fsw, self.fsw_action)() | ||
self.satellite.log_info(f"FSW action {self.fsw_action} activated.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the hardcoded '5700.0' specify here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened a new issue to track this, since we use hardcoded 5700 as a normalization factor (approx. 1 orbit) in various places. #225