Skip to content

Commit

Permalink
feat: add custom profile generators (#419)
Browse files Browse the repository at this point in the history
* feat: add custom profile generators

* wip: tests

* feat: address feedback

* Apply suggestions from code review

Co-authored-by: Lucas <lucas.bremond@gmail.com>

* feat: fix tests

* feat: add more tests

* feat: add orbital momentum

* feat: add python bindings and tests

* refactor: rename and streamline

* feat: create trajectory and alignment targets

* feat: address remaining feedback

---------

Co-authored-by: Lucas <lucas.bremond@gmail.com>
  • Loading branch information
vishwa2710 and lucas-bremond authored Sep 19, 2024
1 parent 09d82b1 commit 19b96f5
Show file tree
Hide file tree
Showing 7 changed files with 1,325 additions and 40 deletions.
2 changes: 1 addition & 1 deletion bindings/python/src/OpenSpaceToolkitAstrodynamicsPy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ PYBIND11_MODULE(OpenSpaceToolkitAstrodynamicsPy, m)
OpenSpaceToolkitAstrodynamicsPy_RootSolver(m);

// Add python submodules to OpenSpaceToolkitAstrodynamicsPy
OpenSpaceToolkitAstrodynamicsPy_Trajectory(m);
OpenSpaceToolkitAstrodynamicsPy_Flight(m);
OpenSpaceToolkitAstrodynamicsPy_Dynamics(m);
OpenSpaceToolkitAstrodynamicsPy_Trajectory(m);
OpenSpaceToolkitAstrodynamicsPy_Access(m);
OpenSpaceToolkitAstrodynamicsPy_Conjunction(m);
OpenSpaceToolkitAstrodynamicsPy_EventCondition(m);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,192 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Flight_Profile(pybind11::module& aMo
using namespace pybind11;

using ostk::core::container::Array;
using ostk::core::container::Pair;
using ostk::core::type::Shared;

using ostk::mathematics::geometry::d3::transformation::rotation::Quaternion;

using ostk::physics::coordinate::Frame;

using ostk::astrodynamics::flight::Profile;
using ostk::astrodynamics::flight::profile::Model;
using ostk::astrodynamics::Trajectory;
using ostk::astrodynamics::trajectory::Orbit;
using ostk::astrodynamics::trajectory::State;

class_<Profile, Shared<Profile>>(
class_<Profile, Shared<Profile>> profileClass(
aModule,
"Profile",
R"doc(
Spacecraft Flight Profile.
)doc"
);

enum_<Profile::Axis>(
profileClass,
"Axis",
R"doc(
The axis of the profile.
)doc"
)

.value("X", Profile::Axis::X, "X axis")
.value("Y", Profile::Axis::Y, "Y axis")
.value("Z", Profile::Axis::Z, "Z axis")

;

enum_<Profile::TargetType>(
profileClass,
"TargetType",
R"doc(
The target type of the profile.
)doc"
)

.value("GeocentricNadir", Profile::TargetType::GeocentricNadir, "Geocentric nadir")
.value("GeodeticNadir", Profile::TargetType::GeodeticNadir, "Geodetic nadir")
.value("Trajectory", Profile::TargetType::Trajectory, "Trajectory")
.value("Sun", Profile::TargetType::Sun, "Sun")
.value("Moon", Profile::TargetType::Moon, "Moon")
.value("VelocityECI", Profile::TargetType::VelocityECI, "Velocity in ECI")
.value("VelocityECEF", Profile::TargetType::VelocityECEF, "Velocity in ECEF")
.value("OrbitalMomentum", Profile::TargetType::OrbitalMomentum, "Orbital momentum")
.value("OrientationProfile", Profile::TargetType::OrientationProfile, "Orientation profile")

;

class_<Profile::Target, Shared<Profile::Target>>(
profileClass,
"Target",
R"doc(
The target of the profile.
)doc"
)

.def(
init<const Profile::TargetType&, const Profile::Axis&, const bool&>(),
R"doc(
Constructor.
Args:
type (Profile.TargetType): The target type.
axis (Profile.Axis): The axis.
anti_direction (bool): True if the direction is flipped, False otherwise. Defaults to False.
)doc",
arg("type"),
arg("axis"),
arg("anti_direction") = false
)

.def_readonly("type", &Profile::Target::type, "The type of the target.")
.def_readonly("axis", &Profile::Target::axis, "The axis of the target.")
.def_readonly(
"anti_direction", &Profile::Target::antiDirection, "True if the direction is flipped, False otherwise."
)

;

class_<Profile::TrajectoryTarget, Profile::Target, Shared<Profile::TrajectoryTarget>>(
profileClass,
"TrajectoryTarget",
R"doc(
The trajectory target.
)doc"
)

