Skip to content

Commit

Permalink
feat: address Kyle's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwaLoft committed Oct 26, 2023
1 parent 5157608 commit 5905dfe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
12 changes: 7 additions & 5 deletions include/OpenSpaceToolkit/Astrodynamics/Trajectory/Sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,16 @@ class Sequence
/// @param [in] aRepetitionCount A repetition count. Defaults to 1.
/// @param [in] aNumericalSolver A Numerical Solver. Defaults to Undefined.
/// @param [in] aDynamicsArray An array of shared dynamics. Defaults to empty.
/// @param [in] maximumPropagationDuration Maximum duration for propagation. Defaults to 7.0 days.
/// @param [in] segmentPropagationDurationLimit Maximum duration for propagation. Defaults to 7.0
/// days.
/// @param [in] verbosity Verbosity level for the solver [0 (low) - 5 (high)]. Defaults to 0.

Sequence(
const Array<Segment>& aSegmentArray = Array<Segment>::Empty(),
const Size& aRepetitionCount = 1,
const NumericalSolver& aNumericalSolver = NumericalSolver::Undefined(),
const Array<Shared<Dynamics>>& aDynamicsArray = Array<Shared<Dynamics>>::Empty(),
const Duration& maximumPropagationDuration = Duration::Days(7.0),
const Duration& segmentPropagationDurationLimit = Duration::Days(7.0),
const Size& verbosity = 0
);

Expand Down Expand Up @@ -149,13 +150,14 @@ class Sequence
/// @brief Solve the sequence given an initial state.
///
/// @param [in] aState Initial state for the sequence.
/// @param [in] aMaximumPropagationDuration Maximum propagation duration. Defaults to 30.0 days.
/// @param [in] sequencePropagationDurationLimit Maximum propagation duration for the Sequence.
/// Defaults to 30.0 days.
/// @param [in] anEventCondition An event condition. Defaults to nullptr.
/// @return A Solution that contains solutions for each segment.

Solution solve(
const State& aState,
const Duration& aMaximumPropagationDuration = Duration::Days(30.0),
const Duration& sequencePropagationDurationLimit = Duration::Days(30.0),
const Shared<EventCondition>& anEventConditionSPtr = nullptr
) const;

Expand All @@ -171,7 +173,7 @@ class Sequence
Size repetitionCount_;
NumericalSolver numericalSolver_;
Array<Shared<Dynamics>> dynamics_;
Duration maximumPropagationDuration_;
Duration segmentPropagationDurationLimit_;
};

} // namespace trajectory
Expand Down
37 changes: 26 additions & 11 deletions src/OpenSpaceToolkit/Astrodynamics/Trajectory/Sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <boost/log/expressions.hpp>
#include <boost/log/trivial.hpp>

#include <OpenSpaceToolkit/Physics/Time/Duration.hpp>

#include <OpenSpaceToolkit/Astrodynamics/Trajectory/Sequence.hpp>

