SpinStabilized.java

  1. /* Copyright 2002-2024 CS GROUP
  2.  * Licensed to CS GROUP (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.CalculusFieldElement;
  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.frames.FieldTransform;
  25. import org.orekit.frames.Frame;
  26. import org.orekit.frames.Transform;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.time.FieldAbsoluteDate;
  29. import org.orekit.utils.FieldPVCoordinatesProvider;
  30. import org.orekit.utils.PVCoordinatesProvider;


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

  41.     /** Underlying non-rotating attitude provider.  */
  42.     private final AttitudeProvider nonRotatingLaw;

  43.     /** Start date of the rotation. */
  44.     private final AbsoluteDate start;

  45.     /** Rotation axis in satellite frame. */
  46.     private final Vector3D axis;

  47.     /** Spin rate in radians per seconds. */
  48.     private final double rate;

  49.     /** Spin vector. */
  50.     private final Vector3D spin;

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

  66.     /** {@inheritDoc} */
  67.     public AttitudeProvider getUnderlyingAttitudeProvider() {
  68.         return nonRotatingLaw;
  69.     }

  70.     /** {@inheritDoc} */
  71.     public Attitude getAttitude(final PVCoordinatesProvider pvProv,
  72.                                 final AbsoluteDate date, final Frame frame) {

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

  76.         // compute spin transform due to spin from reference to current date
  77.         final Transform spinInfluence =
  78.             new Transform(date,
  79.                           new Rotation(axis,
  80.                                        rate * date.durationFrom(start),
  81.                                        RotationConvention.FRAME_TRANSFORM),
  82.                           spin);

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

  85.         // build the attitude
  86.         return new Attitude(date, frame,
  87.                             combined.getRotation(), combined.getRotationRate(), combined.getRotationAcceleration());

  88.     }

  89.     /** {@inheritDoc} */
  90.     public <T extends CalculusFieldElement<T>> FieldAttitude<T> getAttitude(final FieldPVCoordinatesProvider<T> pvProv,
  91.                                                                         final FieldAbsoluteDate<T> date,
  92.                                                                         final Frame frame) {

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

  96.         // compute spin transform due to spin from reference to current date
  97.         final FieldTransform<T> spinInfluence =
  98.             new FieldTransform<>(date,
  99.                                  new FieldRotation<>(new FieldVector3D<>(date.getField(), axis),
  100.                                                      date.durationFrom(start).multiply(rate),
  101.                                                      RotationConvention.FRAME_TRANSFORM),
  102.                                  new FieldVector3D<>(date.getField(), spin));

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

  105.         // build the attitude
  106.         return new FieldAttitude<>(date, frame,
  107.                                    combined.getRotation(), combined.getRotationRate(), combined.getRotationAcceleration());

  108.     }

  109. }