OMMFile.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.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.errors.OrekitException;
  23. import org.orekit.orbits.CartesianOrbit;
  24. import org.orekit.orbits.KeplerianOrbit;
  25. import org.orekit.orbits.PositionAngle;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.propagation.analytical.tle.TLE;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  213.     /** Generate a {@link CartesianOrbit} from the {@link KeplerianOrbit}.
  214.      * @return the {@link CartesianOrbit} generated from the OPM information
  215.      * @throws OrekitException if the Keplerian Orbit cannot be generated
  216.      */
  217.     public CartesianOrbit generateCartesianOrbit() throws OrekitException {
  218.         return new CartesianOrbit(generateKeplerianOrbit());
  219.     }

  220.     /** Generate spacecraft state from the {@link KeplerianOrbit} generated by generateKeplerianOrbit.
  221.      *  Raises an exception if OMM doesn't contain spacecraft mass information.
  222.      * @return the spacecraft state of the OMM
  223.      * @exception OrekitException if there is no spacecraft mass associated with the OMM
  224.      */
  225.     public SpacecraftState generateSpacecraftState()
  226.         throws OrekitException {
  227.         return new SpacecraftState(generateKeplerianOrbit(), getMass());
  228.     }

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

  240.     public static class OMMMetaData extends ODMMetaData {

  241.         /** Description of the Mean Element Theory. Indicates the proper method to employ
  242.          * to propagate the state. */
  243.         private String meanElementTheory;

  244.         /** Create a new meta-data.
  245.          * @param ommFile OMM file to which these meta-data belongs
  246.          */
  247.         OMMMetaData(final OMMFile ommFile) {
  248.             super(ommFile);
  249.         }

  250.         /** Get the description of the Mean Element Theory.
  251.          * @return the mean element theory
  252.          */
  253.         public String getMeanElementTheory() {
  254.             return meanElementTheory;
  255.         }

  256.         /** Set the description of the Mean Element Theory.
  257.          * @param meanElementTheory the mean element theory to be set
  258.          */
  259.         void setMeanElementTheory(final String meanElementTheory) {
  260.             this.meanElementTheory = meanElementTheory;
  261.         }

  262.     }

  263. }