![]() |
WarpTwin
Documentation for WarpTwin models and classes.
|
/******************************************************************************
* 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.
******************************************************************************/
/*
Reaction wheel model header file
Author: Alex Jackson
*/
/*
Metadata for MS GUI:
imdata = {"displayname" : "Torque Coil",
"exclude" : False,
"category" : "Actuators"
}
aliases = {"sc_body" : "Spacecraft Body",
"torque_vector__body" : "Torque Vector",
"current_noise_std" : "Noise",
"seed_value" : "EXCLUDE",
"area" : "Area",
"mom_inertia" : "Moment of Inertia",
"loops" : "Number of Loops",
"misalignment_std" : "Misalignment",
"input_current" : "Input Current",
"mag_field_vec__NED" : "Mag Field Vec",
"power_draw" : "Power Draw",
"applied_torque_body__body" : "Applied Torque",
}
*/
#ifndef MODELS_ACTUATORS_TORQUE_COIL_MODEL_H
#define MODELS_ACTUATORS_TORQUE_COIL_MODEL_H
#include "simulation/Model.h"
#include "core/CartesianVector.hpp"
#include "frames/Joint.h"
#include "models/support/BiasNoiseModel.h"
namespace warptwin {
/**
* @brief Torque Coil Model
*
* This is a model of a torque coil which applies a torque using the magnetic field
* generated by an electromagnet (with no ferromagnetic core) interacting with the Earth's
* magnetic field. A positive torque is applied about the torque vector when a positive
* current is applied. Note that this direction is the orthogonal vector (Area Vector) of
* the wire coil.
*
* Noise is applied as a gaussian noise about the commanded current.
*
* @author Alex Jackson <alex.jackson@attx.tech>
*/
MODEL(TorqueCoilModel)
public:
// Model params
// NAME TYPE DEFAULT VALUE
START_PARAMS
/** The body which will be controlled by this model. The torque will be applied to a
* node aligned to this body, and WarpTwin will translate to torque at the body */
SIGNAL(sc_body, Body*, nullptr)
/** The frame in which the magnetic field vector is expressed. This is most
* typically the magnetometer frame */
SIGNAL(mag_frame, Frame*, nullptr)
/** The torque coil vector wrt the body frame. This is the area vector of the torque coil
* that a positive torque is applied about */
SIGNAL(torque_vector__body, CartesianVector3, CartesianVector3({1.0, 0.0, 0.0}))
/** The standard deviation of input current noise. A new noise
* draw is taken at each timestep. */
SIGNAL(current_noise_std, double, 0.0)
/** Value to seed the internal RNG for this model. */
SIGNAL(seed_value, int, 0)
/** The area inside the loop (m^2) */
SIGNAL(area, double, 1.0)
/** Number of loops of wire in the torque coil */
SIGNAL(loops, double, 1.0)
/** The standard deviation of the misalignment angle (degrees) */
SIGNAL(misalignment_std, double, 0.0)
/** The resistance of the torque coil in Ohms */
SIGNAL(resistance, double, 0.0)
/** The idle power draw of the torque coil when operational in Watts */
SIGNAL(idle_power, double, 0.0)
END_PARAMS
// Model inputs
// NAME TYPE DEFAULT VALUE
START_INPUTS
/** The input current in Amps. Positive current creates a positive torque about the torque vector*/
SIGNAL(input_current, double, 0.0)
/** The external magnetic field vector in the mag frame (nanoTesla) */
SIGNAL(mag_field_vec__mag, CartesianVector3, CartesianVector3({1.0, 0.0, 0.0}))
END_INPUTS
// Model outputs
// NAME TYPE DEFAULT VALUE
START_OUTPUTS
/** The power draw of the reaction wheel in Watts */
SIGNAL(power_draw, double, 0.0)
/** The torque applied to the body in the body frame in N-m*/
SIGNAL(applied_torque_body__body, CartesianVector3, CartesianVector3({0.0, 0.0, 0.0}))
END_OUTPUTS
int16 activate() override;
int16 deactivate() override;
protected:
int16 start() override;
int16 execute() override;
/// @brief The bias and noise model for current.
BiasNoiseModel _current_bias_noise;
/// @brief The torque coil node.
Node _coil_node;
/// @brief Value to hold perturbation to current command
double _perturbation = 0.0;
/// @brief Value to hold total torque calculation
CartesianVector3 _torque_vec;
/// @brief Vector to hold temporary axes during orientation calculation
CartesianVector3 _z_axis;
/// @brief Temporary DCM for quaternion calculation
clockwerk::DCM _DCM_Body_Mag;
/// @brief Misalignment angle
double _misalignment_x = 0.0;
double _misalignment_y = 0.0;
double _misalignment_z = 0.0;
/// @brief Temporary quaternion for misalignment calculation
clockwerk::Quaternion _tempQuat;
/// @brief Misalignment angle magnitude and unit vector
double _theta = 0.0;
CartesianVector3 _evec;
/// @brief Temporary DCM for magnetic field transformation
CartesianVector3 _mag_field_vec_body;
};
}
#endif