Program Listing for File Defs.h

Program Listing for File Defs.h#

Return to documentation for file (include/Karana/SOADyn/Defs.h)

/*
 * Copyright (c) 2024-2026 Karana Dynamics Pty Ltd. All rights reserved.
 *
 * NOTICE TO USER:
 *
 * This source code and/or documentation (the "Licensed Materials") is
 * the confidential and proprietary information of Karana Dynamics Inc.
 * Use of these Licensed Materials is governed by the terms and conditions
 * of a separate software license agreement between Karana Dynamics and the
 * Licensee ("License Agreement"). Unless expressly permitted under that
 * agreement, any reproduction, modification, distribution, or disclosure
 * of the Licensed Materials, in whole or in part, to any third party
 * without the prior written consent of Karana Dynamics is strictly prohibited.
 *
 * THE LICENSED MATERIALS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
 * KARANA DYNAMICS DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, AND
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * IN NO EVENT SHALL KARANA DYNAMICS BE LIABLE FOR ANY DAMAGES WHATSOEVER,
 * INCLUDING BUT NOT LIMITED TO LOSS OF PROFITS, DATA, OR USE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, WHETHER IN CONTRACT, TORT,
 * OR OTHERWISE ARISING OUT OF OR IN CONNECTION WITH THE LICENSED MATERIALS.
 *
 * U.S. Government End Users: The Licensed Materials are a "commercial item"
 * as defined at 48 C.F.R. 2.101, and are provided to the U.S. Government
 * only as a commercial end item under the terms of this license.
 *
 * Any use of the Licensed Materials in individual or commercial software must
 * include, in the user documentation and internal source code comments,
 * this Notice, Disclaimer, and U.S. Government Use Provision.
 */

/**
 * @file
 * @brief Contains the enum and struct defnitions for the SOADyn classes
 */

#pragma once

#include "Karana/Math/Defs.h"
#include "Karana/Scene/Color.h"
#include "Karana/Scene/Layer.h"

namespace Karana::Dynamics {

    // namespace kc = Karana::Core;
    // namespace kf = Karana::Frame;
    namespace km = Karana::Math;
    namespace ks = Karana::Scene;

    /** @brief Enums for the pre-defined and known hinge types */
    enum class HingeType {
        LOCKED,        //!< locked subhinge, no relative motion permitted
        REVOLUTE,      //!< 1 dof hinge with a single SubhingeBase::SubhingeType::PIN
                       //!< subhinge
        UJOINT,        //!< 2 dof hinge with 2 successive
                       //!< SubhingeBase::SubhingeType::PIN subhinges
        GIMBAL,        //!< 3 dof hinge with 2 successive
                       //!< SubhingeBase::SubhingeType::PIN subhinges
        BALL,          //!< 3 dof hinge with 1 SubhingeBase::SubhingeType::SPHERICAL
                       //!< subhinge
        BALL_QUAT,     //!< 3 dof hinge with 1
                       //!< SubhingeBase::SubhingeType::SPHERICAL_QUAT subhinge
        SLIDER,        //!< 1 dof hinge with 1 SubhingeBase::SubhingeType::LINEAR
                       //!< subhinge
        PLANAR,        //!< 2 dof hinge with 2 successive
                       //!< SubhingeBase::SubhingeType::LINEAR subhinges
        TRANSLATIONAL, //!< 3 dof hinge with 3 successive
                       //!< SubhingeBase::SubhingeType::LINEAR subhinges
        FULL6DOF,      //!< 6 dof hinge with a SubhingeBase::SubhingeType::LINEAR3
                       //!< subhinge followed by a
                       // SubhingeBase::SubhingeType::SPHERICAL subhinge
        CYLINDRICAL,   //!< 2 dof hinge with a
                       //!< SubhingeBase::SubhingeType::LINEAR subhinge
                       //!< followed by a
                       //!< SubhingeBase::SubhingeType::PIN subhinge
        HELICAL,       //!< 1 dof hinge with a single
                       //!< SubhingeBase::SubhingeType::SCREW subhinge
        HOOKE,         //!< 2 dof hinge that keeps an outboard body frame's
                       //!< Y-axis perpendicular to an inboard body frame's
                       //!< X-axis. The subhinge sequence consists of a pair of
                       //!< SubhingeBase::SubhingeType::PIN
                       //!< subhinges. The hinge parameters can be computed using the
                       //!< HingeBase::getHookeHingeParams() method.
        INLINE,        //!< 4 dof hinge that keeps an outboard body frame's
                       //!< Z-axis constrained to translate along an inboard
                       //!< body frame's Z-axis. The subhinge sequence
                       //!< consists of a SubhingeBase::SubhingeType::LINEAR
                       //!< subhinge followed by a
                       //!< SubhingeBase::SubhingeType::SPHERICAL subhinge
                       //!< The hinge parameters can be computed using
                       //!< the HingeBase::getInlineHingeParams() method.
        INPLANE,       //!< 5 dof hinge that keeps an outboard body frame
                       //!< constrained to translate in an inboard body
                       //!< frame's XY plane. The subhinge sequence
                       //!< consists of a pair of
                       //!< SubhingeBase::SubhingeType::LINEAR subhinges
                       //!< followed by a !<
                       //!< SubhingeBase::SubhingeType::SPHERICAL subhinge.
                       //!< The hinge parameters can be computed using
                       //!< the HingeBase::getInplaneHingeParams() method.
        PERPENDICULAR, //!< 5 dof hinge that keeps an outboard body
                       //!< frame's Z-axis to remain perpendicular to an
                       //!< inboard body frame's Z-axis. The subhinge
                       //!< sequence consists of a
                       //!< SubhingeBase::SubhingeType::LINEAR3 subhinge
                       //!< followed by a pair of
                       //!< SubhingeBase::SubhingeType::PIN subhinges.  The
                       //!< hinge parameters can be computed using the
                       //!< HingeBase::getPerpendicularHingeParams() method.
        PARALLEL,      //!< 4 dof hinge that keeps an outboard frame's
                       //!< Z-axis to remain parallel to an inboard body
                       //!< frame's Z-axis. The subhinge sequence
                       //!< consists of a
                       //!< SubhingeBase::SubhingeType::LINEAR3 subhinge
                       //!< followed by a SubhingeBase::SubhingeType::PIN
                       //!< subhinge.  The hinge parameters can be computed
                       //!< using the HingeBase::getParallelHingeParams()
                       //!< method.
        CUSTOM,        //!<  hinge with user specified sequence of  subhinge types
        COMPOUND       //!<  hinge with a single
                       //!<  SubhingeBase::SubhingeType::COMPOUND subhinge
    };

