WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
SpacecraftLinkModel.h
/******************************************************************************
* Copyright (c) ATTX INC 2025. All Rights Reserved.
*
* This software and associated documentation (the "Software") are the 
* proprietary and confidential information of ATTX INC. The Software is 
* furnished under a license agreement between ATTX and the user organization 
* and may be used or copied only in accordance with the terms of the agreement.
* Refer to 'license/attx_license.adoc' for standard license terms.
*
* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION 
* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or 
* transmitted in any form or by any means, for any purpose, without the express 
* written permission of ATTX INC.
******************************************************************************/
/*
Spacecraft link model header file

Author: Alex Reynolds
*/
/*
Metadata for MS GUI:
imdata = {"displayname" : "Spacecraft Link",
          "exclude" : False,
          "category" : "Assemblies"
}
aliases = {"sc_1_frame" : "Spacecraft 1 Body",
           "sc_2_frame" : "Spacecraft 2 Body",
           "r_planet" : "Planet Equatorial Radius",
           "planet_frame" : "Planet Frame",
           "max_range" : "Max Range (m)",
           "max_range_rate" : "Max Range Rate (m/s)",
           "max_az_look_angle" : "EXCLUDE",
           "max_el_look_angle" : "EXCLUDE",
           "range" : "Range",
           "range_rate" : "Range Rate",
           "visible" : "Visible",
           "sc_1_az_look_angle" : "EXCLUDE",
           "sc_1_el_look_angle" : "EXCLUDE",
}
*/

#ifndef MODELS_STATES_SPACECRAFT_LINK_MODEL_H
#define MODELS_STATES_SPACECRAFT_LINK_MODEL_H

#include "FrameStateSensorModel.h"
#include "RangeAzElSensorModel.h"
#include "models/environment/OccultationModel.h"
#include "constants/planetdefaults.h"

namespace warptwin {

    /**
     * @brief   Simple spacecraft-to-spacecraft link model
     * 
     * This is a simple model of a spacecraft to spacecraft link. It performs calculations
     * and determines the relative states of two spacecraft and, if link conditions on range, 
     * range rate, occultation, and look angle are met, calculates the link between them. 
     * 
     * This model assumes the boresight vector for the spacecraft-to-spacecraft link is the
     * spacecraft frame +Y vector, in keeping with the convention maintained by the 
     * RangeAzElSensorModel and ground station sensor. See that model for more details
     * on azimuth and elevation definition.
    */
    MODEL(SpacecraftLinkModel)
    public:
        // Model params
        //         NAME                     TYPE                    DEFAULT VALUE
        START_PARAMS
            /** The frame of the first spacecraft in the spacecraft to spacecraft link.
             *  This is the spacecraft which receives az/el masking and, when configured,
             *  must point at the target spacecraft (sc2). */
            SIGNAL(sc_1_frame,              Frame*,                 nullptr)
            /** The frame of the second spacecraft in the spacecraft to spacecraft link */
            SIGNAL(sc_2_frame,              Frame*,                 nullptr)
            /** The planet rotating or inertial frame which is used in the internal
             *  link occultation model. */
            SIGNAL(planet_frame,            Frame*,                 nullptr)
            /** Planet radius in m (default is Earth radius) */
            SIGNAL(r_planet,                double,                 warpos::earth_wgs84.eq_radius)
            /** The maximum range at which link can be achieved. Default is an arbitrarily
             *  large distance, indicating no range restriction.*/
            SIGNAL(max_range,               double,                 warpos::AU_TO_METERS)
            /** The maximum range rate at which link can be achieved. Default is an arbitrarily
             *  large relative velocity, indicating no range rate restriction.*/
            SIGNAL(max_range_rate,          double,                 warpos::AU_TO_METERS)
            /** The maximum azimuth look angle between spacecraft 1's boresight vector and
             *  the other spacecraft for link to be achieved. In RADIANS. 
             *  The default is arbitrarily large angle with no look angle requirement. */
            SIGNAL(max_az_look_angle,        double,                 warpos::TWO_PI)
            /** The maximum elevation look angle between spacecraft 1's boresight vector and
             *  the other spacecraft for link to be achieved. In RADIANS. 
             *  The default is arbitrarily large angle with no look angle requirement. */
            SIGNAL(max_el_look_angle,        double,                 warpos::TWO_PI)
        END_PARAMS

        // Model inputs
        //         NAME                     TYPE                    DEFAULT VALUE
        START_INPUTS

        END_INPUTS

        // Model outputs
        //         NAME                     TYPE                    DEFAULT VALUE
        START_OUTPUTS
            /** This is the range between the two spacecraft. Will be zero if not visible. */
            SIGNAL(range,                   double,                 0.0)
            /** This is the range rate between the two spacecraft. Will be zero if not visible. */
            SIGNAL(range_rate,              double,                 0.0)
            /** This is the azimuth look angle between sc1's boresight and sc2. Will be zero if not visible. */
            SIGNAL(sc_1_az_look_angle,      double,                 0.0)
            /** This is the elevation look angle between sc1's boresight and sc2. Will be zero if not visible. */
            SIGNAL(sc_1_el_look_angle,      double,                 0.0)
            /** This is the link indicator flag for the two spaecraft. True for visible, False for not visible. */
            SIGNAL(visible,                 bool,                   false)
        END_OUTPUTS

    protected:
        int16 start() override;
        int16 execute() override; 

        // The range, azimuth, elevation look angle for both spacecraft
        RangeAzElSensorModel _range_az_el_sensor;

        // Occultation model used internally
        OccultationModel _oc;

        // Temporary/local variables to hold intermediate calculations
        clockwerk::Quaternion _sc_quat_tmp_root;
        CartesianVector3 _sc_pos_tmp__root;
        CartesianVector3 _sc_vel_tmp__root;
        CartesianVector3 _sc_pos_tmp__sc;
        CartesianVector3 _sc_vel_tmp__sc;
    };
}

#endif