Skip to content
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

Set position only once #53

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions paseos/actors/actor_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ def __new__(self):
def __init__(self):
logger.trace("Initializing ActorBuilder")

def get_actor_scaffold(name: str, actor_type: object, position, epoch: pk.epoch):
def get_actor_scaffold(name: str, actor_type: object, epoch: pk.epoch):
"""Initiates an actor with minimal properties.

Args:
name (str): Name of the actor.
actor_type (object): Type of the actor (e.g. SpacecraftActor)
position (list of floats): Starting position of the actor [x,y,z]
epoch (pykep.epoch): Epoch at this position
epoch (pykep.epoch): Current local time of the actor.

Returns:
Created actor
Expand All @@ -43,7 +42,7 @@ def get_actor_scaffold(name: str, actor_type: object, position, epoch: pk.epoch)

logger.trace(f"Creating an actor blueprint with name {name}")

return actor_type(name, position, epoch)
return actor_type(name, epoch)

def set_orbit(
actor: BaseActor,
Expand Down Expand Up @@ -77,6 +76,20 @@ def set_orbit(

logger.debug(f"Added orbit to actor {actor}")

def set_position(actor: BaseActor, position: list):
johanos1 marked this conversation as resolved.
Show resolved Hide resolved
"""Sets the actors position. Use this if you do not want the actor to have a keplerian orbit around a central body.

Args:
actor (BaseActor): Actor set the position on.
position (list): [x,y,z] position.
"""
assert len(position) == 3, "Position has to be list of 3 floats."
assert all(
[isinstance(val, float) for val in position]
), "Position has to be list of 3 floats."
actor._position = position
logger.debug(f"Setting position {position} on actor {actor}")

def set_power_devices(
actor: SpacecraftActor,
battery_level_in_Ws: float,
Expand Down
35 changes: 32 additions & 3 deletions paseos/actors/base_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ class BaseActor(ABC):
# Communication links dictionary
_communication_devices = DotMap(_dynamic=False)

def __init__(self, name: str, position, epoch: pk.epoch) -> None:
def __init__(self, name: str, epoch: pk.epoch) -> None:
"""Constructor for a base actor

Args:
name (str): Name of this actor
position (list of floats): [x,y,z]
epoch (pykep.epoch): Epoch at this pos / velocity
epoch (pykep.epoch): Current local time of the actor.
"""
logger.trace("Instantiating Actor.")
super().__init__()
Expand Down Expand Up @@ -114,7 +113,37 @@ def discharge(self, consumption_rate_in_W: float, duration_in_s: float):
"""
pass

def get_position(self, epoch: pk.epoch):
logger.trace(
"Computing "
+ self._orbital_parameters.name
+ " position at time "
+ str(epoch.mjd2000)
+ " (mjd2000)."
)

if self._orbital_parameters is not None and self._position is not None:
raise ValueError(
"Ambiguous position definition. Either set an orbit OR position with ActorBuilder."
)

# If the actor has no orbit, return position
if self._orbital_parameters is None:
if self._position is not None:
return self._position
else:
return self._orbital_parameters.eph(epoch)

raise NotImplementedError(
"No suitable way added to determine actor position. Either set an orbit or position with ActorBuilder."
)

def get_position_velocity(self, epoch: pk.epoch):
if self._orbital_parameters is None:
raise NotImplementedError(
"No suitable way added to determine actor velocity. Set an orbit with ActorBuilder."
)

