OMMFile.java

  1. /* Copyright 2002-2020 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;

  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.List;

  21. import org.hipparchus.util.FastMath;
  22. import org.orekit.orbits.CartesianOrbit;
  23. import org.orekit.orbits.KeplerianOrbit;
  24. import org.orekit.orbits.PositionAngle;
  25. import org.orekit.propagation.SpacecraftState;
  26. import org.orekit.propagation.analytical.tle.TLE;

  27. /**
  28.  * This class gathers the informations present in the Orbital Mean-Elements Message (OMM),
  29.  * and contains methods to generate a {@link CartesianOrbit}, a {@link KeplerianOrbit},
  30.  * a {@link SpacecraftState} and, eventually, a {@link TLE}.
  31.  * @author sports
  32.  * @since 6.1
  33.  */
  34. public class OMMFile extends OGMFile {

  35.     /** Meta-data. */
  36.     private final OMMMetaData metaData;

  37.     /** Mean motion (the Keplerian Mean motion in revolutions per day). To be used instead of semi-major
  38.      * axis if MEAN_ELEMENT_THEORY = SGP/SGP4. */
  39.     private double meanMotion;

  40.     /** Ephemeris Type, only required if MEAN_ELEMENT_THEORY = SGP/SGP4. Some sources suggest the coding for
  41.      * the EPHEMERIS_TYPE keyword: 1 = SGP, 2 = SGP4, 3 = SDP4, 4 = SGP8, 5 = SDP8. Default value = 0.
  42.      */
  43.     private int ephemerisType;

  44.     /** Classification Type, only required if MEAN_ELEMENT_THEORY = SGP/SGP4. Some sources suggest the
  45.      *  following coding for the CLASSIFICATION_TYPE keyword: U = unclassified, S = secret. Default value = U.
  46.      */
  47.     private char classificationType;

  48.     /** NORAD Catalog Number ("Satellite Number"), an integer of up to nine digits. */
  49.     private Integer noradID;

  50.     /** Element set number for this satellite, only required if MEAN_ELEMENT_THEORY = SGP/SGP4.
  51.      * Normally incremented sequentially, but may be out of sync if it is generated from a backup source.
  52.      * Used to distinguish different TLEs, and therefore only meaningful if TLE based data is being exchanged. */
  53.     private String elementSetNo;

  54.     /** Revolution Number, only required if MEAN_ELEMENT_THEORY = SGP/SGP4. */
  55.     private int revAtEpoch;

  56.     /** SGP/SGP4 drag-like coefficient (in units 1/[Earth radii]), only required if MEAN_ELEMENT_THEORY = SGP/SGP4. */
  57.     private Double bStar;

  58.     /** First Time Derivative of the Mean Motion, only required if MEAN_ELEMENT_THEORY = SGP. */
  59.     private Double meanMotionDot;

  60.     /** Second Time Derivative of Mean Motion, only required if MEAN_ELEMENT_THEORY = SGP. */
  61.     private Double meanMotionDotDot;

  62.     /** TLE related parameters comments. The list contains a string for each line of comment. */
  63.     private List<String> dataTleRelatedParametersComment;

  64.     /** Create a new OMM file object. */
  65.     OMMFile() {
  66.         metaData = new OMMMetaData(this);
  67.     }

  68.     /** Get the meta data.
  69.      * @return meta data
  70.      */
  71.     @Override
  72.     public OMMMetaData getMetaData() {
  73.         return metaData;
  74.     }

  75.     /** Get the orbit mean motion.
  76.      * @return the orbit mean motion
  77.      */
  78.     public double getMeanMotion() {
  79.         return meanMotion;
  80.     }

  81.     /** Set the orbit mean motion.
  82.      * @param motion the mean motion to be set
  83.      */
  84.     void setMeanMotion(final double motion) {
  85.         this.meanMotion = motion;
  86.     }

  87.     /** Get the ephemeris type.
  88.      * @return the ephemerisType
  89.      */
  90.     public int getEphemerisType() {
  91.         return ephemerisType;
  92.     }

  93.     /** Set the ephemeris type.
  94.      * @param ephemerisType the ephemeris type to be set
  95.      */
  96.     void setEphemerisType(final int ephemerisType) {
  97.         this.ephemerisType = ephemerisType;
  98.     }

  99.     /** Get the classification type.
  100.      * @return the classificationType
  101.      */
  102.     public char getClassificationType() {
  103.         return classificationType;
  104.     }

  105.     /** Set the classification type.
  106.      * @param classificationType the classification type to be set
  107.      */
  108.     void setClassificationType(final char classificationType) {
  109.         this.classificationType = classificationType;
  110.     }

  111.     /** Get the NORAD Catalog Number ("Satellite Number").
  112.      * @return the NORAD Catalog Number
  113.      */
  114.     public Integer getNoradID() {
  115.         return noradID;
  116.     }

  117.     /** Set the NORAD Catalog Number ("Satellite Number").
  118.      * @param noradID the element set number to be set
  119.      */
  120.     void setNoradID(final Integer noradID) {
  121.         this.noradID = noradID;
  122.     }

  123.     /** Get the element set number for this satellite.
  124.      * @return the element set number for this satellite
  125.      */
  126.     public String getElementSetNumber() {
  127.         return elementSetNo;
  128.     }

  129.     /** Set the element set number for this satellite.
  130.      * @param elementSetNo the element set number to be set
  131.      */
  132.     void setElementSetNo(final String elementSetNo) {
  133.         this.elementSetNo = elementSetNo;
  134.     }

  135.     /** Get the revolution rumber.
  136.      * @return the revolution rumber
  137.      */
  138.     public int getRevAtEpoch() {
  139.         return revAtEpoch;
  140.     }

  141.     /** Set the revolution rumber.
  142.      * @param revAtEpoch the Revolution Number to be set
  143.      */
  144.     void setRevAtEpoch(final int revAtEpoch) {
  145.         this.revAtEpoch = revAtEpoch;
  146.     }

  147.     /** Get the SGP/SGP4 drag-like coefficient.
  148.      * @return the SGP/SGP4 drag-like coefficient
  149.      */
  150.     public double getBStar() {
  151.         return bStar;
  152.     }

  153.     /** Set the SGP/SGP4 drag-like coefficient.
  154.      * @param bStar the SGP/SGP4 drag-like coefficient to be set
  155.      */
  156.     void setbStar(final double bStar) {
  157.         this.bStar = bStar;
  158.     }

  159.     /** Get the first time derivative of the mean motion.
  160.      * @return the first time derivative of the mean motion
  161.      */
  162.     public double getMeanMotionDot() {
  163.         return meanMotionDot;
  164.     }

  165.     /** Set the first time derivative of the mean motion.
  166.      * @param meanMotionDot the first time derivative of the mean motion to be set
  167.      */
  168.     void setMeanMotionDot(final double meanMotionDot) {
  169.         this.meanMotionDot = meanMotionDot;
  170.     }

  171.     /** Get the second time derivative of the mean motion.
  172.      * @return the second time derivative of the mean motion
  173.      */
  174.     public double getMeanMotionDotDot() {
  175.         return meanMotionDotDot;
  176.     }

  177.     /** Set the second time derivative of the mean motion.
  178.      * @param meanMotionDotDot the second time derivative of the mean motion to be set
  179.      */
  180.     void setMeanMotionDotDot(final double meanMotionDotDot) {
  181.         this.meanMotionDotDot = meanMotionDotDot;
  182.     }

  183.     /** Get the comment for TLE related parameters.
  184.      * @return comment for TLE related parameters
  185.      */
  186.     public List<String> getTLERelatedParametersComment() {
  187.         return Collections.unmodifiableList(dataTleRelatedParametersComment);
  188.     }

  189.     /** Set the comment for TLE related parameters.
  190.      * @param comment comment to set
  191.      */
  192.     void setTLERelatedParametersComment(final List<String> comment) {
  193.         dataTleRelatedParametersComment = new ArrayList<String>(comment);
  194.     }

  195.     /** Generate a {@link KeplerianOrbit} based on the OMM mean Keplerian elements.
  196.      * If the reference frame is not pseudo-inertial, an exception is raised.
  197.      * @return the {@link KeplerianOrbit} generated from the OMM information
  198.      */
  199.     public KeplerianOrbit generateKeplerianOrbit() {
  200.         setMuUsed();
  201.         final double a;
  202.         if (Double.isNaN(getA())) {
  203.             a = FastMath.cbrt(getMuUsed() / (meanMotion * meanMotion));
  204.         } else {
  205.             a = getA();
  206.         }
  207.         return new KeplerianOrbit(a, getE(), getI(), getPa(), getRaan(), getAnomaly(),
  208.                                   PositionAngle.MEAN, metaData.getFrame(), getEpoch(), getMuUsed());
  209.     }

  210.     /** Generate a {@link CartesianOrbit} from the {@link KeplerianOrbit}.
  211.      * @return the {@link CartesianOrbit} generated from the OPM information
  212.      */
  213.     public CartesianOrbit generateCartesianOrbit() {
  214.         return new CartesianOrbit(generateKeplerianOrbit());
  215.     }

  216.     /** Generate spacecraft state from the {@link KeplerianOrbit} generated by generateKeplerianOrbit.
  217.      *  Raises an exception if OMM doesn't contain spacecraft mass information.
  218.      * @return the spacecraft state of the OMM
  219.      */
  220.     public SpacecraftState generateSpacecraftState() {
  221.         return new SpacecraftState(generateKeplerianOrbit(), getMass());
  222.     }

  223.     /** Generate TLE from OMM file. Launch Year, Launch Day and Launch Piece are not present in the
  224.      * OMM file, they have to be set manually by the user with the AdditionalData static class.
  225.      * @return the tle
  226.      */
  227.     public TLE generateTLE() {
  228.         return new TLE(noradID, classificationType,
  229.                        metaData.getLaunchYear(), metaData.getLaunchNumber(), metaData.getLaunchPiece(),
  230.                        ephemerisType, Integer.parseInt(elementSetNo), getEpoch(),
  231.                        meanMotion, meanMotionDot, meanMotionDotDot,
  232.                        getE(), getI(), getPa(), getRaan(), getAnomaly(), revAtEpoch,
  233.                        bStar, getDataContext().getTimeScales().getUTC());
  234.     }

  235.     public static class OMMMetaData extends ODMMetaData {

  236.         /** Description of the Mean Element Theory. Indicates the proper method to employ
  237.          * to propagate the state. */
  238.         private String meanElementTheory;

  239.         /** Create a new meta-data.
  240.          * @param ommFile OMM file to which these meta-data belongs
  241.          */
  242.         OMMMetaData(final OMMFile ommFile) {
  243.             super(ommFile);
  244.         }

  245.         /** Get the description of the Mean Element Theory.
  246.          * @return the mean element theory
  247.          */
  248.         public String getMeanElementTheory() {
  249.             return meanElementTheory;
  250.         }

  251.         /** Set the description of the Mean Element Theory.
  252.          * @param meanElementTheory the mean element theory to be set
  253.          */
  254.         void setMeanElementTheory(final String meanElementTheory) {
  255.             this.meanElementTheory = meanElementTheory;
  256.         }

  257.     }

  258. }