Skip to content

Commit

Permalink
feat: add update_target binding to EventCondition (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwa2710 authored Oct 31, 2024
1 parent 503eae8 commit 7e082b3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_EventCondition(pybind11::module& aMo
R"doc(
The value of the target.
:type: Real
:type: float
)doc"
)
.def_readonly(
Expand All @@ -153,6 +153,15 @@ inline void OpenSpaceToolkitAstrodynamicsPy_EventCondition(pybind11::module& aMo
:type: Type
)doc"
)
.def_readonly(
"value_offset",
&EventCondition::Target::valueOffset,
R"doc(
The value offset of the target. Used for Relative targets.
:type: float
)doc"
)

.def("__eq__", &EventCondition::Target::operator==)
.def("__ne__", &EventCondition::Target::operator!=)
Expand Down Expand Up @@ -233,6 +242,18 @@ inline void OpenSpaceToolkitAstrodynamicsPy_EventCondition(pybind11::module& aMo
)doc"
)

.def(
"update_target",
&EventCondition::updateTarget,
R"doc(
Update the target value if the event condition is relative.
Args:
state (State): The state to calculate the relative target from.
)doc",
arg("state")
)

.def(
"is_satisfied",
&EventCondition::isSatisfied,
Expand Down
23 changes: 21 additions & 2 deletions bindings/python/test/test_event_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import pytest

from ostk.physics.time import Instant
from ostk.physics.coordinate import Position, Velocity, Frame

from ostk.astrodynamics.trajectory import State
from ostk.astrodynamics import EventCondition


Expand All @@ -12,7 +16,7 @@ def name() -> str:

@pytest.fixture
def evaluator() -> callable:
return lambda state: 0.0
return lambda state: 5.0


@pytest.fixture
Expand All @@ -22,7 +26,7 @@ def target_value() -> float:

@pytest.fixture
def target(target_value: float) -> EventCondition.Target:
return EventCondition.Target(target_value, EventCondition.Target.Type.Absolute)
return EventCondition.Target(target_value, EventCondition.Target.Type.Relative)


@pytest.fixture
Expand Down Expand Up @@ -56,3 +60,18 @@ def test_get_target(
self, event_condition: EventCondition, target: EventCondition.Target
):
assert event_condition.get_target() == target

def test_update_target(
self,
event_condition: EventCondition,
):
current_target_value_offset: float = event_condition.get_target().value_offset
event_condition.update_target(
State(
Instant.J2000(),
Position.meters([0.0, 0.0, 0.0], Frame.GCRF()),
Velocity.meters_per_second([0.0, 0.0, 0.0], Frame.GCRF()),
)
)

assert event_condition.get_target().value_offset != current_target_value_offset

0 comments on commit 7e082b3

Please sign in to comment.