logger.trace(
"Computing "
+ self._orbital_parameters.name
Expand Down
5 changes: 2 additions & 3 deletions paseos/actors/ground_station_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
class GroundstationActor(BaseActor):
"""This class models a groundstation actor."""

def __init__(self, name: str, position, epoch: pk.epoch) -> None:
def __init__(self, name: str, epoch: pk.epoch) -> None:
"""Constructor for a groundstation actor.

Args:
name (str): Name of this actor
position (list of floats): [x,y,z]
epoch (pykep.epoch): Epoch at this pos / velocity
"""
logger.trace("Instantiating GroundstationActor.")
super().__init__(name, position, epoch)
super().__init__(name, epoch)
4 changes: 1 addition & 3 deletions paseos/actors/spacecraft_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ class SpacecraftActor(BaseActor):
def __init__(
self,
name: str,
position,
epoch: pk.epoch,
) -> None:
"""Constructor for a spacecraft actor

Args:
name (str): Name of this actor
position (list of floats): [x,y,z]
epoch (pykep.epoch): Epoch at this pos
"""
logger.trace("Instantiating SpacecraftActor.")
super().__init__(name, position, epoch)
super().__init__(name, epoch)

@property
def charging_rate_in_W(self):
Expand Down
2 changes: 1 addition & 1 deletion paseos/tests/activity_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

def test_activity():
"""Test if performing activity consumes power as expected"""
sim, sat1, earth = get_default_instance()
sim, sat1, _ = get_default_instance()

# Initial power is 500
assert sat1.battery_level_in_Ws == 500
Expand Down
8 changes: 2 additions & 6 deletions paseos/tests/check_communication_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ def test_communication_link():
# create satellites where sat1 and sat2 starts from the same point but move along different orbit.
# At t=1470s they will not be in line of sight anymore.
earth = pk.planet.jpl_lp("earth")
sat1 = ActorBuilder.get_actor_scaffold(
"sat1", SpacecraftActor, [0, 0, 0], pk.epoch(0)
)
sat2 = ActorBuilder.get_actor_scaffold(
"sat2", SpacecraftActor, [0, 0, 0], pk.epoch(0)
)
sat1 = ActorBuilder.get_actor_scaffold("sat1", SpacecraftActor, pk.epoch(0))
sat2 = ActorBuilder.get_actor_scaffold("sat2", SpacecraftActor, pk.epoch(0))

ActorBuilder.set_orbit(
sat1,
Expand Down
2 changes: 1 addition & 1 deletion paseos/tests/eclipse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def test_eclipse():
"""Get the default satellite and see if is in eclipse and getting out of it"""
sim, sat1, earth = get_default_instance()
_, sat1, earth = get_default_instance()

assert not is_in_eclipse(sat1, earth, pk.epoch(0), plot=True)
assert is_in_eclipse(sat1, earth, pk.epoch(0.5), plot=True)
Expand Down
4 changes: 2 additions & 2 deletions paseos/tests/init_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@


def test_init():
sim, sat1, earth = get_default_instance() # noqa
cfg = sim.get_cfg() # noqa
sim, _, _ = get_default_instance() # noqa
_ = sim.get_cfg() # noqa


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions paseos/tests/line_of_sight_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
def test_los():
"""create satellites where sat1 and 2 are in sight of each other (as well as sat 1 and 3)
but sat 2 and 3 are on opposite sides of the planet"""
sim, sat1, earth = get_default_instance()
_, sat1, earth = get_default_instance()

sat2 = ActorBuilder.get_actor_scaffold(
"sat2", SpacecraftActor, [10000000, 0, 0], pk.epoch(0)
"sat2", SpacecraftActor, pk.epoch(0)
)
ActorBuilder.set_orbit(sat2, [0, 10000000, 0], [0, 0, 8000.0], pk.epoch(0), earth)

sat3 = ActorBuilder.get_actor_scaffold(
"sat3", SpacecraftActor, [10000000, 0, 0], pk.epoch(0)
"sat3", SpacecraftActor, pk.epoch(0)
)
ActorBuilder.set_orbit(sat3, [0, -10000000, 0], [0, 0, -8000.0], pk.epoch(0), earth)

Expand Down
4 changes: 1 addition & 3 deletions paseos/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ def get_default_instance() -> (paseos.PASEOS, SpacecraftActor, pk.planet):
earth = pk.planet.jpl_lp("earth")

# Define local actor
sat1 = ActorBuilder.get_actor_scaffold(
"sat1", SpacecraftActor, [10000000, 0, 0], pk.epoch(0)
)
sat1 = ActorBuilder.get_actor_scaffold("sat1", SpacecraftActor, pk.epoch(0))
ActorBuilder.set_orbit(sat1, [10000000, 0, 0], [0, 8000.0, 0], pk.epoch(0), earth)
ActorBuilder.set_power_devices(sat1, 500, 10000, 1)
# init simulation
Expand Down
4 changes: 1 addition & 3 deletions paseos/tests/visualization_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ def test_animation():
"""Simple test to verify that the animation executes without errors."""
sim, sat1, earth = get_default_instance()

sat2 = ActorBuilder.get_actor_scaffold(
"sat2", SpacecraftActor, [10000000, 0, 0], pk.epoch(0)
)
sat2 = ActorBuilder.get_actor_scaffold("sat2", SpacecraftActor, pk.epoch(0))
ActorBuilder.set_orbit(sat2, [0, 10000000, 0], [0, 0, 8000.0], pk.epoch(0), earth)
ActorBuilder.set_power_devices(sat2, 5000, 10000, 1)
sim.add_known_actor(sat2)
Expand Down