WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
AerodynamicsStateModel.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.
******************************************************************************/
/*
Aerodynamics state model header file

Author: Mickey Mathew
*/
/* 
Metadata for MS GUI:
imdata = {"displayname" : "Aerodynamic State",
          "exclude" : False,
          "category" : "Dynamics"
}
aliases = {"aero_frame_ptr" : "Vehicle Frame",
           "velo_frame_ptr" : "Velocity Frame",
           "wind_frame_ptr" : "Wind Frame",
           "v_obj__velo" : "Vehicle Velocity",
           "v_wind__wind" : "Wind Velocity",
           "speed_of_sound" : "Speed of Sound",
           "v_aero__aero" : "EXCLUDE",
           "v_inf__aero" : "V infinity",
           "angle_of_attack" : "Angle of Attack",
           "sideslip_angle" : "Sideslip Angle",
           "airspeed" : "Magnitude of Velocity",
           "mach_number" : "Mach Number",
}
*/

#ifndef MODELS_STATES_AERODYNAMICS_STATE_MODEL_H
#define MODELS_STATES_AERODYNAMICS_STATE_MODEL_H

#include "simulation/Model.h" 
#include "frames/Frame.h"

namespace warptwin {

    /**
     * @brief   Aerodynamics State Model
     * 
     * This model calculates the common "vehicle relative" wind effects 
     * alpha, beta, mach, v_infinity, and airspeed on the vehicle in the 
     * vehicle "aerodynamics frame" which is defined for the purpose
     * of this model as follows:
     * - X points forward on the vehicle out the nose (generally in the direction of travel)
     * - Y points out the right wing of the vehicle
     * - Z points down
     * 
     * Such that the vehicle generally moves with positive velocity in x.
    */
    MODEL(AerodynamicsStateModel)
    public:
        // Model params
        //         NAME                     TYPE                    DEFAULT VALUE
        START_PARAMS
            /** The body frame state of the vehicle being analyzed */
            SIGNAL(aero_frame_ptr,          Frame*,                nullptr)
            /** The frame in which the input vehicle velocity is measured */
            SIGNAL(velo_frame_ptr,          Frame*,                nullptr) 
            /** The frame in which the wind velocity is measured */
            SIGNAL(wind_frame_ptr,          Frame*,                nullptr) 
        END_PARAMS

        // Model inputs
        //         NAME                     TYPE                    DEFAULT VALUE
        START_INPUTS
            /** The velocity of the object as measured in the velo frame -- for instance, velocity in ECEF */
            SIGNAL(v_obj__velo,             CartesianVector3,      CartesianVector3({0.0, 0.0, 0.0}))
            /** The velocity vector of the wind as measured in the wind frame -- for instance, wind in NED*/
            SIGNAL(v_wind__wind,            CartesianVector3,      CartesianVector3({0.0, 0.0, 0.0}))
            /** The speed of sound from the atmospheric model. Default value is 343.0 meters per second */
            SIGNAL(speed_of_sound,          double,                 343.0)
        END_INPUTS

        // Model outputs
        //         NAME                     TYPE                    DEFAULT VALUE
        START_OUTPUTS
            /** The velocity of the aerodynamics frame relative to the oncoming wind, in aero frame coords */
            SIGNAL(v_aero__aero,            CartesianVector3,      CartesianVector3({0.0, 0.0, 0.0}))
            /** The relative wind experienced by the aerodynamics frame in aerodynamics coordinates. Opposite of v_aero__aero */
            SIGNAL(v_inf__aero,             CartesianVector3,      CartesianVector3({0.0, 0.0, 0.0}))
            /** Angle between velocity vector and body x-axis in x–z plane */
            SIGNAL(angle_of_attack,         double,                  0.0)
            /** Angle between velocity vector and body x–z plane */
            SIGNAL(sideslip_angle,          double,                  0.0)
            /** Magnitude of air-relative velocity */
            SIGNAL(airspeed,                double,                  0.0)
            /** The ratio of the object's speed in relation to the speed of sound. */
            SIGNAL(mach_number,             double,                  0.0)
        END_OUTPUTS

    protected:
        int16 start() override;
        int16 execute() override;
        
        // Temporary vectors and variables to carry out our calculations
        CartesianVector3 _v_obj__aero;
        CartesianVector3 _v_wind__aero;
        double _safesqrtresult;
    };

}

#endif