@@ -31,6 +31,9 @@ using DynamicProvider = ostk::physics::coordinate::frame::provider::Dynamic;
31
31
32
32
using TransformModel = ostk::astrodynamics::flight::profile::model::Transform;
33
33
34
+ static Shared<const Frame> DEFAULT_ECI_FRAME = Frame::GCRF();
35
+ static Shared<const Frame> DEFAULT_ECEF_FRAME = Frame::ITRF();
36
+
34
37
Profile::Target::Target (const TargetType& aType, const Axis& anAxis, const bool & isAntiDirection)
35
38
: type(aType),
36
39
axis(anAxis),
@@ -284,21 +287,21 @@ Profile Profile::CustomPointing(
284
287
// Copy the orbit and orientation generator to avoid dangling references.
285
288
auto dynamicProviderGenerator = [anOrbit, anOrientationGenerator](const Instant& anInstant) -> Transform
286
289
{
287
- const State state = anOrbit.getStateAt (anInstant);
290
+ const State state = anOrbit.getStateAt (anInstant). inFrame (DEFAULT_ECI_FRAME) ;
288
291
289
- const Position position_GCRF = state.getPosition ();
290
- const Velocity velocity_GCRF = state.getVelocity ();
292
+ const Position position = state.getPosition ();
293
+ const Velocity velocity = state.getVelocity ();
291
294
292
295
return Transform::Active (
293
296
anInstant,
294
- -position_GCRF .accessCoordinates (),
295
- -velocity_GCRF .accessCoordinates (),
297
+ -position .accessCoordinates (),
298
+ -velocity .accessCoordinates (),
296
299
anOrientationGenerator (state),
297
300
Vector3d (0.0 , 0.0 , 0.0 ) // TBM: Artificially set to 0 for now.
298
301
);
299
302
};
300
303
301
- return Profile (TransformModel (DynamicProvider (dynamicProviderGenerator), Frame::GCRF () ));
304
+ return Profile (TransformModel (DynamicProvider (dynamicProviderGenerator), DEFAULT_ECI_FRAME ));
302
305
}
303
306
304
307
std::function<Quaternion(const State&)> Profile::AlignAndConstrain (
@@ -440,15 +443,17 @@ Profile::Profile()
440
443
441
444
Vector3d Profile::ComputeGeocentricNadirDirectionVector (const State& aState)
442
445
{
443
- return -aState.getPosition ().accessCoordinates ().normalized ();
446
+ return -aState.inFrame (DEFAULT_ECI_FRAME). getPosition ().accessCoordinates ().normalized ();
444
447
}
445
448
446
449
Vector3d Profile::ComputeGeodeticNadirDirectionVector (const State& aState)
447
450
{
448
- const Transform ITRF_GCRF_transform = Frame::ITRF () ->getTransformTo (Frame::GCRF () , aState.accessInstant ());
451
+ const Transform ITRF_GCRF_transform = DEFAULT_ECEF_FRAME ->getTransformTo (DEFAULT_ECI_FRAME , aState.accessInstant ());
449
452
450
453
const LLA lla = LLA::Cartesian (
451
- ITRF_GCRF_transform.getInverse ().applyToPosition (aState.getPosition ().accessCoordinates ()),
454
+ ITRF_GCRF_transform.getInverse ().applyToPosition (
455
+ aState.inFrame (DEFAULT_ECI_FRAME).getPosition ().accessCoordinates ()
456
+ ),
452
457
EarthGravitationalModel::EGM2008.equatorialRadius_ ,
453
458
EarthGravitationalModel::EGM2008.flattening_
454
459
);
@@ -465,46 +470,51 @@ Vector3d Profile::ComputeGeodeticNadirDirectionVector(const State& aState)
465
470
Vector3d Profile::ComputeTargetDirectionVector (const State& aState, const ostk::astrodynamics::Trajectory& aTrajectory)
466
471
{
467
472
const Vector3d targetPositionCoordinates =
468
- aTrajectory.getStateAt (aState.accessInstant ()).inFrame (Frame::GCRF () ).getPosition ().accessCoordinates ();
469
- const Vector3d satellitePositionCoordinates = aState.getPosition ().accessCoordinates ();
473
+ aTrajectory.getStateAt (aState.accessInstant ()).inFrame (DEFAULT_ECI_FRAME ).getPosition ().accessCoordinates ();
474
+ const Vector3d satellitePositionCoordinates = aState.inFrame (DEFAULT_ECI_FRAME). getPosition ().accessCoordinates ();
470
475
471
476
return (targetPositionCoordinates - satellitePositionCoordinates).normalized ();
472
477
}
473
478
474
479
Vector3d Profile::ComputeTargetVelocityVector (const State& aState, const ostk::astrodynamics::Trajectory& aTrajectory)
475
480
{
476
- const Transform ITRF_GCRF_transform = Frame::ITRF ()->getTransformTo (Frame::GCRF (), aState.accessInstant ());
481
+ const Instant& instant = aState.accessInstant ();
482
+
483
+ const Vector3d slidingTargetGroundVelocityCoordinates =
484
+ aTrajectory.getStateAt (instant).inFrame (DEFAULT_ECEF_FRAME).getVelocity ().accessCoordinates ();
477
485
478
- const State slidingTargetState_GCRF = aTrajectory.getStateAt (aState.accessInstant ());
479
- const State slidingTargetState_ITRF = slidingTargetState_GCRF.inFrame (Frame::ITRF ());
486
+ if (slidingTargetGroundVelocityCoordinates.isZero ())
487
+ {
488
+ throw ostk::core::error::RuntimeError (
489
+ " Cannot compute a Target Velocity Vector if the target's sliding velocity is zero."
490
+ );
491
+ }
480
492
481
- const Vector3d relativePositionDirection =
482
- (slidingTargetState_GCRF.getPosition ().getCoordinates () - aState.getPosition ().getCoordinates ()).normalized ();
483
- const Vector3d relativeVelocityDirection =
484
- ITRF_GCRF_transform.applyToVector (slidingTargetState_ITRF.getVelocity ().getCoordinates ()).normalized ();
493
+ const Transform ITRF_GCRF_transform = DEFAULT_ECEF_FRAME->getTransformTo (DEFAULT_ECI_FRAME, instant);
485
494
486
- const Vector3d relativeNormalDirection = relativePositionDirection.cross (relativeVelocityDirection).normalized ();
495
+ const Vector3d slidingTargetGroundVelocityCoordinatesRotated =
496
+ ITRF_GCRF_transform.applyToVector (slidingTargetGroundVelocityCoordinates);
487
497
488
- return relativeNormalDirection. cross (relativePositionDirection );
498
+ return slidingTargetGroundVelocityCoordinatesRotated. normalized ( );
489
499
}
490
500
491
501
Vector3d Profile::ComputeCelestialDirectionVector (const State& aState, const Celestial& aCelestial)
492
502
{
493
503
const Vector3d celestialPositionCoordinates =
494
- aCelestial.getPositionIn (Frame::GCRF () , aState.getInstant ()).accessCoordinates ();
495
- const Vector3d satellitePositionCoordinates = aState.getPosition ().accessCoordinates ();
504
+ aCelestial.getPositionIn (DEFAULT_ECI_FRAME , aState.getInstant ()).accessCoordinates ();
505
+ const Vector3d satellitePositionCoordinates = aState.inFrame (DEFAULT_ECI_FRAME). getPosition ().accessCoordinates ();
496
506
497
507
return (celestialPositionCoordinates - satellitePositionCoordinates).normalized ();
498
508
}
499
509
500
510
Vector3d Profile::ComputeVelocityDirectionVector_ECI (const State& aState)
501
511
{
502
- return aState.getVelocity ().accessCoordinates ().normalized ();
512
+ return aState.inFrame (DEFAULT_ECI_FRAME). getVelocity ().accessCoordinates ().normalized ();
503
513
}
504
514
505
515
Vector3d Profile::ComputeVelocityDirectionVector_ECEF (const State& aState)
506
516
{
507
- return aState.inFrame (Frame::ITRF () ).getVelocity ().accessCoordinates ().normalized ();
517
+ return aState.inFrame (DEFAULT_ECEF_FRAME ).getVelocity ().accessCoordinates ().normalized ();
508
518
}
509
519
510
520
Vector3d Profile::ComputeClockingAxisVector (const Vector3d& anAlignmentAxisVector, const Vector3d& aClockingVector)
@@ -514,8 +524,9 @@ Vector3d Profile::ComputeClockingAxisVector(const Vector3d& anAlignmentAxisVecto
514
524
515
525
Vector3d Profile::ComputeOrbitalMomentumDirectionVector (const State& aState)
516
526
{
517
- const Vector3d positionDirection = aState.getPosition ().getCoordinates ().normalized ();
518
- const Vector3d velocityDirection = aState.getVelocity ().getCoordinates ().normalized ();
527
+ const State state = aState.inFrame (DEFAULT_ECI_FRAME);
528
+ const Vector3d positionDirection = state.getPosition ().getCoordinates ().normalized ();
529
+ const Vector3d velocityDirection = state.getVelocity ().getCoordinates ().normalized ();
519
530
520
531
return positionDirection.cross (velocityDirection).normalized ();
521
532
}
0 commit comments