namespace ostk
Expand All @@ -13,6 +15,8 @@ namespace astro
namespace trajectory
{

using ostk::physics::time::Duration;

const Instant& Sequence::Solution::accessStartInstant() const
{
return segmentSolutions.accessFirst().accessStartInstant();
Expand Down Expand Up @@ -138,7 +142,7 @@ Sequence::Sequence(
repetitionCount_(aRepetitionCount),
numericalSolver_(aNumericalSolver),
dynamics_(aDynamicsArray),
maximumPropagationDuration_(maximumPropagationDuration)
segmentPropagationDurationLimit_(maximumPropagationDuration)
{
if (verbosity == 5)
{
Expand Down Expand Up @@ -199,7 +203,7 @@ Array<Shared<Dynamics>> Sequence::getDynamics() const

Duration Sequence::getMaximumPropagationDuration() const
{
return maximumPropagationDuration_;
return segmentPropagationDurationLimit_;
}

void Sequence::addSegment(const Segment& aSegment)
Expand All @@ -223,22 +227,24 @@ void Sequence::addManeuverSegment(const Shared<EventCondition>& anEventCondition
}

Sequence::Solution Sequence::solve(
const State& aState, const Duration& aMaximumPropagationDuration, const Shared<EventCondition>& anEventConditionSPtr
const State& aState,
const Duration& sequencePropagationDurationLimit,
const Shared<EventCondition>& anEventConditionSPtr
) const
{
Array<Segment::Solution> segmentSolutions;

State initialState = aState;
State finalState = State::Undefined();

bool eventConditionIsSatisfied = anEventConditionSPtr == nullptr;
Duration totalPropagationDuration = Duration::Seconds(0.0);

for (Size i = 0; i < repetitionCount_; ++i)
{
for (const Segment& segment : segments_)
{
// Maximum propagation check
if ((initialState.accessInstant() - aState.accessInstant()) > aMaximumPropagationDuration)
// Terminate Sequence unsuccessfully if the propagation limit was exceeded
if (totalPropagationDuration > sequencePropagationDurationLimit)
{
BOOST_LOG_TRIVIAL(warning)
<< "Terminating Sequence because maximum propagation duration is reached." << std::endl;

Check warning on line 250 in src/OpenSpaceToolkit/Astrodynamics/Trajectory/Sequence.cpp

View check run for this annotation

Codecov / codecov/patch

src/OpenSpaceToolkit/Astrodynamics/Trajectory/Sequence.cpp#L249-L250

Added lines #L249 - L250 were not covered by tests
Expand All @@ -248,7 +254,12 @@ Sequence::Solution Sequence::solve(

BOOST_LOG_TRIVIAL(debug) << "Solving Segment:\n" << segment << std::endl;

Segment::Solution segmentSolution = segment.solve(initialState, maximumPropagationDuration_);
// Clip the segment propagation limit if it will exceed the Sequence propagation limit
const Duration segmentPropagationDurationLimit = std::min(
segmentPropagationDurationLimit_, (sequencePropagationDurationLimit - totalPropagationDuration)
);

Segment::Solution segmentSolution = segment.solve(initialState, segmentPropagationDurationLimit);

segmentSolution.name =
String::Format("{} - {} - {}", segmentSolution.name, segment.getEventCondition()->getName(), i);
Expand All @@ -257,15 +268,17 @@ Sequence::Solution Sequence::solve(

segmentSolutions.add(segmentSolution);

// Segment condition check
totalPropagationDuration += segmentSolution.getPropagationDuration();

// Terminate Sequence unsuccessfully if the segment condition was not satisfied
if (!segmentSolution.conditionIsSatisfied)
{
BOOST_LOG_TRIVIAL(warning) << "Segment condition is not satisfied." << std::endl;

return {segmentSolutions, false};
}

// Event condition check
// Terminate Sequence successfully if a provided event condition was satisfied
if (anEventConditionSPtr != nullptr &&
anEventConditionSPtr->isSatisfied(segmentSolution.states.accessLast(), initialState))
{
Expand All @@ -278,11 +291,13 @@ Sequence::Solution Sequence::solve(
}
}

if (eventConditionIsSatisfied)
// No Event Condition was provided, therefore the Sequence has successfully completed
if (anEventConditionSPtr == nullptr)
{
return {segmentSolutions, true};
}

// An Event Condition was provided, however the condition was not met, therefore the completion is unsuccessful
return {segmentSolutions, false};
}

Expand Down Expand Up @@ -315,7 +330,7 @@ void Sequence::print(std::ostream& anOutputStream, bool displayDecorator) const
}

ostk::core::utils::Print::Line(anOutputStream)
<< "Maximum Propagation Duration:" << maximumPropagationDuration_.toString();
<< "Maximum Propagation Duration:" << segmentPropagationDurationLimit_.toString();

if (displayDecorator)
{
Expand Down

0 comments on commit 5905dfe

Please sign in to comment.