GroundPointing.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.RealFieldElement;
  19. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  20. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  21. import org.hipparchus.util.FastMath;
  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.errors.OrekitMessages;
  24. import org.orekit.frames.Frame;
  25. import org.orekit.time.AbsoluteDate;
  26. import org.orekit.time.FieldAbsoluteDate;
  27. import org.orekit.utils.AngularCoordinates;
  28. import org.orekit.utils.FieldAngularCoordinates;
  29. import org.orekit.utils.FieldPVCoordinates;
  30. import org.orekit.utils.FieldPVCoordinatesProvider;
  31. import org.orekit.utils.PVCoordinates;
  32. import org.orekit.utils.PVCoordinatesProvider;
  33. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  34. import org.orekit.utils.TimeStampedPVCoordinates;


  35. /**
  36.  * Base class for ground pointing attitude providers.
  37.  *
  38.  * <p>This class is a basic model for different kind of ground pointing
  39.  * attitude providers, such as : body center pointing, nadir pointing,
  40.  * target pointing, etc...
  41.  * </p>
  42.  * <p>
  43.  * The object <code>GroundPointing</code> is guaranteed to be immutable.
  44.  * </p>
  45.  * @see     AttitudeProvider
  46.  * @author V&eacute;ronique Pommier-Maurussane
  47.  */
  48. public abstract class GroundPointing implements AttitudeProvider {

  49.     /** Serializable UID. */
  50.     private static final long serialVersionUID = 20150529L;

  51.     /** J axis. */
  52.     private static final PVCoordinates PLUS_J =
  53.             new PVCoordinates(Vector3D.PLUS_J, Vector3D.ZERO, Vector3D.ZERO);

  54.     /** K axis. */
  55.     private static final PVCoordinates PLUS_K =
  56.             new PVCoordinates(Vector3D.PLUS_K, Vector3D.ZERO, Vector3D.ZERO);

  57.     /** Inertial frame. */
  58.     private final Frame inertialFrame;

  59.     /** Body frame. */
  60.     private final Frame bodyFrame;

  61.     /** Default constructor.
  62.      * Build a new instance with arbitrary default elements.
  63.      * @param inertialFrame frame in which orbital velocities are computed
  64.      * @param bodyFrame the frame that rotates with the body
  65.      * @exception OrekitException if the first frame specified is not a pseudo-inertial frame
  66.      * @since 7.1
  67.      */
  68.     protected GroundPointing(final Frame inertialFrame, final Frame bodyFrame)
  69.         throws OrekitException {
  70.         if (!inertialFrame.isPseudoInertial()) {
  71.             throw new OrekitException(OrekitMessages.NON_PSEUDO_INERTIAL_FRAME,
  72.                                       inertialFrame.getName());
  73.         }
  74.         this.inertialFrame = inertialFrame;
  75.         this.bodyFrame     = bodyFrame;
  76.     }

  77.     /** Get the body frame.
  78.      * @return body frame
  79.      */
  80.     public Frame getBodyFrame() {
  81.         return bodyFrame;
  82.     }

  83.     /** Compute the target point position/velocity in specified frame.
  84.      * <p>
  85.      * This method is {@code public} only to allow users to subclass this
  86.      * abstract class from other packages. It is <em>not</em> intended to
  87.      * be used directly.
  88.      * </p>
  89.      * @param pvProv provider for PV coordinates
  90.      * @param date date at which target point is requested
  91.      * @param frame frame in which observed ground point should be provided
  92.      * @return observed ground point position (element 0) and velocity (at index 1)
  93.      * in specified frame
  94.      * @throws OrekitException if some specific error occurs,
  95.      * such as no target reached
  96.      */
  97.     public abstract TimeStampedPVCoordinates getTargetPV(PVCoordinatesProvider pvProv,
  98.                                                          AbsoluteDate date, Frame frame)
  99.         throws OrekitException;

  100.     /** Compute the target point position/velocity in specified frame.
  101.      * @param pvProv provider for PV coordinates
  102.      * @param date date at which target point is requested
  103.      * @param frame frame in which observed ground point should be provided
  104.      * @param <T> type of the fiels elements
  105.      * @return observed ground point position (element 0) and velocity (at index 1)
  106.      * in specified frame
  107.      * @throws OrekitException if some specific error occurs,
  108.      * such as no target reached
  109.      * @since 9.0
  110.      */
  111.     public abstract <T extends RealFieldElement<T>> TimeStampedFieldPVCoordinates<T> getTargetPV(FieldPVCoordinatesProvider<T> pvProv,
  112.                                                                                                  FieldAbsoluteDate<T> date,
  113.                                                                                                  Frame frame)
  114.         throws OrekitException;

  115.     /** {@inheritDoc} */
  116.     public Attitude getAttitude(final PVCoordinatesProvider pvProv, final AbsoluteDate date,
  117.                                 final Frame frame)
  118.         throws OrekitException {

  119.         // satellite-target relative vector
  120.         final PVCoordinates pva  = pvProv.getPVCoordinates(date, inertialFrame);
  121.         final TimeStampedPVCoordinates delta =
  122.                 new TimeStampedPVCoordinates(date, pva, getTargetPV(pvProv, date, inertialFrame));

  123.         // spacecraft and target should be away from each other to define a pointing direction
  124.         if (delta.getPosition().getNorm() == 0.0) {
  125.             throw new OrekitException(OrekitMessages.SATELLITE_COLLIDED_WITH_TARGET);
  126.         }

  127.         // attitude definition:
  128.         // line of sight    -> +z satellite axis,
  129.         // orbital velocity -> (z, +x) half plane
  130.         final Vector3D p  = pva.getPosition();
  131.         final Vector3D v  = pva.getVelocity();
  132.         final Vector3D a  = pva.getAcceleration();
  133.         final double   r2 = p.getNormSq();
  134.         final double   r  = FastMath.sqrt(r2);
  135.         final Vector3D keplerianJerk = new Vector3D(-3 * Vector3D.dotProduct(p, v) / r2, a, -a.getNorm() / r, v);
  136.         final PVCoordinates velocity = new PVCoordinates(v, a, keplerianJerk);

  137.         final PVCoordinates los    = delta.normalize();
  138.         final PVCoordinates normal = PVCoordinates.crossProduct(delta, velocity).normalize();

  139.         AngularCoordinates ac = new AngularCoordinates(los, normal, PLUS_K, PLUS_J, 1.0e-9);

  140.         if (frame != inertialFrame) {
  141.             // prepend transform from specified frame to inertial frame
  142.             ac = ac.addOffset(frame.getTransformTo(inertialFrame, date).getAngular());
  143.         }

  144.         // build the attitude
  145.         return new Attitude(date, frame, ac);

  146.     }

  147.     /** {@inheritDoc} */
  148.     public <T extends RealFieldElement<T>>FieldAttitude<T> getAttitude(final FieldPVCoordinatesProvider<T> pvProv,
  149.                                                                        final FieldAbsoluteDate<T> date,
  150.                                                                        final Frame frame)
  151.         throws OrekitException {

  152.         // satellite-target relative vector
  153.         final FieldPVCoordinates<T> pva  = pvProv.getPVCoordinates(date, inertialFrame);
  154.         final TimeStampedFieldPVCoordinates<T> delta =
  155.                 new TimeStampedFieldPVCoordinates<>(date, pva, getTargetPV(pvProv, date, inertialFrame));

  156.         // spacecraft and target should be away from each other to define a pointing direction
  157.         if (delta.getPosition().getNorm().getReal() == 0.0) {
  158.             throw new OrekitException(OrekitMessages.SATELLITE_COLLIDED_WITH_TARGET);
  159.         }

  160.         // attitude definition:
  161.         // line of sight    -> +z satellite axis,
  162.         // orbital velocity -> (z, +x) half plane
  163.         final FieldVector3D<T> p  = pva.getPosition();
  164.         final FieldVector3D<T> v  = pva.getVelocity();
  165.         final FieldVector3D<T> a  = pva.getAcceleration();
  166.         final T   r2 = p.getNormSq();
  167.         final T   r  = r2.sqrt();
  168.         final FieldVector3D<T> keplerianJerk = new FieldVector3D<>(FieldVector3D.dotProduct(p, v).multiply(-3).divide(r2), a, a.getNorm().divide(r).multiply(-1), v);
  169.         final FieldPVCoordinates<T> velocity = new FieldPVCoordinates<>(v, a, keplerianJerk);


  170.         final FieldPVCoordinates<T> los    = delta.normalize();

  171.         final FieldPVCoordinates<T> normal = (delta.crossProduct(velocity)).normalize();

  172.         final FieldVector3D<T> zero  = FieldVector3D.getZero(r.getField());
  173.         final FieldVector3D<T> plusK = FieldVector3D.getPlusK(r.getField());
  174.         final FieldVector3D<T> plusJ = FieldVector3D.getPlusJ(r.getField());
  175.         FieldAngularCoordinates<T> ac =
  176.                         new FieldAngularCoordinates<>(los, normal,
  177.                                                       new FieldPVCoordinates<>(plusK, zero, zero),
  178.                                                       new FieldPVCoordinates<>(plusJ, zero, zero),
  179.                                                       1.0e-6);

  180.         if (frame != inertialFrame) {
  181.             // prepend transform from specified frame to inertial frame
  182.             ac = ac.addOffset(new FieldAngularCoordinates<>(r.getField(),
  183.                                                             frame.getTransformTo(inertialFrame, date.toAbsoluteDate()).getAngular()));
  184.         }

  185.         // build the attitude
  186.         return new FieldAttitude<>(date, frame, ac);

  187.     }

  188. }