Skip to content

Commit

Permalink
feat: event condition relative target (#263)
Browse files Browse the repository at this point in the history
* feat: add relative target for event conditions

* feat: update tests

* feat: add duration condition

* feat: use a relativeTarget_ so as to not update the target_ field ever

* Apply suggestions from code review

Co-authored-by: kyle-cochran <kyle.ray.cochran@gmail.com>

* feat: use a Target object

* style: format

* fix: tests

* Apply suggestions from code review

Co-authored-by: kyle-cochran <kyle.ray.cochran@gmail.com>

* feat: address remaining feedback

* chore: format

---------

Co-authored-by: kyle-cochran <kyle.ray.cochran@gmail.com>
Co-authored-by: Vishwa Shah <vishwa@loftorbital.com>
  • Loading branch information
3 people authored Nov 2, 2023
1 parent 62ba2dc commit 92babf0
Show file tree
Hide file tree
Showing 30 changed files with 980 additions and 207 deletions.
172 changes: 170 additions & 2 deletions bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/EventCondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ using ostk::core::types::Shared;

using ostk::math::obj::VectorXd;

using ostk::physics::units::Length;
using ostk::physics::units::Angle;

using ostk::astro::EventCondition;
using ostk::astro::trajectory::State;

Expand All @@ -37,6 +40,127 @@ class PyEventCondition : public EventCondition
inline void OpenSpaceToolkitAstrodynamicsPy_EventCondition(pybind11::module& aModule)
{
{
class_<EventCondition::Target> eventConditionTarget_class(
aModule,
"EventConditionTarget",
R"doc(
The Event Condition Target.
Group:
event-condition
)doc"
);

enum_<EventCondition::Target::Type>(
eventConditionTarget_class,
"Type",
R"doc(
Event Condition Target type.
)doc"
)

.value("Absolute", EventCondition::Target::Type::Absolute, "Absolute")
.value(
"RelativeSegmentStart",
EventCondition::Target::Type::RelativeSegmentStart,
"Relative to the State at the start of the current Segment."
)
.value(
"RelativeSequenceStart",
EventCondition::Target::Type::RelativeSequenceStart,
"Relative to the State at the start of the Sequence."
)

;

eventConditionTarget_class

.def(
init<const Real&, const EventCondition::Target::Type&>(),
R"doc(
Construct a new `EventConditionTarget` object.
Args:
value (float): The value of the target.
type (EventConditionTarget.Type): The type of the target. Defaults to EventConditionTarget.Type.Absolute.
Returns:
event_condition_target (EventConditionTarget): The new `EventConditionTarget` object.
)doc",
arg("value"),
arg("type") = EventCondition::Target::Type::Absolute
)

.def(
init<const Length&, const EventCondition::Target::Type&>(),
R"doc(
Construct a new `EventConditionTarget` object.
Args:
length (Length): The value of the target as a `Length`.
type (EventConditionTarget.Type): The type of the target. Defaults to EventConditionTarget.Type.Absolute.
Returns:
event_condition_target (EventConditionTarget): The new `EventConditionTarget` object.
)doc",
arg("value"),
arg("type") = EventCondition::Target::Type::Absolute
)

.def(
init<const Angle&, const EventCondition::Target::Type&>(),
R"doc(
Construct a new `EventConditionTarget` object.
Args:
angle (Angle): The value of the target as an `Angle`.
type (EventConditionTarget.Type): The type of the target. Defaults to EventConditionTarget.Type.Absolute.
Returns:
event_condition_target (EventConditionTarget): The new `EventConditionTarget` object.
)doc",
arg("value"),
arg("type") = EventCondition::Target::Type::Absolute
)

.def_static(
"StringFromType",
&EventCondition::Target::StringFromType,
R"doc(
Enum as a string
Args:
type (EventConditionTarget.Type): The type of the target.
Returns:
string (str): Name of the enum as a string.
)doc"
)

.def_readonly(
"value",
&EventCondition::Target::value,
R"doc(
The value of the target.
:type: Real
)doc"
)
.def_readonly(
"type",
&EventCondition::Target::type,
R"doc(
The type of the target.
:type: Type
)doc"
)

.def("__eq__", &EventCondition::Target::operator==)
.def("__ne__", &EventCondition::Target::operator!=)

;

class_<EventCondition, PyEventCondition, Shared<EventCondition>> eventCondition_class(
aModule,
"EventCondition",
Expand All @@ -51,17 +175,39 @@ inline void OpenSpaceToolkitAstrodynamicsPy_EventCondition(pybind11::module& aMo
eventCondition_class

.def(
init<const String&>(),
init<const String&, const std::function<Real(const State&)>&, const EventCondition::Target&>(),
R"doc(
Construct a new `EventCondition` object.
Args:
name (str): The name of the event condition.
evaluator (callable): The evaluator that accepts a `State` and returns a float value.
target (EventConditionTarget): The target of the event condition.
Returns:
event_condition (EventCondition): The new `EventCondition` object.
)doc",
arg("name"),
arg("evaluator"),
arg("target")
)

.def(
init<const String&, const std::function<Real(const State&)>&, const Real&>(),
R"doc(
Construct a new `EventCondition` object.
Args:
name (str): The name of the event condition.
evaluator (callable): The evaluator that accepts a `State` and returns a float value.
target_value (float): The target of the event condition.
Returns:
event_condition (EventCondition): The new `EventCondition` object.
)doc"
)doc",
arg("name"),
arg("evaluator"),
arg("target_value")
)

.def("__str__", &(shiftToString<EventCondition>))
Expand All @@ -78,6 +224,28 @@ inline void OpenSpaceToolkitAstrodynamicsPy_EventCondition(pybind11::module& aMo
)doc"
)

.def(
"get_evaluator",
&EventCondition::getEvaluator,
R"doc(
Get the evaluator of the event condition.
Returns:
evaluator (str): The evaluator of the event condition.
)doc"
)

.def(
"get_target",
&EventCondition::getTarget,
R"doc(
Get the target of the event condition.
Returns:
target (EventConditionTarget): The target of the event condition.
)doc"
)

.def(
"is_satisfied",
&EventCondition::isSatisfied,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ inline void OpenSpaceToolkitAstrodynamicsPy_EventCondition_AngularCondition(pybi
arg("target_angle")
)

.def(
init<
const String&,
const AngularCondition::Criterion&,
std::function<Real(const State&)>,
const EventCondition::Target&>(),
R"doc(
Constructor.
Args:
name (str): The name of the condition.
criterion (ostk.astrodynamics.event_condition.AngularCondition.Criterion): The criterion of the condition.
evaluator (function): The evaluator of the condition.
target (EventConditionTarget): The target of the condition.
)doc",
arg("name"),
arg("criterion"),
arg("evaluator"),
arg("target")
)

.def("__str__", &(shiftToString<AngularCondition>))
.def("__repr__", &(shiftToString<AngularCondition>))

Expand All @@ -87,18 +109,6 @@ inline void OpenSpaceToolkitAstrodynamicsPy_EventCondition_AngularCondition(pybi
)doc"
)

.def(
"get_evaluator",
&AngularCondition::getEvaluator,
R"doc(
Get the evaluator of the condition.
Returns:
function: The evaluator of the condition.
)doc"
)

.def(
"get_target_angle",
&AngularCondition::getTargetAngle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_EventCondition_COECondition(pybind11
Args:
criterion (Criterion): The criterion.
frame (Frame): The reference frame.
semi_major_axis (float): The semi-major axis.
semi_major_axis (EventConditionTarget): The semi-major axis.
gravitational_parameter (float): The gravitational parameter.
Returns:
Expand All @@ -59,7 +59,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_EventCondition_COECondition(pybind11
Args:
criterion (Criterion): The criterion.
frame (Frame): The reference frame.
eccentricity (float): The eccentricity.
eccentricity (EventConditionTarget): The eccentricity.
gravitational_parameter (float): The gravitational parameter.
Returns:
Expand All @@ -80,7 +80,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_EventCondition_COECondition(pybind11
Args:
criterion (Criterion): The criterion.
frame (Frame): The reference frame.
inclination (float): The inclination.
inclination (EventConditionTarget): The inclination.
gravitational_parameter (float): The gravitational parameter.
Returns:
Expand All @@ -101,7 +101,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_EventCondition_COECondition(pybind11
Args:
criterion (Criterion): The criterion.
frame (Frame): The reference frame.
aop (float): The argument of perigee.
aop (EventConditionTarget): The argument of perigee.
gravitational_parameter (float): The gravitational parameter.
Returns:
Expand All @@ -122,7 +122,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_EventCondition_COECondition(pybind11
Args:
criterion (Criterion): The criterion.
frame (Frame): The reference frame.
raan (float): The right ascension of the ascending node.
raan (EventConditionTarget): The right ascension of the ascending node.
gravitational_parameter (float): The gravitational parameter.
Returns:
Expand All @@ -143,7 +143,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_EventCondition_COECondition(pybind11
Args:
criterion (Criterion): The criterion.
frame (Frame): The reference frame.
true_anomaly (float): The true anomaly.
true_anomaly (EventConditionTarget): The true anomaly.
gravitational_parameter (float): The gravitational parameter.
Returns:
Expand All @@ -164,7 +164,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_EventCondition_COECondition(pybind11
Args:
criterion (Criterion): The criterion.
frame (Frame): The reference frame.
mean_anomaly (float): The mean anomaly.
mean_anomaly (EventConditionTarget): The mean anomaly.
gravitational_parameter (float): The gravitational parameter.
Returns:
Expand All @@ -185,7 +185,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_EventCondition_COECondition(pybind11
Args:
criterion (Criterion): The criterion.
frame (Frame): The reference frame.
eccentric_anomaly (float): The eccentric anomaly.
eccentric_anomaly (EventConditionTarget): The eccentric anomaly.
gravitational_parameter (float): The gravitational parameter.
Returns:
Expand Down
Loading

0 comments on commit 92babf0

Please sign in to comment.