SpinStabilized.java

  1. /* Copyright 2002-2025 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.     @Override
  68.     public AttitudeProvider getUnderlyingAttitudeProvider() {
  69.         return nonRotatingLaw;
  70.     }

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

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

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

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

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

  90.     }

  91.     /** {@inheritDoc} */
  92.     @Override
  93.     public Rotation getAttitudeRotation(final PVCoordinatesProvider pvProv, final AbsoluteDate date, final Frame frame) {
  94.         // get rotation from underlying non-rotating law
  95.         final Rotation baseRotation = nonRotatingLaw.getAttitudeRotation(pvProv, date, frame);

  96.         // compute spin rotation due to spin from reference to current date
  97.         final Rotation spinInfluence = new Rotation(axis, rate * date.durationFrom(start), RotationConvention.FRAME_TRANSFORM);

  98.         // combine the two rotations
  99.         return baseRotation.compose(spinInfluence, RotationConvention.FRAME_TRANSFORM);
  100.     }

  101.     /** {@inheritDoc} */
  102.     @Override
  103.     public <T extends CalculusFieldElement<T>> FieldAttitude<T> getAttitude(final FieldPVCoordinatesProvider<T> pvProv,
  104.                                                                         final FieldAbsoluteDate<T> date,
  105.                                                                         final Frame frame) {

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

  109.         // compute spin transform due to spin from reference to current date
  110.         final FieldTransform<T> spinInfluence =
  111.             new FieldTransform<>(date,
  112.                                  new FieldRotation<>(new FieldVector3D<>(date.getField(), axis),
  113.                                                      date.durationFrom(start).multiply(rate),
  114.                                                      RotationConvention.FRAME_TRANSFORM),
  115.                                  new FieldVector3D<>(date.getField(), spin));

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

  118.         // build the attitude
  119.         return new FieldAttitude<>(date, frame,
  120.                                    combined.getRotation(), combined.getRotationRate(), combined.getRotationAcceleration());

  121.     }

  122.     /** {@inheritDoc} */
  123.     @Override
  124.     public <T extends CalculusFieldElement<T>> FieldRotation<T> getAttitudeRotation(final FieldPVCoordinatesProvider<T> pvProv,
  125.                                                                                     final FieldAbsoluteDate<T> date,
  126.                                                                                     final Frame frame) {

  127.         // get attitude from underlying non-rotating law
  128.         final FieldRotation<T> baseRotation = nonRotatingLaw.getAttitudeRotation(pvProv, date, frame);

  129.         // compute spin rotation due to spin from reference to current date
  130.         final FieldRotation<T> spinInfluence =
  131.                 new FieldRotation<>(new FieldVector3D<>(date.getField(), axis),
  132.                                 date.durationFrom(start).multiply(rate),
  133.                                 RotationConvention.FRAME_TRANSFORM);

  134.         // combine the two rotations
  135.         return baseRotation.compose(spinInfluence, RotationConvention.FRAME_TRANSFORM);
  136.     }
  137. }