WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
GravityGradientModel.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.
******************************************************************************/
/*
Gravity gradient torque model header file

Author: Sam Matez
*/
/*
Metadata for MS GUI:
imdata = {"displayname" : "Gravity Gradient Torque",
          "exclude" : False,
          "category" : "Dynamics"
}
aliases = {"mu" : "GM",
           "pos_body_pci" : "Position",
           "quat_body_pci" : "Attitude",
           "inertiatensor_body_body" : "Spacecraft Inertia",
           "ggTorque_body_body" : "Gravity Torque"
}
*/

#ifndef MODELS_ENVIRONMENT_GRAVITY_GRADIENT_MODEL_H 
#define MODELS_ENVIRONMENT_GRAVITY_GRADIENT_MODEL_H

#include "frames/Body.h"
#include "frames/frameutils.h"
#include "simulation/Model.h"
#include "constants/planetdefaults.h"

namespace warptwin {

    /**
     * @brief   Gravity Gradient Model
     * 
     * This model calculates the gravity gradient torque force 
     * resulting from differences in axial inertia on a spacecraft.
     * The equations used for this calculation come from "Analytical
     * Mechanics of Space Systems (Fourth Edition), by Hanspeter
     * Schaub and John L. Junkins", page 226 (eq. 4.158). The gravity
     * gradient torque calculation is done in the body frame (Body
     * frame position and inertia).
     * 
     * Author: Sam Matez
     * Email: sam.matez@attx.tech
     * 
    */
    MODEL(GravityGradientModel)
    public:
        // Model params
        //         NAME                     TYPE                    DEFAULT VALUE
        START_PARAMS
            /** This is the gravitational parameter of our parent planet. Defaults to
             * Earth's gravitational parameter for ease of use */
            SIGNAL(mu,                      double,                 warpos::earth_wgs84.mu)
        END_PARAMS

        // Model inputs
        //         NAME                     TYPE                    DEFAULT VALUE
        START_INPUTS
            /** The position of the body with respect to PCI frame, expressed in PCI coordinates */
            SIGNAL(pos_body_pci,            CartesianVector3,      CartesianVector3({0.0, 0.0, 0.0}))
            /** The attitude of the body with respect ot the PCI frame, in quaternions */
            SIGNAL(quat_body_pci,           clockwerk::Quaternion, clockwerk::Quaternion({1.0, 0.0, 0.0, 0.0}))
            /** The inertia tensor expressed in the body frame */
            SIGNAL(inertiatensor_body_body, Matrix3,                Matrix3({{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}))
        END_INPUTS

        // Model outputs
        //         NAME                     TYPE                    DEFAULT VALUE
        START_OUTPUTS
            /** The tourque vector acting on the body due to gravity gradient effects wrt to the body frame */
            SIGNAL(ggTorque_body_body,      CartesianVector3,      CartesianVector3({0.0, 0.0, 0.0}))
        END_OUTPUTS

    protected:
        // Execute in protected
        int16 execute() override; 

        // Temporary vectors and variables to carry out our calculations
        CartesianVector3 _pos_body_pci__body;
        double _r;
        double _multiplier;
        CartesianVector3 _ggTorque;

    };

}

#endif