SpinStabilized.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.FieldRotation;
  20. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  21. import org.hipparchus.geometry.euclidean.threed.Rotation;
  22. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  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.FieldPVCoordinatesProvider;
  31. import org.orekit.utils.PVCoordinatesProvider;


  32. /**
  33.  * This class handles a spin stabilized attitude provider.
  34.  * <p>Spin stabilized laws are handled as wrappers for an underlying
  35.  * non-rotating law. This underlying law is typically an instance
  36.  * of {@link CelestialBodyPointed} with the pointing axis equal to
  37.  * the rotation axis, but can in fact be anything.</p>
  38.  * <p>Instances of this class are guaranteed to be immutable.</p>
  39.  * @author Luc Maisonobe
  40.  */
  41. public class SpinStabilized implements AttitudeProviderModifier {

  42.     /** Serializable UID. */
  43.     private static final long serialVersionUID = -7025790361794748354L;

  44.     /** Underlying non-rotating attitude provider.  */
  45.     private final AttitudeProvider nonRotatingLaw;

  46.     /** Start date of the rotation. */
  47.     private final AbsoluteDate start;

  48.     /** Rotation axis in satellite frame. */
  49.     private final Vector3D axis;

  50.     /** Spin rate in radians per seconds. */
  51.     private final double rate;

  52.     /** Spin vector. */
  53.     private final Vector3D spin;

  54.     /** Creates a new instance.
  55.      * @param nonRotatingLaw underlying non-rotating attitude provider
  56.      * @param start start date of the rotation
  57.      * @param axis rotation axis in satellite frame
  58.      * @param rate spin rate in radians per seconds
  59.      */
  60.     public SpinStabilized(final AttitudeProvider nonRotatingLaw,
  61.                           final AbsoluteDate start,
  62.                           final Vector3D axis, final double rate) {
  63.         this.nonRotatingLaw = nonRotatingLaw;
  64.         this.start          = start;
  65.         this.axis           = axis;
  66.         this.rate           = rate;
  67.         this.spin           = new Vector3D(rate / axis.getNorm(), axis);
  68.     }

  69.     /** {@inheritDoc} */
  70.     public AttitudeProvider getUnderlyingAttitudeProvider() {
  71.         return nonRotatingLaw;
  72.     }

  73.     /** {@inheritDoc} */
  74.     public Attitude getAttitude(final PVCoordinatesProvider pvProv,
  75.                                 final AbsoluteDate date, final Frame frame)
  76.         throws OrekitException {

  77.         // get attitude from underlying non-rotating law
  78.         final Attitude base = nonRotatingLaw.getAttitude(pvProv, date, frame);
  79.         final Transform baseTransform = new Transform(date, base.getOrientation());

  80.         // compute spin transform due to spin from reference to current date
  81.         final Transform spinInfluence =
  82.             new Transform(date,
  83.                           new Rotation(axis,
  84.                                        rate * date.durationFrom(start),
  85.                                        RotationConvention.FRAME_TRANSFORM),
  86.                           spin);

  87.         // combine the two transforms
  88.         final Transform combined = new Transform(date, baseTransform, spinInfluence);

  89.         // build the attitude
  90.         return new Attitude(date, frame,
  91.                             combined.getRotation(), combined.getRotationRate(), combined.getRotationAcceleration());

  92.     }

  93.     /** {@inheritDoc} */
  94.     public <T extends RealFieldElement<T>> FieldAttitude<T> getAttitude(final FieldPVCoordinatesProvider<T> pvProv,
  95.                                                                         final FieldAbsoluteDate<T> date,
  96.                                                                         final Frame frame)
  97.         throws OrekitException {

  98.         // get attitude from underlying non-rotating law
  99.         final FieldAttitude<T> base = nonRotatingLaw.getAttitude(pvProv, date, frame);
  100.         final FieldTransform<T> baseTransform = new FieldTransform<>(date, base.getOrientation());

  101.         // compute spin transform due to spin from reference to current date
  102.         final FieldTransform<T> spinInfluence =
  103.             new FieldTransform<>(date,
  104.                                  new FieldRotation<>(new FieldVector3D<>(date.getField(), axis),
  105.                                                      date.durationFrom(start).multiply(rate),
  106.                                                      RotationConvention.FRAME_TRANSFORM),
  107.                                  new FieldVector3D<>(date.getField(), spin));

  108.         // combine the two transforms
  109.         final FieldTransform<T> combined = new FieldTransform<>(date, baseTransform, spinInfluence);

  110.         // build the attitude
  111.         return new FieldAttitude<>(date, frame,
  112.                                    combined.getRotation(), combined.getRotationRate(), combined.getRotationAcceleration());

  113.     }

  114. }