    /** @brief The available subhinge types */
    enum class SubhingeType {
        LOCKED,         //!< 0 dof locked subhinge
        PIN,            //!< 1 dof rotation about an axis subhinge
        LINEAR,         //!< 1 dof translation along an axis subhinge
        LINEAR3,        //!< 3 dof general translational  subhinge
        SPHERICAL,      //!< 3 dof rotational subhinge (Karana::Math::RotationVector for Q)
        SPHERICAL_QUAT, //!< 3 dof rotational subhinge (Karana::Math::UnitQuaternion for Q)
        SCREW,          //!< 1 dof rotation and translation about and along an axis subhinge
        COMPOUND        //!< subhinge for a compound body
    };

    /** @brief The available bilateral constraint types */
    enum BilateralConstraintType : short {
        CUTJOINT_LOOP, //!< cutjoint loop constraint
        CONVEL_LOOP,   //!< convel loop constraint
        COORDINATE,    //!< coordinate constraint
        ALL,           //!< true for all bilateral constraint
    };

    /** @brief Enum with values to classify the reason for the termination of a
        step */
    enum class MMSolverType {
        TREE_DYNAMICS,           ///<  ATBI forward dynamics for a tree system
        TREE_AUGMENTED_DYNAMICS, ///< tree-augmented ATBI constrained forward dynamics
        KINEMATICS,              ///< kinematics simulation mode
        INVERSE_DYNAMICS,        ///< inverse dynamics for a tree system
        UNDEFINED,               ///< undefined solver type
    };

    /** @brief Enum with values to classify the reason for the termination of a
        step */
    enum class SpStatusEnum {
        UNKNOWN, ///< unknown
        // REACHED_HOP_END_TIME,      ///< reached normal termination of the current hop
        REACHED_END_TIME,              ///< normal termination, reached requested end time
        REACHED_TERMINATION_CONDITION, ///< premature termination since the termination
                                       ///< condition was met
        REACHED_ZERO_CROSSING,         ///< premature end on reaching zero-crossing condition
        FAILED_STEP_VALIDATION         ///< rolled back due to failing step validation check
    };

    /**
     * @brief A class used to tell whether the SubTree needs a state reset or not.
     */
    enum class NeedsStateReset {
        /// No reset needed. States are okay.
        NO_RESET_NEEDED,

        /// The numerics have changed, but the number of states remains the same.
        NUMERICS_CHANGED,

        /// The number of states has changed.
        NUM_STATES_CHANGED,
    };

    /** @brief Enum with values to classify the type of coordinate to
        freeze */
    enum class CKFrozenCoordType {
        Q,   ///< only the Q configuration coordinate
        U,   ///< only the U velocity coordinate
        Q_U, ///< both the Q configuration and U velocity coordinates
    };

    /** @brief struct for modal frequency domain analysis */
    struct ModalAnalysis {
        /// Modal frequencies
        km::Vec w;

        /// Modal shapes
        km::Mat phi;
    };

    /** @brief Parameters for creating stick parts geometry */
    struct StickPartsConfig {
        StickPartsConfig(){};
        ks::Color body_color = ks::Color::DARKMAGENTA;  //!< Body color
        ks::Color joint_color = ks::Color::ORANGERED;   //!< Subhinge axis color
        ks::Color constraint_color = ks::Color::RED;    //!< Constraint part color
        ks::Color sensor_node_color = ks::Color::GREEN; //!< Non-force node color
        ks::Color force_node_color = ks::Color::BLUE;   //!< Force node color
        float body_stick_radius = 0.02f;                //!< Radius for the body stick part cylinder
        float pin_hinge_length = 0.1f;     //!< Length of the pin subhinge axis cylinder
        float pin_hinge_radius = 0.05f;    //!< Radius of the pin subhinge axis cylinder
        float sphere_hinge_radius = 0.07f; //!< Radius of the spherical  subhinge axis cylinder
        float hinge_axes_length = 0.2f;    //!< Length of the pin subhinge axes
        float node_radius = 0.04f;         //!< Node sphere stick part radius
        ks::layer_t layers = ks::LAYER_STICK_FIGURE; //!< the scene layer type
    };

} // namespace Karana::Dynamics