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

Author: Alex Reynolds
*/
/*
Metadata for MS GUI:
imdata = {"displayname" : "Frame State Sensor",
          "exclude" : False, 
          "category" : "Sensors"
}
aliases = {"target_frame_ptr" : "Frame A",
           "reference_frame_ptr" : "Frame B",
           "output_frame_ptr" : "EXCLUDE",
           "pos_tgt_ref__out" : "Position A wrt B",
           "vel_tgt_ref__out" : "Velocity A in B",
           "vel_tgt_ref_inertial__out" : "EXCLUDE",
           "att_tgt_ref" : "Attitude A wrt B",
           "omega_tgt_ref__out" : "Ang. Vel. A wrt B"
}
*/

#ifndef MODELS_STATES_FRAME_STATE_SENSOR_MODEL_H
#define MODELS_STATES_FRAME_STATE_SENSOR_MODEL_H

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

namespace warptwin {

    /**
     * @brief   Model for sensing the relative state between two frames in WarpTwin
     * 
     * The frame state sensor model senses the relative state between two
     * frames and outputs that state difference as represented in a third,
     * output frame. It applies basic kinematics using base functions 
     * developed in the clockwerk module to generate a step-by-step difference 
     * between two frames.
     * 
     * The results output by this model can be described as
     * "the state of target_frame relative to reference_frame as output in 
     *  output_frame coordinates"
    */
    MODEL(FrameStateSensorModel)
    public:
        // Model params
        //         NAME                     TYPE                    DEFAULT VALUE
        START_PARAMS
            /** The target_frame is the frame state we are sensing -- we want to 
              * know where target_frame is */
            SIGNAL(target_frame_ptr,        Frame*,                nullptr) 
            /** The reference_frame is the frame relative to which we are sensing.
              * Results are output relative to the reference frame, in either 
              * reference frame or output frame coordinates. */
            SIGNAL(reference_frame_ptr,     Frame*,                nullptr)
            /** The output_frame is the frame in which the output results are
             *  represented. If it is set to nullptr, reference_frame is used.
             *  Not used for attitude. */
            SIGNAL(output_frame_ptr,        Frame*,                nullptr)
        END_PARAMS

        // Model inputs
        //         NAME                     TYPE                    DEFAULT VALUE
        START_INPUTS

        END_INPUTS

        // Model outputs
        //         NAME                     TYPE                    DEFAULT VALUE
        START_OUTPUTS
            /** This is the position of the target frame origin wrt the reference frame origin,
              * output in output frame coordinates */
            SIGNAL(pos_tgt_ref__out,        CartesianVector3,      CartesianVector3({0.0, 0.0, 0.0}))
            /** This is the velocity of our target frame origin as represented IN the reference
             *  frame. It is NOT simply the difference in the velocities of their origins, which
             *  is different. This value accounts for reference frame rotation. Output is in output coordinates */
            SIGNAL(vel_tgt_ref__out,        CartesianVector3,      CartesianVector3({0.0, 0.0, 0.0}))
            /** This is the inertial velocity of our target frame origin relative to our reference
             *  frame origin, represented in output frame coordinates. It is an inertial differencing
             *  of the origins represented in reference, and does not account for reference rotation. */
            SIGNAL(vel_tgt_ref_inertial__out,CartesianVector3,     CartesianVector3({0.0, 0.0, 0.0}))
            /** This is the attitude of the target frame relative to the reference frame */
            SIGNAL(att_tgt_ref,             clockwerk::Quaternion, clockwerk::Quaternion({1.0, 0.0, 0.0, 0.0}))
            /** This is the angular velocity of the target frame wrt the reference frame, output in
              * output frame coordinates */
            SIGNAL(omega_tgt_ref__out,      CartesianVector3,      CartesianVector3({0.0, 0.0, 0.0}))
        END_OUTPUTS

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

        // DCM relating our reference frame to our root frame
        clockwerk::DCM _dcm_tmp;

        CartesianVector3 _tmp_tgt;
    };
}

#endif