Skip to content

Commit

Permalink
feat!: add tabulated profile (#74)
Browse files Browse the repository at this point in the history
* feat: add Orbit::generateFrameName

* refactor: add minor improvements

* chore: improve helpers

* feat!: add Tabulated model support to flight Profile

* fix: apply suggestions

* fix: re-add Profile copy constructor and copy assignment operator

* fix: segfault

* build: update deps

Co-authored-by: Lucas Brémond <lucas@loftorbital.com>
  • Loading branch information
lucas-bremond and lucas-bremond authored Oct 26, 2022
1 parent 5506b5d commit 5a33a87
Show file tree
Hide file tree
Showing 30 changed files with 1,756 additions and 486 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ ELSE ()
MESSAGE (SEND_ERROR "[NLopt] not found.")
ENDIF ()

### Open Space Toolkit ▸ Core [0.2.x]
### Open Space Toolkit ▸ Core

FIND_PACKAGE ("OpenSpaceToolkitCore" "0.2" REQUIRED)

Expand All @@ -280,7 +280,7 @@ IF (NOT OpenSpaceToolkitCore_FOUND)

ENDIF ()

### Open Space Toolkit ▸ I/O [0.2.x]
### Open Space Toolkit ▸ I/O

FIND_PACKAGE ("OpenSpaceToolkitIO" "0.2" REQUIRED)

Expand All @@ -290,7 +290,7 @@ IF (NOT OpenSpaceToolkitIO_FOUND)

ENDIF ()

### Open Space Toolkit ▸ Mathematics [0.2.x]
### Open Space Toolkit ▸ Mathematics

FIND_PACKAGE ("OpenSpaceToolkitMathematics" "0.2" REQUIRED)

Expand All @@ -300,7 +300,7 @@ IF (NOT OpenSpaceToolkitMathematics_FOUND)

ENDIF ()

### Open Space Toolkit ▸ Physics [0.2.x]
### Open Space Toolkit ▸ Physics

FIND_PACKAGE ("OpenSpaceToolkitPhysics" "0.2" REQUIRED)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <OpenSpaceToolkitAstrodynamicsPy/Flight/Profile/Models.cpp>
#include <OpenSpaceToolkitAstrodynamicsPy/Flight/Profile/Model.cpp>
#include <OpenSpaceToolkitAstrodynamicsPy/Flight/Profile/State.cpp>

#include <OpenSpaceToolkit/Astrodynamics/Flight/Profile.hpp>
Expand All @@ -22,19 +24,14 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Flight_Profile (
using ostk::core::ctnr::Array ;

using ostk::physics::coord::Frame ;
using DynamicProvider = ostk::physics::coord::frame::provider::Dynamic ;

using ostk::astro::flight::Profile ;
using ostk::astro::flight::profile::State ;
using ostk::astro::flight::profile::Model ;

class_<Profile>(aModule, "Profile")

.def(init<const DynamicProvider&, const Shared<const Frame>&>())

// .def(init<const Array<State>&>())

// .def(self == self)
// .def(self != self)
.def(init<const Model&>(), arg("model"))

.def("__str__", &(shiftToString<Profile>))
.def("__repr__", &(shiftToString<Profile>))
Expand All @@ -44,6 +41,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Flight_Profile (
.def("get_state_at", &Profile::getStateAt, arg("instant"))
.def("get_states_at", &Profile::getStatesAt, arg("instants"))
.def("get_axes_at", &Profile::getAxesAt, arg("instant"))
.def("get_body_frame", &Profile::getBodyFrame, arg("frame_name"))

.def_static("undefined", &Profile::Undefined)
.def_static("inertial_pointing", &Profile::InertialPointing, arg("trajectory"), arg("quaternion"))
Expand All @@ -59,6 +57,8 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Flight_Profile (

// Add objects to "profile" submodule
OpenSpaceToolkitAstrodynamicsPy_Flight_Profile_State(profile) ;
OpenSpaceToolkitAstrodynamicsPy_Flight_Profile_Model(profile) ;
OpenSpaceToolkitAstrodynamicsPy_Flight_Profile_Models(profile) ;

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/// @project Open Space Toolkit ▸ Astrodynamics
/// @file bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Flight/Profile/Model.cpp
/// @author Lucas Brémond <lucas@loftorbital.com>
/// @license Apache License 2.0

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <OpenSpaceToolkit/Astrodynamics/Flight/Profile/Model.hpp>

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

inline void OpenSpaceToolkitAstrodynamicsPy_Flight_Profile_Model ( pybind11::module& aModule )
{

using namespace pybind11 ;

using ostk::astro::flight::profile::Model ;

class_<Model>(aModule, "Model")

.def("__eq__", [] (const Model &self, const Model &other){ return self == other; })
.def("__ne__", [] (const Model &self, const Model &other){ return self != other; })

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

.def("is_defined", &Model::isDefined)

.def("calculate_state_at", &Model::calculateStateAt, arg("instant"))
.def("calculate_states_at", &Model::calculateStatesAt, arg("instants"))
.def("get_axes_at", &Model::getAxesAt, arg("instant"))
.def("get_body_frame", &Model::getBodyFrame, arg("frame_name"))

;

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/// @project Open Space Toolkit ▸ Astrodynamics
/// @file bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Flight/Profile/Models.cpp
/// @author Lucas Brémond <lucas@loftorbital.com>
/// @license Apache License 2.0

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <OpenSpaceToolkitAstrodynamicsPy/Flight/Profile/Models/Tabulated.cpp>
#include <OpenSpaceToolkitAstrodynamicsPy/Flight/Profile/Models/Transform.cpp>

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

inline void OpenSpaceToolkitAstrodynamicsPy_Flight_Profile_Models ( pybind11::module& aModule )
{

// Create "models" python submodule
auto models = aModule.def_submodule("models") ;

// Add __path__ attribute for "models" submodule
models.attr("__path__") = "ostk.astrodynamics.flight.profile.models" ;

// add objects to "models" submodule
OpenSpaceToolkitAstrodynamicsPy_Flight_Profile_Models_Transform(models) ;
OpenSpaceToolkitAstrodynamicsPy_Flight_Profile_Models_Tabulated(models) ;

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/// @project Open Space Toolkit ▸ Astrodynamics
/// @file bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Flight/Profile/Models/Tabulated.cpp
/// @author Lucas Brémond <lucas@loftorbital.com>
/// @license Apache License 2.0

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <OpenSpaceToolkit/Astrodynamics/Flight/Profile/Models/Tabulated.hpp>

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

inline void OpenSpaceToolkitAstrodynamicsPy_Flight_Profile_Models_Tabulated ( pybind11::module& aModule )
{

using namespace pybind11 ;

using ostk::core::ctnr::Array ;

using ostk::astro::flight::profile::State ;
using ostk::astro::flight::profile::Model ;
using ostk::astro::flight::profile::models::Tabulated ;

class_<Tabulated, Model>(aModule, "Tabulated")

.def(init<Array<State>&>(), arg("states"))

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

.def("is_defined", &Tabulated::isDefined)

.def("get_interval", &Tabulated::getInterval)
.def("calculate_state_at", &Tabulated::calculateStateAt, arg("instant"))
.def("get_axes_at", &Tabulated::getAxesAt, arg("instant"))
.def("get_body_frame", &Tabulated::getBodyFrame, arg("frame_name"))

// .def_static("load", &Tabulated::Load, arg("file"))

;

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/// @project Open Space Toolkit ▸ Astrodynamics
/// @file bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Flight/Profile/Models/Transform.cpp
/// @author Lucas Brémond <lucas@loftorbital.com>
/// @license Apache License 2.0

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <OpenSpaceToolkit/Astrodynamics/Flight/Profile/Models/Transform.hpp>

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

inline void OpenSpaceToolkitAstrodynamicsPy_Flight_Profile_Models_Transform ( pybind11::module& aModule )
{

using namespace pybind11 ;

using ostk::core::types::Shared ;
using ostk::core::ctnr::Array ;

using ostk::physics::coord::Frame ;
using DynamicProvider = ostk::physics::coord::frame::provider::Dynamic ;

using ostk::astro::flight::profile::State ;
using ostk::astro::flight::profile::Model ;
using ostk::astro::flight::profile::models::Transform ;

class_<Transform, Model>(aModule, "Transform")

.def(init<const DynamicProvider&, const Shared<const Frame>&>(), arg("dynamic_provider"), arg("frame"))

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

.def("is_defined", &Transform::isDefined)

.def("calculate_state_at", &Transform::calculateStateAt, arg("instant"))
.def("get_axes_at", &Transform::getAxesAt, arg("instant"))
.def("get_body_frame", &Transform::getBodyFrame, arg("frame_name"))

.def_static("undefined", &Transform::Undefined)
.def_static("inertial_pointing", &Transform::InertialPointing, arg("trajectory"), arg("quaternion"))
.def_static("nadir_pointing", &Transform::NadirPointing, arg("orbit"), arg("orbital_frame_type"))

;

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Model

class_<BaseModel>(aModule, "Model")

.def("__eq__", [](const BaseModel &self, const BaseModel &other){ return self == other; })
.def("__ne__", [](const BaseModel &self, const BaseModel &other){ return self != other; })
.def("__eq__", [] (const BaseModel &self, const BaseModel &other){ return self == other; })
.def("__ne__", [] (const BaseModel &self, const BaseModel &other){ return self != other; })

.def("__str__", &(shiftToString<BaseModel>))
.def("__repr__", &(shiftToString<BaseModel>))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit

class_<Model>(aModule, "OrbitModel")

.def("__eq__", [](const Model &self, const Model &other){ return self == other; })
.def("__ne__", [](const Model &self, const Model &other){ return self != other; })
.def("__eq__", [] (const Model &self, const Model &other){ return self == other; })
.def("__ne__", [] (const Model &self, const Model &other){ return self != other; })

.def("__str__", &(shiftToString<Model>))

Expand Down
44 changes: 43 additions & 1 deletion bindings/python/test/flight/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@
Length = physics.units.Length
Transform = physics.coordinate.Transform
Position = physics.coordinate.Position
Velocity = physics.coordinate.Velocity
Frame = physics.coordinate.Frame
Axes = physics.coordinate.Axes
DynamicProvider = physics.coordinate.frame.providers.Dynamic
Trajectory = astrodynamics.Trajectory
Orbit = astrodynamics.trajectory.Orbit
Profile = astrodynamics.flight.Profile
State = astrodynamics.flight.profile.State
TransformModel = astrodynamics.flight.profile.models.Transform
TabulatedModel = astrodynamics.flight.profile.models.Tabulated

################################################################################################################################################################

Expand All @@ -51,7 +54,7 @@ def profile () -> Profile:
def dynamic_provider_generator (instant: Instant):
return Transform.identity(instant)

return Profile(DynamicProvider(dynamic_provider_generator), Frame.GCRF())
return Profile(TransformModel(DynamicProvider(dynamic_provider_generator), Frame.GCRF()))

################################################################################################################################################################

Expand Down Expand Up @@ -83,6 +86,13 @@ def test_get_axes_at (self, profile: Profile, instant: Instant):
assert axes is not None
assert isinstance(axes, Axes)

def test_get_body_frame (self, profile: Profile, instant: Instant):

frame = profile.get_body_frame("Name")

assert frame is not None
assert isinstance(frame, Frame)

def test_undefined (self):

profile: Profile = Profile.undefined()
Expand Down Expand Up @@ -120,4 +130,36 @@ def test_nadir_pointing (self):
assert isinstance(profile, Profile)
assert profile.is_defined()

def test_tabulated (self):

tabulated_model = TabulatedModel(
states = [
State(
instant = Instant.date_time(datetime(2020, 1, 1, 0, 0, 0), Scale.UTC),
position = Position.meters((0.0, 0.0, 0.0), Frame.GCRF()),
velocity = Velocity.meters_per_second((0.0, 0.0, 0.0), Frame.GCRF()),
attitude = Quaternion.unit(),
angular_velocity = (0.0, 0.0, 0.0),
reference_frame = Frame.GCRF(),
),
State(
instant = Instant.date_time(datetime(2020, 1, 1, 0, 1, 0), Scale.UTC),
position = Position.meters((0.0, 0.0, 0.0), Frame.GCRF()),
velocity = Velocity.meters_per_second((0.0, 0.0, 0.0), Frame.GCRF()),
attitude = Quaternion.unit(),
angular_velocity = (0.0, 0.0, 0.0),
reference_frame = Frame.GCRF(),
),
],
)

profile = Profile(
model = tabulated_model,
)

assert isinstance(profile, Profile)
assert profile.is_defined()

assert profile.get_state_at(Instant.date_time(datetime(2020, 1, 1, 0, 0, 30), Scale.UTC)) is not None

################################################################################################################################################################
4 changes: 2 additions & 2 deletions docker/development/debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ RUN mkdir -p /tmp/open-space-toolkit-io \

## Open Space Toolkit ▸ Mathematics

ARG OSTK_MATHEMATICS_VERSION=0.4.8
ARG OSTK_MATHEMATICS_VERSION=0.5.0

RUN mkdir -p /tmp/open-space-toolkit-mathematics \
&& cd /tmp/open-space-toolkit-mathematics \
Expand All @@ -111,7 +111,7 @@ RUN mkdir -p /tmp/open-space-toolkit-mathematics \

## Open Space Toolkit ▸ Physics

ARG OSTK_PHYSICS_VERSION=0.5.21
ARG OSTK_PHYSICS_VERSION=0.5.22

RUN mkdir -p /tmp/open-space-toolkit-physics \
&& cd /tmp/open-space-toolkit-physics \
Expand Down
4 changes: 2 additions & 2 deletions docker/development/fedora/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ RUN mkdir -p /tmp/open-space-toolkit-io \

## Open Space Toolkit ▸ Mathematics

ARG OSTK_MATHEMATICS_VERSION=0.4.8
ARG OSTK_MATHEMATICS_VERSION=0.5.0

RUN mkdir -p /tmp/open-space-toolkit-mathematics \
&& cd /tmp/open-space-toolkit-mathematics \
Expand All @@ -105,7 +105,7 @@ RUN mkdir -p /tmp/open-space-toolkit-mathematics \

## Open Space Toolkit ▸ Physics

ARG OSTK_PHYSICS_VERSION=0.5.21
ARG OSTK_PHYSICS_VERSION=0.5.22

RUN mkdir -p /tmp/open-space-toolkit-physics \
&& cd /tmp/open-space-toolkit-physics \
Expand Down
Loading

0 comments on commit 5a33a87

Please sign in to comment.