CelestialBodyPointed.java

  1. /* Copyright 2002-2018 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.attitudes;

  18. import org.hipparchus.Field;
  19. import org.hipparchus.RealFieldElement;
  20. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  21. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  22. import org.hipparchus.geometry.euclidean.threed.Rotation;
  23. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  24. import org.orekit.errors.OrekitException;
  25. import org.orekit.frames.FieldTransform;
  26. import org.orekit.frames.Frame;
  27. import org.orekit.frames.Transform;
  28. import org.orekit.time.AbsoluteDate;
  29. import org.orekit.time.FieldAbsoluteDate;
  30. import org.orekit.utils.FieldPVCoordinates;
  31. import org.orekit.utils.FieldPVCoordinatesProvider;
  32. import org.orekit.utils.PVCoordinates;
  33. import org.orekit.utils.PVCoordinatesProvider;


  34. /**
  35.  * This class handles a celestial body pointed attitude provider.
  36.  * <p>The celestial body pointed law is defined by two main elements:
  37.  * <ul>
  38.  *   <li>a celestial body towards which some satellite axis is exactly aimed</li>
  39.  *   <li>a phasing reference defining the rotation around the pointing axis</li>
  40.  * </ul>
  41.  *
  42.  * <p>
  43.  * The celestial body implicitly defines two of the three degrees of freedom
  44.  * and the phasing reference defines the remaining degree of freedom. This definition
  45.  * can be represented as first aligning exactly the satellite pointing axis to
  46.  * the current direction of the celestial body, and then to find the rotation
  47.  * around this axis such that the satellite phasing axis is in the half-plane
  48.  * defined by a cut line on the pointing axis and containing the celestial
  49.  * phasing reference.
  50.  * </p>
  51.  * <p>
  52.  * In order for this definition to work, the user must ensure that the phasing
  53.  * reference is <strong>never</strong> aligned with the pointing reference.
  54.  * Since the pointed body moves as the date changes, this should be ensured
  55.  * regardless of the date. A simple way to do this for Sun, Moon or any planet
  56.  * pointing is to choose a phasing reference far from the ecliptic plane. Using
  57.  * <code>Vector3D.PLUS_K</code>, the equatorial pole, is perfect in these cases.
  58.  * </p>
  59.  * <p>Instances of this class are guaranteed to be immutable.</p>
  60.  * @author Luc Maisonobe
  61.  */
  62. public class CelestialBodyPointed implements AttitudeProvider {

  63.     /** Serializable UID. */
  64.     private static final long serialVersionUID = 6222161082155807729L;

  65.     /** Frame in which {@link #phasingCel} is defined. */
  66.     private final Frame celestialFrame;

  67.     /** Celestial body to point at. */
  68.     private final PVCoordinatesProvider pointedBody;

  69.     /** Phasing reference, in celestial frame. */
  70.     private final Vector3D phasingCel;

  71.     /** Satellite axis aiming at the pointed body, in satellite frame. */
  72.     private final Vector3D pointingSat;

  73.     /** Phasing reference, in satellite frame. */
  74.     private final Vector3D phasingSat;

  75.     /** Creates new instance.
  76.      * @param celestialFrame frame in which <code>phasingCel</code> is defined
  77.      * @param pointedBody celestial body to point at
  78.      * @param phasingCel phasing reference, in celestial frame
  79.      * @param pointingSat satellite vector defining the pointing direction
  80.      * @param phasingSat phasing reference, in satellite frame
  81.      */
  82.     public CelestialBodyPointed(final Frame celestialFrame,
  83.                                 final PVCoordinatesProvider pointedBody,
  84.                                 final Vector3D phasingCel,
  85.                                 final Vector3D pointingSat,
  86.                                 final Vector3D phasingSat) {
  87.         this.celestialFrame = celestialFrame;
  88.         this.pointedBody    = pointedBody;
  89.         this.phasingCel     = phasingCel;
  90.         this.pointingSat    = pointingSat;
  91.         this.phasingSat     = phasingSat;
  92.     }

  93.     /** {@inheritDoc} */
  94.     public Attitude getAttitude(final PVCoordinatesProvider pvProv,
  95.                                 final AbsoluteDate date, final Frame frame)
  96.         throws OrekitException {

  97.         final PVCoordinates satPV = pvProv.getPVCoordinates(date, celestialFrame);

  98.         // compute celestial references at the specified date
  99.         final PVCoordinates bodyPV    = pointedBody.getPVCoordinates(date, celestialFrame);
  100.         final PVCoordinates pointing  = new PVCoordinates(satPV, bodyPV);
  101.         final Vector3D      pointingP = pointing.getPosition();
  102.         final double        r2        = Vector3D.dotProduct(pointingP, pointingP);

  103.         // evaluate instant rotation axis due to sat and body motion only (no phasing yet)
  104.         final Vector3D rotAxisCel =
  105.             new Vector3D(1 / r2, Vector3D.crossProduct(pointingP, pointing.getVelocity()));

  106.         // fix instant rotation to take phasing constraint into account
  107.         // (adding a rotation around pointing axis ensuring the motion of the phasing axis
  108.         //  is constrained in the pointing-phasing plane)
  109.         final Vector3D v1    = Vector3D.crossProduct(rotAxisCel, phasingCel);
  110.         final Vector3D v2    = Vector3D.crossProduct(pointingP,  phasingCel);
  111.         final double   compensation = -Vector3D.dotProduct(v1, v2) / v2.getNormSq();
  112.         final Vector3D phasedRotAxisCel = new Vector3D(1.0, rotAxisCel, compensation, pointingP);

  113.         // compute transform from celestial frame to satellite frame
  114.         final Rotation celToSatRotation =
  115.             new Rotation(pointingP, phasingCel, pointingSat, phasingSat);

  116.         // build transform combining rotation and instant rotation axis
  117.         Transform transform = new Transform(date, celToSatRotation, celToSatRotation.applyTo(phasedRotAxisCel));
  118.         if (frame != celestialFrame) {
  119.             // prepend transform from specified frame to celestial frame
  120.             transform = new Transform(date, frame.getTransformTo(celestialFrame, date), transform);
  121.         }

  122.         // build the attitude
  123.         return new Attitude(date, frame, transform.getRotation(), transform.getRotationRate(), transform.getRotationAcceleration());

  124.     }

  125.     /** {@inheritDoc} */
  126.     public <T extends RealFieldElement<T>> FieldAttitude<T> getAttitude(final FieldPVCoordinatesProvider<T> pvProv,
  127.                                                                         final FieldAbsoluteDate<T> date,
  128.                                                                         final Frame frame)
  129.         throws OrekitException {

  130.         final Field<T> field = date.getField();
  131.         final FieldPVCoordinates<T> satPV = pvProv.getPVCoordinates(date, celestialFrame);

  132.         // compute celestial references at the specified date
  133.         final FieldPVCoordinates<T> bodyPV    = new FieldPVCoordinates<>(field,
  134.                                                                          pointedBody.getPVCoordinates(date.toAbsoluteDate(),
  135.                                                                                                       celestialFrame));
  136.         final FieldPVCoordinates<T> pointing  = new FieldPVCoordinates<>(satPV, bodyPV);
  137.         final FieldVector3D<T>      pointingP = pointing.getPosition();
  138.         final T                     r2        = FieldVector3D.dotProduct(pointingP, pointingP);

  139.         // evaluate instant rotation axis due to sat and body motion only (no phasing yet)
  140.         final FieldVector3D<T> rotAxisCel =
  141.             new FieldVector3D<>(r2.reciprocal(), FieldVector3D.crossProduct(pointingP, pointing.getVelocity()));

  142.         // fix instant rotation to take phasing constraint into account
  143.         // (adding a rotation around pointing axis ensuring the motion of the phasing axis
  144.         //  is constrained in the pointing-phasing plane)
  145.         final FieldVector3D<T> v1           = FieldVector3D.crossProduct(rotAxisCel, phasingCel);
  146.         final FieldVector3D<T> v2           = FieldVector3D.crossProduct(pointingP,  phasingCel);
  147.         final T                compensation = FieldVector3D.dotProduct(v1, v2).negate().divide(v2.getNormSq());
  148.         final FieldVector3D<T> phasedRotAxisCel = new FieldVector3D<>(field.getOne(), rotAxisCel, compensation, pointingP);

  149.         // compute transform from celestial frame to satellite frame
  150.         final FieldRotation<T> celToSatRotation =
  151.             new FieldRotation<>(pointingP, new FieldVector3D<>(field, phasingCel),
  152.                             new FieldVector3D<>(field, pointingSat), new FieldVector3D<>(field, phasingSat));

  153.         // build transform combining rotation and instant rotation axis
  154.         FieldTransform<T> transform = new FieldTransform<>(date, celToSatRotation, celToSatRotation.applyTo(phasedRotAxisCel));
  155.         if (frame != celestialFrame) {
  156.             // prepend transform from specified frame to celestial frame
  157.             transform = new FieldTransform<>(date, frame.getTransformTo(celestialFrame, date), transform);
  158.         }

  159.         // build the attitude
  160.         return new FieldAttitude<>(date, frame,
  161.                         transform.getRotation(), transform.getRotationRate(), transform.getRotationAcceleration());

  162.     }

  163. }