Icarus
Vehicle Simulation as a Transformable Computational Graph, built on Vulcan and Janus
Loading...
Searching...
No Matches
icarus::PhysicalComponent< Scalar > Class Template Reference

Intermediate class for components with physical body attachment. More...

#include <PhysicalComponent.hpp>

Inheritance diagram for icarus::PhysicalComponent< Scalar >:
Collaboration diagram for icarus::PhysicalComponent< Scalar >:

Public Member Functions

bool HasBodyAttachment () const override
 Whether this component has a body attachment (position/orientation).
Vec3< Scalar > GetBodyPosition () const override
 Get the component's mounting position in vehicle body frame.
janus::Quaternion< Scalar > GetBodyOrientation () const override
 Get the component's mounting orientation (body-to-component rotation).
janus::Quaternion< Scalar > GetComponentToBodyRotation () const
 Get rotation from component frame to body frame.
Vec3< Scalar > TransformToBodyFrame (const Vec3< Scalar > &v_local) const
 Transform a vector from component local frame to body frame.
Vec3< Scalar > TransformToLocalFrame (const Vec3< Scalar > &v_body) const
 Transform a vector from body frame to component local frame.
Public Member Functions inherited from icarus::Component< Scalar >
virtual ~Component ()=default
virtual void Provision (Backplane< Scalar > &bp)=0
 Provision phase - called once at application launch.
virtual void Stage (Backplane< Scalar > &bp)=0
 Stage phase - called at start of each run/episode.
virtual void Step (Scalar t, Scalar dt)=0
 Step phase - called every time step (hot path!).
virtual void PreStep (Scalar, Scalar)
 Called before any component Steps (for pre-processing).
virtual void PostStep (Scalar, Scalar)
 Called after all component Steps (for post-processing).
virtual void OnError (const SimulationError &)
 Called when simulation encounters an error.
virtual void Shutdown ()
 Called during shutdown (cleanup, flush buffers).
virtual std::string Name () const =0
 Component instance name (e.g., "MainEngine").
virtual std::string Entity () const
 Entity namespace (e.g., "X15").
virtual std::string TypeName () const
 Component type name for data dictionary (e.g., "JetEngine").
std::string FullName () const
 Full qualified name: entity.component (or just component).
virtual std::vector< SignalDeclDeclareInputs () const
 Declared inputs (for documentation/dependency graph).
virtual std::vector< SignalDeclDeclareOutputs () const
 Declared outputs (for documentation/dependency graph).
std::vector< std::string > GetOutputNames () const
 Get list of output signal names.
std::vector< std::string > GetInputNames () const
 Get list of input signal names.
bool IsProvisioned () const
 Check if Provision has been called.
bool IsStaged () const
 Check if Stage has been called.
void SetConfig (ComponentConfig config)
 Set component configuration (called by factory after construction).
const ComponentConfigGetConfig () const
 Get component configuration.
const vulcan::time::Epoch< Scalar > * GetEpoch () const
 Get simulation epoch (read-only).

Protected Member Functions

void ReadAttachmentFromConfig ()
 Read body attachment from component config.
void SetBodyAttachment (const Vec3< Scalar > &position, const janus::Quaternion< Scalar > &orientation)
 Set body attachment programmatically (for testing or dynamic mounting).
void SetBodyPosition (const Vec3< Scalar > &position)
 Set body position only (orientation defaults to identity).
Protected Member Functions inherited from icarus::Component< Scalar >
template<typename T>
read_param (const std::string &key, const T &default_val) const
 Read a scalar config parameter with default.
template<typename T>
require_param (const std::string &key) const
 Read a required scalar config parameter (throws if missing).
Vec3< Scalar > read_param_vec3 (const std::string &key, const Vec3< Scalar > &default_val) const
 Read a Vec3 config parameter with automatic double→Scalar conversion.
Vec3< Scalar > require_param_vec3 (const std::string &key) const
 Read a required Vec3 config parameter (throws if missing).
Vec4< Scalar > read_param_vec4 (const std::string &key, const Vec4< Scalar > &default_val) const
 Read a Vec4 config parameter with automatic double→Scalar conversion.
Vec4< Scalar > require_param_vec4 (const std::string &key) const
 Read a required Vec4 config parameter (throws if missing).
void MarkProvisioned ()
void MarkStaged ()
void ResetStaged ()
void BindEpoch (const vulcan::time::Epoch< Scalar > *epoch)

Protected Attributes

Vec3< Scalar > body_position_ = Vec3<Scalar>::Zero()
 Mounting position in vehicle body frame [m].
janus::Quaternion< Scalar > body_orientation_
 Rotation from body frame to component local frame (identity by default).
bool has_body_attachment_ = false
 True after ReadAttachmentFromConfig() is called.

Detailed Description

template<typename Scalar>
class icarus::PhysicalComponent< Scalar >

Intermediate class for components with physical body attachment.

Components that have a physical presence on the vehicle (mass sources, force sources, sensors, actuators) should inherit from this class.

Provides:

  • Body position (mounting location in vehicle body frame)
  • Body orientation (rotation from body frame to component local frame)
  • Config parsing helper for both quaternion and Euler angle formats

Non-physical components (environment models, schedulers, etc.) should inherit directly from Component<Scalar>.

Configuration Format

Subclasses call ReadAttachmentFromConfig() in Stage() to parse:

body_position: [x, y, z] # meters, in body frame
# Option 1: Quaternion (w, x, y, z)
body_orientation: [1.0, 0.0, 0.0, 0.0] # identity rotation
# Option 2: Euler angles (ZYX order, degrees)
body_orientation_euler_zyx: [yaw, pitch, roll]

