DateBasedManeuverTriggers.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.forces.maneuvers.trigger;

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

  21. import org.hipparchus.CalculusFieldElement;
  22. import org.hipparchus.Field;
  23. import org.orekit.propagation.events.EventDetectionSettings;
  24. import org.orekit.propagation.events.FieldEventDetectionSettings;
  25. import org.orekit.propagation.events.FieldEventDetector;
  26. import org.orekit.propagation.events.FieldParameterDrivenDateIntervalDetector;
  27. import org.orekit.propagation.events.ParameterDrivenDateIntervalDetector;
  28. import org.orekit.time.AbsoluteDate;
  29. import org.orekit.utils.ParameterDriver;

  30. /** Maneuver triggers based on a start and end date.
  31.  * @author Maxime Journot
  32.  * @since 10.2
  33.  */
  34. public class DateBasedManeuverTriggers extends IntervalEventTrigger<ParameterDrivenDateIntervalDetector> {

  35.     /** Default name for trigger. */
  36.     public static final String DEFAULT_NAME = "";

  37.     /** Name of the trigger (used as prefix for start and stop parameters drivers). */
  38.     private final String name;

  39.     /** Simple constructor.
  40.      * @param date start (or end) data of the maneuver
  41.      * @param duration maneuver duration (if positive, maneuver is from date to date + duration,
  42.      * if negative, maneuver will be from date - duration to date)
  43.      */
  44.     public DateBasedManeuverTriggers(final AbsoluteDate date, final double duration) {
  45.         this(DEFAULT_NAME, date, duration);
  46.     }

  47.     /** Simple constructor.
  48.      * @param name name of the trigger (used as prefix for start and stop parameters drivers)
  49.      * @param date start (or end) data of the maneuver
  50.      * @param duration maneuver duration (if positive, maneuver is from date to date + duration,
  51.      * if negative, maneuver will be from date - duration to date)
  52.      * @since 11.1
  53.      */
  54.     public DateBasedManeuverTriggers(final String name, final AbsoluteDate date, final double duration) {
  55.         this(name, date, duration, ParameterDrivenDateIntervalDetector.getDefaultDetectionSettings(date, date.shiftedBy(duration)));
  56.     }

  57.     /** Simple constructor.
  58.      * @param name name of the trigger (used as prefix for start and stop parameters drivers)
  59.      * @param date start (or end) data of the maneuver
  60.      * @param duration maneuver duration (if positive, maneuver is from date to date + duration,
  61.      * if negative, maneuver will be from date - duration to date)
  62.      * @param detectionSettings date detection settings (warning: choose with care, as poor settings might miss the maneuver)
  63.      * @since 13.0
  64.      */
  65.     public DateBasedManeuverTriggers(final String name, final AbsoluteDate date, final double duration,
  66.                                      final EventDetectionSettings detectionSettings) {
  67.         super(createDetector(name, date, duration, detectionSettings));
  68.         this.name = name;
  69.     }

  70.     /** Create a date detector from one boundary and signed duration.
  71.      * @param prefix for start and stop parameters drivers
  72.      * @param date start (or end) data of the maneuver
  73.      * @param duration maneuver duration (if positive, maneuver is from date to date + duration,
  74.      * if negative, maneuver will be from date - duration to date)
  75.      * @param detectionSettings event detection settings
  76.      * @return date detector
  77.      * @since 13.0
  78.      */
  79.     private static ParameterDrivenDateIntervalDetector createDetector(final String prefix, final AbsoluteDate date,
  80.                                                                       final double duration,
  81.                                                                       final EventDetectionSettings detectionSettings) {
  82.         if (duration >= 0) {
  83.             return new ParameterDrivenDateIntervalDetector(prefix, date, date.shiftedBy(duration)).
  84.                     withDetectionSettings(detectionSettings);
  85.         } else {
  86.             return new ParameterDrivenDateIntervalDetector(prefix, date.shiftedBy(duration), date).
  87.                     withDetectionSettings(detectionSettings);
  88.         }
  89.     }

  90.     /** {@inheritDoc} */
  91.     @Override
  92.     public String getName() {
  93.         return name;
  94.     }

  95.     /** Get the start date.
  96.      * @return the start date
  97.      */
  98.     public AbsoluteDate getStartDate() {
  99.         return getFiringIntervalDetector().getStartDriver().getDate();
  100.     }

  101.     /** Get the end date.
  102.      * @return the end date
  103.      */
  104.     public AbsoluteDate getEndDate() {
  105.         return getFiringIntervalDetector().getStopDriver().getDate();
  106.     }

  107.     /** Get the duration of the maneuver (s).
  108.      * duration = endDate - startDate
  109.      * @return the duration of the maneuver (s)
  110.      */
  111.     public double getDuration() {
  112.         return getEndDate().durationFrom(getStartDate());
  113.     }

  114.     /** {@inheritDoc} */
  115.     @Override
  116.     protected <D extends FieldEventDetector<S>, S extends CalculusFieldElement<S>> D convertIntervalDetector(final Field<S> field,
  117.                                                                                                              final ParameterDrivenDateIntervalDetector detector) {

  118.         final FieldParameterDrivenDateIntervalDetector<S> fd =
  119.                         new FieldParameterDrivenDateIntervalDetector<>(field, "",
  120.                                         detector.getStartDriver().getBaseDate(),
  121.                                         detector.getStopDriver().getBaseDate())
  122.                                 .withDetectionSettings(new FieldEventDetectionSettings<>(field, detector.getDetectionSettings()));
  123.         fd.getStartDriver().setName(detector.getStartDriver().getName());
  124.         fd.getStopDriver().setName(detector.getStopDriver().getName());
  125.         fd.getMedianDriver().setName(detector.getMedianDriver().getName());
  126.         fd.getDurationDriver().setName(detector.getDurationDriver().getName());

  127.         @SuppressWarnings("unchecked")
  128.         final D converted = (D) fd;
  129.         return converted;

  130.     }

  131.     /** {@inheritDoc} */
  132.     @Override
  133.     public List<ParameterDriver> getParametersDrivers() {
  134.         return Collections.unmodifiableList(Arrays.asList(getFiringIntervalDetector().getStartDriver(),
  135.                                                           getFiringIntervalDetector().getStopDriver(),
  136.                                                           getFiringIntervalDetector().getMedianDriver(),
  137.                                                           getFiringIntervalDetector().getDurationDriver()));
  138.     }
  139. }