.def(
init<const Trajectory&, const Profile::Axis&, const bool&&>(),
R"doc(
Constructor.
Args:
trajectory (Trajectory): The trajectory, required only if the target type is `Trajectory`.
axis (Profile.Axis): The axis.
anti_direction (bool): True if the direction is flipped, False otherwise. Defaults to False.
)doc",
arg("trajectory"),
arg("axis"),
arg("anti_direction") = false
)

.def_readonly(
"trajectory",
&Profile::TrajectoryTarget::trajectory,
"The trajectory of the target. Required only if the target type is `Trajectory`."
)

;

class_<Profile::OrientationProfileTarget, Profile::Target, Shared<Profile::OrientationProfileTarget>>(
profileClass,
"OrientationProfileTarget",
R"doc(
The alignment profile target.
)doc"
)

.def(
init<const Array<Pair<Instant, Vector3d>>&, const Profile::Axis&, const bool&&>(),
R"doc(
Constructor.
Args:
orientation_profile (list[Tuple[Instant, Vector3d]]): The orientation profile.
axis (Profile.Axis): The axis.
anti_direction (bool): True if the direction is flipped, False otherwise. Defaults to False.
)doc",
arg("orientation_profile"),
arg("axis"),
arg("anti_direction") = false
)

.def_readonly(
"orientation_profile",
&Profile::OrientationProfileTarget::orientationProfile,
"The orientation profile of the target"
)

;

class_<Profile::CustomTarget, Profile::Target, Shared<Profile::CustomTarget>>(
profileClass,
"CustomTarget",
R"doc(
The custom target.
)doc"
)

.def(
init<const std::function<Vector3d(const State&)>&, const Profile::Axis&, const bool&&>(),
R"doc(
Constructor.
Args:
orientation_generator (Callable[np.ndarray, State]]): The orientation generator, accepts a state and returns a size 3 array of directions.
axis (Profile.Axis): The axis.
anti_direction (bool): True if the direction is flipped, False otherwise. Defaults to False.
)doc",
arg("orientation_generator"),
arg("axis"),
arg("anti_direction") = false
)

.def_readonly(
"orientation_generator",
&Profile::CustomTarget::orientationGenerator,
"The orientation generator of the target"
)

;

profileClass

.def(
init<const Model&>(),
R"doc(
Expand Down Expand Up @@ -156,6 +325,70 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Flight_Profile(pybind11::module& aMo
arg("orbital_frame_type")
)

.def_static(
"custom_pointing",
overload_cast<const Orbit&, const std::function<Quaternion(const State&)>&>(&Profile::CustomPointing),
R"doc(
Create a custom pointing profile.
Args:
orbit (Orbit): The orbit.
orientation_generator (callable[Quaternion, State]): The orientation generator. Typically used in conjunction with `align_and_constrain`.
Returns:
Profile: The custom pointing profile.
)doc",
arg("orbit"),
arg("orientation_generator")
)

.def_static(
"custom_pointing",
overload_cast<
const Orbit&,
const Shared<const Profile::Target>&,
const Shared<const Profile::Target>&,
const Angle&>(&Profile::CustomPointing),
R"doc(
Create a custom pointing profile.
Args:
orbit (Orbit): The orbit.
alignment_target (Profile.Target): The alignment target.
clocking_target (Profile.Target): The clocking target.
angular_offset (Angle): The angular offset. Defaults to `Angle.Zero()`.
Returns:
Profile: The custom pointing profile.
)doc",
arg("orbit"),
arg("alignment_target"),
arg("clocking_target"),
arg_v("angular_offset", Angle::Zero(), "Angle.Zero()")
)

.def_static(
"align_and_constrain",
&Profile::AlignAndConstrain,
R"doc(
Generate a function that provides a quaternion that aligns to the `alignment_target` and constrains to the `clocking_target` for a given state.
Args:
alignment_target (Profile.Target | Profile.TrajectoryTarget | Profile.OrientationProfileTarget | Profile.CustomTarget): The alignment target.
clocking_target (Profile.Target | Profile.TrajectoryTarget | Profile.OrientationProfileTarget | Profile.CustomTarget): The clocking target.
angular_offset (Angle): The angular offset. Defaults to `Angle.Zero()`.
Returns:
callable[Quaternion, State]: The custom orientation.
)doc",
arg("alignment_target"),
arg("clocking_target"),
arg_v("angular_offset", Angle::Zero(), "Angle.Zero()")
)

;

// Create "profile" python submodule
Expand Down
Loading

0 comments on commit 19b96f5

Please sign in to comment.