Orientation Convention

body_orientation represents the rotation FROM body frame TO component local frame (body-to-component).

CAD Interpretation: The Euler angles describe "how I rotated this component starting from alignment with body axes."

Frame Transformation:

  • To transform component outputs TO body frame: F_body = body_orientation.conjugate().rotate(F_local)
  • To transform body vectors TO component frame (e.g., sensors): v_local = body_orientation.rotate(v_body)

Example

A rocket engine with thrust along its local +X axis, mounted at body position [0, 0, 10] pointing along body -Z:

- type: RocketEngine
name: MainEngine
body_position: [0.0, 0.0, 10.0] # nozzle at z=10m
body_orientation_euler_zyx: [0.0, -90.0, 0.0] # pitch -90 deg -> +X -> -Z

The engine outputs force_local = [thrust, 0, 0]. Vehicle6DOF transforms: F_body = R.conjugate().rotate([thrust, 0, 0]) = [0, 0, -thrust]

Template Parameters
ScalarNumeric type (double or casadi::MX)

Member Function Documentation

◆ GetBodyOrientation()

template<typename Scalar>
janus::Quaternion< Scalar > icarus::PhysicalComponent< Scalar >::GetBodyOrientation ( ) const
inlinenodiscardoverridevirtual

Get the component's mounting orientation (body-to-component rotation).

Convention: Transforms vectors FROM body frame TO component local frame. To transform component outputs TO body frame, use conjugate().

Returns
Identity quaternion for components without attachment

Reimplemented from icarus::Component< Scalar >.

◆ GetBodyPosition()

template<typename Scalar>
Vec3< Scalar > icarus::PhysicalComponent< Scalar >::GetBodyPosition ( ) const
inlinenodiscardoverridevirtual

Get the component's mounting position in vehicle body frame.

Returns
Zero vector for components without attachment

Reimplemented from icarus::Component< Scalar >.

◆ GetComponentToBodyRotation()

template<typename Scalar>
janus::Quaternion< Scalar > icarus::PhysicalComponent< Scalar >::GetComponentToBodyRotation ( ) const
inlinenodiscard

Get rotation from component frame to body frame.

This is the inverse of GetBodyOrientation() and is commonly needed to transform component outputs (forces, moments) to body frame.

Returns
Quaternion that transforms component vectors to body frame

◆ HasBodyAttachment()

template<typename Scalar>
bool icarus::PhysicalComponent< Scalar >::HasBodyAttachment ( ) const
inlinenodiscardoverridevirtual

Whether this component has a body attachment (position/orientation).

Returns
false for base Component; overridden in PhysicalComponent

Reimplemented from icarus::Component< Scalar >.

◆ ReadAttachmentFromConfig()

template<typename Scalar>
void icarus::PhysicalComponent< Scalar >::ReadAttachmentFromConfig ( )
inlineprotected

Read body attachment from component config.

Call this in Stage() to parse body_position and body_orientation from the component's YAML configuration.

Supports two orientation formats:

  • body_orientation: [w, x, y, z] - quaternion
  • body_orientation_euler_zyx: [yaw, pitch, roll] - Euler angles (degrees)

If neither orientation is specified, defaults to identity (no rotation). If body_position is not specified, defaults to origin [0, 0, 0].

Convention Note: The YAML config uses body_orientation_euler_zyx: [yaw, pitch, roll] (degrees, aerospace order), but Janus from_euler() expects (roll, pitch, yaw) (radians). This method handles the conversion.

Precondition
GetConfig() returns valid ComponentConfig
Postcondition
has_body_attachment_ is true

◆ SetBodyAttachment()

template<typename Scalar>
void icarus::PhysicalComponent< Scalar >::SetBodyAttachment ( const Vec3< Scalar > & position,
const janus::Quaternion< Scalar > & orientation )
inlineprotected

Set body attachment programmatically (for testing or dynamic mounting).

Parameters
positionPosition in vehicle body frame [m]
orientationRotation from body to component frame

◆ SetBodyPosition()

template<typename Scalar>
void icarus::PhysicalComponent< Scalar >::SetBodyPosition ( const Vec3< Scalar > & position)
inlineprotected

Set body position only (orientation defaults to identity).

Parameters
positionPosition in vehicle body frame [m]

◆ TransformToBodyFrame()

template<typename Scalar>
Vec3< Scalar > icarus::PhysicalComponent< Scalar >::TransformToBodyFrame ( const Vec3< Scalar > & v_local) const
inlinenodiscard

Transform a vector from component local frame to body frame.

Parameters
v_localVector in component local frame
Returns
Vector in body frame

◆ TransformToLocalFrame()

template<typename Scalar>
Vec3< Scalar > icarus::PhysicalComponent< Scalar >::TransformToLocalFrame ( const Vec3< Scalar > & v_body) const
inlinenodiscard

Transform a vector from body frame to component local frame.

Parameters
v_bodyVector in body frame
Returns
Vector in component local frame

Member Data Documentation

◆ body_orientation_

template<typename Scalar>
janus::Quaternion<Scalar> icarus::PhysicalComponent< Scalar >::body_orientation_
protected

Rotation from body frame to component local frame (identity by default).

◆ body_position_

template<typename Scalar>
Vec3<Scalar> icarus::PhysicalComponent< Scalar >::body_position_ = Vec3<Scalar>::Zero()
protected

Mounting position in vehicle body frame [m].

◆ has_body_attachment_

template<typename Scalar>
bool icarus::PhysicalComponent< Scalar >::has_body_attachment_ = false
protected

True after ReadAttachmentFromConfig() is called.


The documentation for this class was generated from the following file: