Skip to content

Commit

Permalink
feat: add segment solution constructor (#304)
Browse files Browse the repository at this point in the history
* build: support space separated paths in Makefile

* feat: add bindings for segment solution constructor

* test: add test and fix old test

* chore: style
  • Loading branch information
Derollez authored Dec 19, 2023
1 parent 51ffce3 commit 9f02666
Show file tree
Hide file tree
Showing 26 changed files with 262 additions and 169 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ build-packages-python-standalone: ## Build Python packages (standalone)
start-development-no-link: build-development-image-non-root ## Start development environment

@ echo "Starting development environment..."
@ mkdir -p $(CURDIR)/build
@ mkdir -p "$(CURDIR)/build"

docker run \
--name=open-space-toolkit-$(project_name)-dev-non-root \
Expand All @@ -272,7 +272,7 @@ start-development-link: build-development-image ## Start linked development envi

@ echo "Starting development environment (linked)..."

@ mkdir -p $(CURDIR)/build
@ mkdir -p "$(CURDIR)/build"
@ docker_development_image_repository=$(docker_development_image_repository) docker_image_version=$(docker_image_version) "$(CURDIR)/tools/development/start.sh" --link $(links)
@ sudo chown -R $(shell id -u):$(shell id -g) $(CURDIR)

Expand Down
4 changes: 3 additions & 1 deletion bindings/python/docs/Demonstration/Orbit Propagation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@
"source": [
"instant_J2000 = Instant.J2000()\n",
"celestial_objects = [\n",
" Earth.EGM96(360, 360), # Earth.EGM2008(), Earth.WGS84_EGM96(), Earth.EGM84(180, 180)\n",
" Earth.EGM96(\n",
" 360, 360\n",
" ), # Earth.EGM2008(), Earth.WGS84_EGM96(), Earth.EGM84(180, 180)\n",
" Sun.default(),\n",
" Moon.default(),\n",
"]\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Segment(pybind11::module&
)doc"
)

.def(
init<const String&, const Array<Shared<Dynamics>>&, const Array<State>&, const bool&, const Segment::Type&>(
),
arg("name"),
arg("dynamics"),
arg("states"),
arg("condition_is_satisfied"),
arg("segment_type"),
R"doc(
Construct a Segment Solution.
Args:
name (str): The name of the segment.
dynamics (list[Dynamics]): The dynamics.
states (list[State]): The states.
condition_is_satisfied (bool): Whether the event condition is satisfied.
segment_type (Type): The type of the segment.
)doc"
)

.def("__str__", &(shiftToString<Segment::Solution>))
.def("__repr__", &(shiftToString<Segment::Solution>))

Expand Down Expand Up @@ -225,143 +246,141 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Segment(pybind11::module&

;

{
enum_<Segment::Type>(
segment,
"Type",
enum_<Segment::Type>(
segment,
"Type",
R"doc(
Segment type.
)doc"
)

.value("Coast", Segment::Type::Coast, "Coast")
.value("Maneuver", Segment::Type::Maneuver, "Maneuver")

;

segment

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

.def(
"get_name",
&Segment::getName,
R"doc(
Get the name of the segment.
Returns:
str: The name of the segment.
)doc"
)
.def(
"get_event_condition",
&Segment::getEventCondition,
R"doc(
Get the event condition.
Returns:
EventCondition: The event condition.
)doc"
)
.def(
"get_dynamics",
&Segment::getDynamics,
R"doc(
Get the dynamics.
Returns:
Dynamics: The dynamics.
)doc"
)
.def(
"get_numerical_solver",
&Segment::getNumericalSolver,
R"doc(
Get the numerical solver.
Returns:
NumericalSolver: The numerical solver.
)doc"
)
.def(
"get_type",
&Segment::getType,
R"doc(
Segment type.
Get the type of the segment.
Returns:
Type: The type of the segment.
)doc"
)

.value("Coast", Segment::Type::Coast, "Coast")
.value("Maneuver", Segment::Type::Maneuver, "Maneuver")

;

segment

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

.def(
"get_name",
&Segment::getName,
R"doc(
Get the name of the segment.
Returns:
str: The name of the segment.
)doc"
)
.def(
"get_event_condition",
&Segment::getEventCondition,
R"doc(
Get the event condition.
Returns:
EventCondition: The event condition.
)doc"
)
.def(
"get_dynamics",
&Segment::getDynamics,
R"doc(
Get the dynamics.
Returns:
Dynamics: The dynamics.
)doc"
)
.def(
"get_numerical_solver",
&Segment::getNumericalSolver,
R"doc(
Get the numerical solver.
Returns:
NumericalSolver: The numerical solver.
)doc"
)
.def(
"get_type",
&Segment::getType,
R"doc(
Get the type of the segment.
Returns:
Type: The type of the segment.
)doc"
)

.def(
"solve",
&Segment::solve,
arg("state"),
arg("maximum_propagation_duration") = Duration::Days(30.0),
R"doc(
Solve the segment.
Args:
state (State): The state.
maximum_propagation_duration (Duration, optional): The maximum propagation duration.
Returns:
SegmentSolution: The segment solution.
)doc"
)

.def_static(
"coast",
&Segment::Coast,
arg("name"),
arg("event_condition"),
arg("dynamics"),
arg("numerical_solver"),
R"doc(
Create a coast segment.
Args:
name (str): The name of the segment.
event_condition (EventCondition): The event condition.
dynamics (Dynamics): The dynamics.
numerical_solver (NumericalSolver): The numerical solver.
Returns:
Segment: The coast segment.
)doc"
)

.def_static(
"maneuver",
&Segment::Maneuver,
arg("name"),
arg("event_condition"),
arg("thruster_dynamics"),
arg("dynamics"),
arg("numerical_solver"),
R"doc(
Create a maneuver segment.
Args:
name (str): The name of the segment.
event_condition (EventCondition): The event condition.
thruster_dynamics (ThrusterDynamics): The thruster dynamics.
dynamics (Dynamics): The dynamics.
numerical_solver (NumericalSolver): The numerical solver.
Returns:
Segment: The maneuver segment.
)doc"
)

;
}
.def(
"solve",
&Segment::solve,
arg("state"),
arg("maximum_propagation_duration") = Duration::Days(30.0),
R"doc(
Solve the segment.
Args:
state (State): The state.
maximum_propagation_duration (Duration, optional): The maximum propagation duration.
Returns:
SegmentSolution: The segment solution.
)doc"
)

.def_static(
"coast",
&Segment::Coast,
arg("name"),
arg("event_condition"),
arg("dynamics"),
arg("numerical_solver"),
R"doc(
Create a coast segment.
Args:
name (str): The name of the segment.
event_condition (EventCondition): The event condition.
dynamics (Dynamics): The dynamics.
numerical_solver (NumericalSolver): The numerical solver.
Returns:
Segment: The coast segment.
)doc"
)

.def_static(
"maneuver",
&Segment::Maneuver,
arg("name"),
arg("event_condition"),
arg("thruster_dynamics"),
arg("dynamics"),
arg("numerical_solver"),
R"doc(
Create a maneuver segment.
Args:
name (str): The name of the segment.
event_condition (EventCondition): The event condition.
thruster_dynamics (ThrusterDynamics): The thruster dynamics.
dynamics (Dynamics): The dynamics.
numerical_solver (NumericalSolver): The numerical solver.
Returns:
Segment: The maneuver segment.
)doc"
)

;
}
4 changes: 3 additions & 1 deletion bindings/python/test/conjunction/messages/ccsds/test_cdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def cdm() -> CDM:
return CDM(
header=CDM.Header(
ccsds_cdm_version="1.0",
creation_date=Instant.date_time(datetime(2010, 3, 12, 22, 31, 12), Scale.UTC),
creation_date=Instant.date_time(
datetime(2010, 3, 12, 22, 31, 12), Scale.UTC
),
originator="JSPOC",
message_for="SATELLITE A",
message_id="201113719185",
Expand Down
4 changes: 3 additions & 1 deletion bindings/python/test/event_condition/test_coe_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,7 @@ def test_static_constructors(
frame: Frame,
gravitational_parameter: Derived,
):
condition = static_constructor(criterion, frame, target, gravitational_parameter)
condition = static_constructor(
criterion, frame, target, gravitational_parameter
)
assert condition is not None
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ def test_build(self):
assert satellite_system.get_mass() == dry_mass
assert satellite_system.get_geometry() == geometry
assert np.array_equal(satellite_system.get_inertia_tensor(), inertia_tensor)
assert satellite_system.get_cross_sectional_surface_area() == cross_sectional_surface_area
assert (
satellite_system.get_cross_sectional_surface_area()
== cross_sectional_surface_area
)
assert satellite_system.get_drag_coefficient() == drag_coefficient
assert satellite_system.get_propulsion_system() == propulsion_system
4 changes: 3 additions & 1 deletion bindings/python/test/flight/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def test_undefined(self):
assert profile.is_defined() is False

def test_inertial_pointing(self):
quaternion: Quaternion = Quaternion([0.0, 0.0, 0.0, 1.0], Quaternion.Format.XYZS)
quaternion: Quaternion = Quaternion(
[0.0, 0.0, 0.0, 1.0], Quaternion.Format.XYZS
)

trajectory: Trajectory = Trajectory.position(
Position.meters((0.0, 0.0, 0.0), Frame.GCRF())
Expand Down
4 changes: 3 additions & 1 deletion bindings/python/test/guidance_law/test_constant_thrust.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,6 @@ def test_compute_acceleration_success(
)

assert len(contribution) == 3
assert contribution == pytest.approx([0.0, 0.009523809523809525, 0.0], abs=5e-11)
assert contribution == pytest.approx(
[0.0, 0.009523809523809525, 0.0], abs=5e-11
)
3 changes: 2 additions & 1 deletion bindings/python/test/guidance_law/test_qlaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def target_COE() -> COE:
@pytest.fixture
def gravitational_parameter() -> Derived:
return Derived(
3.986004418e14, EarthGravitationalModel.EGM2008.gravitational_parameter.get_unit()
3.986004418e14,
EarthGravitationalModel.EGM2008.gravitational_parameter.get_unit(),
)


Expand Down
Loading

0 comments on commit 9f02666

Please sign in to comment.