SpacecraftBodyFrame.java

  1. /* Copyright 2002-2023 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.files.ccsds.definitions;

  18. import org.orekit.errors.OrekitException;
  19. import org.orekit.errors.OrekitMessages;

  20. /** Frames used in CCSDS Attitude Data Messages for the spacecraft body.
  21.  * @author Luc Maisonobe
  22.  * @since 11.0
  23.  */
  24. public class SpacecraftBodyFrame {

  25.     /** Equipment on which the frame is located. */
  26.     public enum BaseEquipment {

  27.         /** Accelerometer. */
  28.         ACC,

  29.         /** Actuator: could denote reaction wheels, solar arrays, thrusters, etc.. */
  30.         ACTUATOR,

  31.         /** Autonomous Star Tracker. */
  32.         AST,

  33.         /** Coarse Sun Sensor. */
  34.         CSS,

  35.         /** Digital Sun Sensor. */
  36.         DSS,

  37.         /** Earth Sensor Assembly. */
  38.         ESA,

  39.         /** Gyro reference frame (this name is used in SANA registry https://sanaregistry.org/r/spacecraft_body_reference_frames/). */
  40.         GYRO_FRAME,

  41.         /** Gyro reference frame (this name was used in ADM V1.0 (CCSDS 504.0-B-1). */
  42.         GYRO,

  43.         /** Inertial Measurement Unit. */
  44.         IMU_FRAME,

  45.         /** Instrument. */
  46.         INSTRUMENT,

  47.         /** Magnetic Torque Assembly. */
  48.         MTA,

  49.         /** Reaction Wheel. */
  50.         RW,

  51.         /** Solar Array. */
  52.         SA,

  53.         /** Spacecraft Body. */
  54.         SC_BODY,

  55.         /** Sensor. */
  56.         SENSOR,

  57.         /** Star Tracker. */
  58.         STARTRACKER,

  59.         /** Three Axis Magnetometer. */
  60.         TAM;

  61.     }

  62.     /** Equipment on which the frame is located. */
  63.     private final BaseEquipment baseEquipment;

  64.     /** Frame label. */
  65.     private final String label;

  66.     /** Simple constructor.
  67.      * @param baseEquipment equipment on which the frame is located
  68.      * @param label frame label
  69.      */
  70.     public SpacecraftBodyFrame(final BaseEquipment baseEquipment, final String label) {
  71.         this.baseEquipment = baseEquipment;
  72.         this.label         = label;
  73.     }

  74.     /** Get the quipment on which the frame is located.
  75.      * @return equipment on which the frame is located
  76.      */
  77.     public BaseEquipment getBaseEquipment() {
  78.         return baseEquipment;
  79.     }

  80.     /** Get the frame label.
  81.      * @return frame label
  82.      */
  83.     public String getLabel() {
  84.         return label;
  85.     }

  86.     /** {@inheritDoc}
  87.      * <p>
  88.      * The CCSDS composite name combines the {@link #getBaseEquipment() base equipment}
  89.      * and the {@link #getLabel()}
  90.      * </p>
  91.      * @return CCSDS composite name
  92.      */
  93.     @Override
  94.     public String toString() {
  95.         // the names should normally have a form similar to SC_BODY_i
  96.         // however sometimes is is only SC_BODYi or even SC_BODY when parsed
  97.         // in the first case, we put the missing '_' back
  98.         // in the second case, we just keep the base equipment name
  99.         return getLabel().length() > 0 ?
  100.                getBaseEquipment().name() + "_" + getLabel() :
  101.                getBaseEquipment().name();
  102.     }

  103.     /** Build an instance from a normalized descriptor.
  104.      * <p>
  105.      * Normalized strings have '_' characters replaced by spaces,
  106.      * and multiple spaces collapsed as one space only.
  107.      * </p>
  108.      * @param descriptor normalized descriptor
  109.      * @return parsed body frame
  110.      */
  111.     public static SpacecraftBodyFrame parse(final String descriptor) {
  112.         for (final BaseEquipment equipment : BaseEquipment.values()) {
  113.             if (descriptor.startsWith(equipment.name())) {
  114.                 // the names should normally have a form similar to SC_BODY_i
  115.                 // however sometimes is is only SC_BODYi or even SC_BODY
  116.                 // so we try to parse these common cases
  117.                 int index = equipment.name().length();
  118.                 if (index < descriptor.length() && descriptor.charAt(index) == '_') {
  119.                     ++index;
  120.                 }
  121.                 return new SpacecraftBodyFrame(equipment, descriptor.substring(index));
  122.             }
  123.         }
  124.         throw new OrekitException(OrekitMessages.CCSDS_INVALID_FRAME, descriptor);
  125.     }

  126. }