Skip to content

Commit e98e167

Browse files
feat: add support for state filter with fixed targets (#552)
* feat: add support for state filter with fixed targets * Apply suggestions from code review Co-authored-by: Antoine Paletta <98616558+apaletta3@users.noreply.github.com> --------- Co-authored-by: Antoine Paletta <98616558+apaletta3@users.noreply.github.com>
1 parent 53b2add commit e98e167

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

src/OpenSpaceToolkit/Astrodynamics/Access/Generator.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,6 @@ Array<Array<Access>> Generator::computeAccessesForFixedTargets(
413413
const bool& coarse
414414
) const
415415
{
416-
if (stateFilter_)
417-
{
418-
throw ostk::core::error::RuntimeError("State filter is not supported for multiple access targets.");
419-
}
420-
421416
// create a stacked matrix of SEZ rotations for all access targets
422417

423418
const Index targetCount = someAccessTargets.getSize();
@@ -657,13 +652,24 @@ Array<Array<Access>> Generator::computeAccessesForFixedTargets(
657652
{
658653
const Instant& instant = instants[index];
659654

655+
const State toTrajectoryState = aToTrajectory.getStateAt(instant);
656+
660657
// calculate target to satellite vector in ITRF
661658
const Vector3d toPositionCoordinates_ITRF =
662-
aToTrajectory.getStateAt(instant).inFrame(Frame::ITRF()).getPosition().getCoordinates();
659+
toTrajectoryState.inFrame(Frame::ITRF()).getPosition().getCoordinates();
663660

664661
// check if satellite is in access
665-
const auto inAccess =
666-
visibilityCriterionFilter(fromPositionCoordinates_ITRF, toPositionCoordinates_ITRF, instant);
662+
auto inAccess = visibilityCriterionFilter(fromPositionCoordinates_ITRF, toPositionCoordinates_ITRF, instant);
663+
664+
if (this->getStateFilter())
665+
{
666+
for (Index i = 0; i < targetCount; ++i)
667+
{
668+
const State fromState = someAccessTargets[i].accessTrajectory().getStateAt(instant);
669+
670+
inAccess(i) = inAccess(i) && this->getStateFilter()(fromState, toTrajectoryState);
671+
}
672+
}
667673

668674
inAccessPerTarget.row(index) = inAccess.cast<int>().transpose();
669675
}

test/OpenSpaceToolkit/Astrodynamics/Access/Generator.test.cpp

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -864,22 +864,6 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Access_Generator, ComputeAccesses)
864864
defaultGenerator_.computeAccesses(interval, {trajectoryTarget, accessTarget}, orbit, true),
865865
ostk::core::error::RuntimeError
866866
);
867-
868-
{
869-
const auto stateFilter = [](const State&, const State&) -> bool
870-
{
871-
return true;
872-
};
873-
874-
defaultGenerator_.setStateFilter(stateFilter);
875-
876-
EXPECT_THROW(
877-
defaultGenerator_.computeAccesses(interval, {accessTarget, accessTarget}, orbit),
878-
ostk::core::error::RuntimeError
879-
);
880-
881-
defaultGenerator_.setStateFilter(nullptr);
882-
}
883867
}
884868

885869
// single target
@@ -1042,6 +1026,32 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Access_Generator, ComputeAccesses)
10421026
}
10431027
}
10441028
}
1029+
1030+
// Elevation Interval visibility criterion, target with state filter
1031+
1032+
{
1033+
const auto stateFilter = [](const State& aFirstState, const State& aSecondState) -> bool
1034+
{
1035+
(void)aFirstState;
1036+
(void)aSecondState;
1037+
return false;
1038+
};
1039+
1040+
const Generator generator =
1041+
Generator(defaultEnvironment_, Duration::Minutes(1.0), Duration::Seconds(5.0), {}, stateFilter);
1042+
1043+
const ostk::mathematics::object::Interval<Real> elevationInterval =
1044+
ostk::mathematics::object::Interval<Real>::Closed(0.0, 90.0);
1045+
1046+
const VisibilityCriterion visibilityCriterion =
1047+
VisibilityCriterion::FromElevationInterval(elevationInterval);
1048+
1049+
const AccessTarget accessTarget = AccessTarget::FromLLA(visibilityCriterion, LLAs[0], defaultEarthSPtr_);
1050+
1051+
const Array<Access> accesses = generator.computeAccesses(interval, accessTarget, toTrajectory);
1052+
1053+
ASSERT_EQ(accesses.getSize(), 0);
1054+
}
10451055
}
10461056
}
10471057

0 commit comments

Comments
 (0)