FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
Auv.h
1#pragma once
2
482#include "AuvFoil.h"
483
484#include <fhsim/simobject/SimObject.h>
485#include <fhsim_environment/BodyFlowInteraction.h>
486#include <fhsim_environment/EnvironmentProvider.h>
487#include <fhsim_environment/WakeSourceSet.h>
488#include <string>
489
490class PrintDuringExec;
491
498{
499 double radius = 0.0;
500 double volume = 0.0;
501 double frontalArea = 0.0;
502 double mass = 0.0;
503 double ixx = 0.0;
504 double iyy = 0.0;
505 double izz = 0.0;
506};
507
513enum class AuvRudderPlane
514{
515 Dive,
516 Yaw
517};
518
521{
523 double rho = 1025.0;
524 double area = 0.016;
525 double pos[3] = {-0.85, 0.0, 0.0};
526 double maxDeflection = 0.35;
527};
528
529class Auv : public SimObject
530{
531public:
532 Auv(std::string simObjectName, ISimObjectCreator* creator);
533
540 ~Auv() override;
541
543 void OdeFcn(const double dT, const double* const adX, double* const adXDot) const override;
544
547
583 bool HasJacobians() const override;
584 void OdeJacobian(double T, const double* X, double* J, int nStates) override;
585 int GetJacobianSparsity(int nStates, int* rowPtr, int* colIdx) override;
586
636 bool HasPortJacobians() const override;
637 void InputPortJacobian(const std::string& portName, double T, const double* X,
638 double* dF_dInput, int portSize, int nStates) override;
639 void OutputPortJacobian(const std::string& portName, double T, const double* X,
640 double* dPort_dX, int portSize, int nStates, int index) override;
642
643 void FinalSetup(const double dT, const double* const adX, ISimObjectCreator* const creator) override;
644
646 void PreOdeFcn(double T, const double* X, IStateUpdater* updater) override;
647
658 static AuvHullProperties HullPropertiesOf(double length, double diameter, double averageDensity);
659
680 static double SubmergedFraction(double axisDepth, double radius);
681
699 static void AxialDragWrench(const double relVel_d[3], double rho, double frontalArea,
700 double axialDragCoeff, double wrench_d[6]);
701
703 static const int kSectionCount = 3;
704
714 static const double kCrossFlowSpeedEpsilon;
715
744 static void CrossFlowStripWrench(const double relVel_d[3], const double omega_d[3],
745 double rho, double crossFlowDragCoeff, int sectionCount, const double* sectionX,
746 const double* sectionDiameter, const double* sectionLength, double wrench_d[6]);
747
778 static void SlenderBodyLiftWrench(const double relVel_d[3], const double omega_d[3], double rho,
779 int sectionCount, const double* sectionX, const double* sectionDiameter,
780 const double* sectionLength, double wrench_d[6], double (*dWrench_dVelocity)[6] = nullptr);
781
792 static double RollDampingMoment(double rollRate, double linear, double quadratic);
793
801 static const double kInflowSpeedEpsilon;
802
820 static void RudderWrench(AuvRudderPlane plane, const double relVel_d[3], const double omega_d[3],
821 double deflection, const AuvRudderProperties& rudder, double wrench_d[6]);
822
852 static void RudderWrenchJacobian(AuvRudderPlane plane, const double relVel_d[3],
853 const double omega_d[3], double deflection, const AuvRudderProperties& rudder,
854 double dWrench_dVelocity[6][6], double dWrench_dDeflection[6]);
855
856#ifdef FH_VISUALIZATION
868 void RenderInit(Ogre::Root* const ogreRoot, ISimObjectCreator* const creator) override;
869
880 void RenderUpdate(const double dT, const double* const adX) override;
881#endif
882
883protected:
885 virtual void CalcFoundation(const double dT, const double* const adX);
886
888 virtual void AddExternalForces(const double dT, const double* const adX);
889
891 virtual void AddInternalForces(const double dT);
892
894 virtual void AddThrustForces(const double dT, const double* const adX);
895
897 virtual void AddHullHydroForces();
898
900 virtual void AddRudderForces(const double dT, const double* const adX);
901
911 void WarnIfTheFinsCannotDive(const std::string& simObjectName, double diveAngle) const;
912
915
926 virtual double ComputeThrust(double propulsionPower, double surgeSpeed) const;
927
929 double ClampedPropulsionPower(double commandedPower) const;
930
932 virtual void CalcDerivatives(double* const adXDot);
933
935 virtual void CalcOutput(const double dT, const double* const adX);
936
938 void CalcOutputCommon(const double dT, const double* const adX) const;
939
942 const double* OutPos(const double dT, const double* const adX);
943 const double* OutVel(const double dT, const double* const adX);
944 const double* OutQuater(const double dT, const double* const adX);
945 const double* OutEuler(const double dT, const double* const adX);
946 const double* OutHeading(const double dT, const double* const adX);
947 const double* OutPitch(const double dT, const double* const adX);
948 const double* OutDepth(const double dT, const double* const adX);
949 const double* OutSpeed(const double dT, const double* const adX);
950 const double* OutAltitude(const double dT, const double* const adX);
951 const double* OutSeaDepth(const double dT, const double* const adX);
952 const double* OutBattery(const double dT, const double* const adX);
953 const double* OutBatteryFraction(const double dT, const double* const adX);
954 const double* OutThrust(const double dT, const double* const adX);
956
957 // Geometry and mass, all derived from Length, Diameter and AverageDensity.
958 double m_length = 0.0;
960 double m_cOG[3];
961 double m_massInverse[6][6];
962 double m_rigidInertia[6];
963 double m_addedMass[6];
964 double m_rhoWater;
966
967 // Propulsion, drag and the hotel load.
971 double m_thrusterPos[3];
973
974 // Cross-flow strip theory and the roll damping it cannot supply.
981
982 // The fins. One set of properties serves both planes; they differ only in which
983 // transverse component of the inflow they see.
985
989 class AuvCaster final : public environment::wake::PropelledObject
990 {
991 public:
992 explicit AuvCaster(const Auv& auv)
993 : m_auv(auv)
994 {
995 }
996
998 environment::wake::WakeCastState Reference(const double* X) const override;
1000 void CurrentLoad(const double* X, const double freeStream[3], const double flowDir[3], double force[3], double& frontalArea,
1001 double rearCentre[3]) const override;
1003 environment::wake::PropellerJetInput PropellerJet(const double* X) const override;
1004
1005 private:
1006 const Auv& m_auv;
1007 };
1008
1009 environment::EnvironmentProvider* m_environment = nullptr;
1011 environment::wake::BodyFlowInteraction m_flow;
1012 double m_propellerDiameter = 0.0;
1013 double m_jetTime = 0.0;
1014 double m_jetCommandedPower = 0.0;
1015 double m_castRudderDive = 0.0;
1016 double m_castRudderYaw = 0.0;
1017 PrintDuringExec* m_print = nullptr;
1018
1019 // Input ports
1020 ISignalPort* m_inThrustPower = nullptr;
1021 ISignalPort* m_inRudderYaw = nullptr;
1022 ISignalPort* m_inRudderDive = nullptr;
1023 ISignalPort* m_inExternalForce = nullptr;
1024
1025 ICommonComputation* m_commonCalc = nullptr;
1026
1043 unsigned long m_IStatePos = 0;
1044 unsigned long m_IStateQuater = 0;
1045 unsigned long m_IStateLocalVel = 0;
1046 unsigned long m_IStateOmega = 0;
1047 unsigned long m_IStateBattery = 0;
1048 unsigned long m_IStateBase = 0;
1050
1057 int LocalIndex(unsigned long globalStateIndex) const
1058 {
1059 return static_cast<int>(globalStateIndex - m_IStateBase);
1060 }
1061
1062 // Working set of the derivative evaluation, in the style of TrawlDoorBase.
1063 double ma_adSumForces[6] = {0, 0, 0, 0, 0, 0};
1064 double ma_mdR[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
1065 double ma_adXVel_n[3] = {0, 0, 0};
1066 double ma_adWaterVel_d[3] = {0, 0, 0};
1067 const double* ma_adXPos_n = nullptr;
1068 const double* ma_adXQuater = nullptr;
1069 const double* ma_adXVel_d = nullptr;
1070 const double* ma_adXOmega = nullptr;
1071 const double* ma_adXBattery = nullptr;
1072 double ma_adRelVel_d[3] = {0, 0, 0};
1073 double ma_dPropulsionPower = 0.0;
1074 double ma_dCommandedPower = 0.0;
1075 double ma_dRudderDive = 0.0;
1076 double ma_dRudderYaw = 0.0;
1077
1078 // Output port storage, all written by CalcOutput.
1079 double m_outPos[3] = {0, 0, 0};
1080 double m_outVel[3] = {0, 0, 0};
1081 double m_outQuater[4] = {1, 0, 0, 0};
1082 double m_outEuler[3] = {0, 0, 0};
1083 double m_outDepth = 0.0;
1084 double m_outSpeed = 0.0;
1085 double m_outAltitude = 0.0;
1086 double m_outSeaDepth = 0.0;
1088 double m_outThrust = 0.0;
1089
1090#ifdef FH_VISUALIZATION
1101 double HullRadiusAt(double bodyX) const;
1102
1107 void BuildHullSurface(Ogre::ManualObject* const hull) const;
1108
1119 void BuildFinPlane(Ogre::ManualObject* const fins, AuvRudderPlane plane) const;
1120
1121 Ogre::SceneManager* m_sceneMgr = nullptr;
1122 Ogre::SceneNode* m_renderNode = nullptr;
1123 Ogre::SceneNode* m_diveFinNode = nullptr;
1124 Ogre::SceneNode* m_yawFinNode = nullptr;
1125 Ogre::ManualObject* m_hullObject = nullptr;
1126 Ogre::ManualObject* m_diveFinObject = nullptr;
1127 Ogre::ManualObject* m_yawFinObject = nullptr;
1128#endif
1129};
Definition Auv.h:990
environment::wake::PropellerJetInput PropellerJet(const double *X) const override
The thruster at ThrusterPos, shaft along body x, T_eff = ComputeThrust() (no thrust deduction),...
void CurrentLoad(const double *X, const double freeStream[3], const double flowDir[3], double force[3], double &frontalArea, double rearCentre[3]) const override
The hull, lift and fin drag at the free stream, on the frontal area pi D²/4, the rear centre at the s...
environment::wake::WakeCastState Reference(const double *X) const override
The body origin and its velocity in NED.
Definition Auv.h:530
double ma_dCommandedPower
The commanded propulsion power of the current derivative evaluation, W, before the clamp.
Definition Auv.h:1074
double ma_dRudderYaw
The commanded yaw-plane deflection of the current derivative evaluation, rad, before the clamp.
Definition Auv.h:1076
static AuvHullProperties HullPropertiesOf(double length, double diameter, double averageDensity)
double m_maxPropulsionPower
The largest propulsion power accepted, W.
Definition Auv.h:969
double m_castRudderDive
The RudderDive command at the last PreOdeFcn [rad]: the hull load's dive fins.
Definition Auv.h:1015
virtual void AddRudderForces(const double dT, const double *const adX)
Adds the wrench of both fin planes, and caches the two commanded deflections.
const double * ma_adXPos_n
The NED position state.
Definition Auv.h:1067
static double RollDampingMoment(double rollRate, double linear, double quadratic)
double m_length
The hull length, m. Kept because the visualisation draws it.
Definition Auv.h:958
double m_sectionX[kSectionCount]
The body-frame x of each section centroid, m.
Definition Auv.h:976
double m_outThrust
Thrust along body x, N.
Definition Auv.h:1088
double ma_adSumForces[6]
Body-frame force in [0..2] and moment about the origin in [3..5].
Definition Auv.h:1063
unsigned long m_IStateQuater
Global index of the attitude quaternion state.
Definition Auv.h:1044
double m_sectionDiameter[kSectionCount]
The cross-flow diameter of each section, m.
Definition Auv.h:977
static void RudderWrench(AuvRudderPlane plane, const double relVel_d[3], const double omega_d[3], double deflection, const AuvRudderProperties &rudder, double wrench_d[6])
virtual void CalcDerivatives(double *const adXDot)
Turns the accumulated wrench into the state derivatives.
double m_massInverse[6][6]
The inverse of the constant mass matrix.
Definition Auv.h:961
static double SubmergedFraction(double axisDepth, double radius)
double m_sectionLength[kSectionCount]
The length of each section, m.
Definition Auv.h:978
static void CrossFlowStripWrench(const double relVel_d[3], const double omega_d[3], double rho, double crossFlowDragCoeff, int sectionCount, const double *sectionX, const double *sectionDiameter, const double *sectionLength, double wrench_d[6])
double AuthorityCheckCruiseSpeed() const
The forward speed the dive-authority check assumes, from this vehicle's own parameters.
unsigned long m_IStateLocalVel
Global index of the body-frame velocity state.
Definition Auv.h:1045
void CalcOutputCommon(const double dT, const double *const adX) const
Trampoline registered as the common computation of every output port.
double m_crossFlowDragCoeff
The two-dimensional cross-flow drag coefficient of a section.
Definition Auv.h:975
const double * ma_adXQuater
The attitude quaternion state.
Definition Auv.h:1068
double m_cOG[3]
The centre of gravity in the body frame, m.
Definition Auv.h:960
static void RudderWrenchJacobian(AuvRudderPlane plane, const double relVel_d[3], const double omega_d[3], double deflection, const AuvRudderProperties &rudder, double dWrench_dVelocity[6][6], double dWrench_dDeflection[6])
double m_outPos[3]
Position in NED, m.
Definition Auv.h:1079
void OdeFcn(const double dT, const double *const adX, double *const adXDot) const override
Calculates the state derivatives.
double m_rigidInertia[6]
The diagonal of the rigid-body mass matrix.
Definition Auv.h:962
ICommonComputation * m_commonCalc
Shared recomputation behind every output port.
Definition Auv.h:1025
double ma_dRudderDive
The commanded dive-plane deflection of the current derivative evaluation, rad, before the clamp.
Definition Auv.h:1075
double ma_adXVel_n[3]
The velocity of the origin in NED, m/s.
Definition Auv.h:1065
ISignalPort * m_inRudderDive
Commanded dive-plane fin deflection, rad.
Definition Auv.h:1022
ISignalPort * m_inExternalForce
An external force in NED, N.
Definition Auv.h:1023
double ClampedPropulsionPower(double commandedPower) const
Clamps a commanded power to the range the thruster accepts, [0, MaxPropulsionPower].
double m_initialBattery
The battery energy at the start of the mission, J.
Definition Auv.h:965
ISignalPort * m_inThrustPower
Commanded propulsion power, W.
Definition Auv.h:1020
double m_outVel[3]
Velocity in NED, m/s.
Definition Auv.h:1080
virtual void AddThrustForces(const double dT, const double *const adX)
Adds the thruster wrench and caches the propulsion power the battery pays for.
double m_propellerDiameter
PropellerDiameter [m], read with CastWake only.
Definition Auv.h:1012
double m_jetCommandedPower
The ThrustPower command at the last PreOdeFcn [W]: the jet's thrust.
Definition Auv.h:1014
double m_rollDampingQuadratic
The quadratic roll damping, N·m·s².
Definition Auv.h:980
virtual void AddExternalForces(const double dT, const double *const adX)
Adds the ExternalForce input port, at the body origin.
double m_outSpeed
Forward speed through the water, m/s.
Definition Auv.h:1084
double m_outQuater[4]
Attitude quaternion.
Definition Auv.h:1081
const double * ma_adXOmega
The body-frame angular velocity state.
Definition Auv.h:1070
static const int kSectionCount
The number of hull sections the cross-flow strip theory divides the hull into.
Definition Auv.h:703
environment::EnvironmentProvider * m_environment
m_flow's Environment, from FinalSetup.
Definition Auv.h:1009
double m_castRudderYaw
The RudderYaw command at the last PreOdeFcn [rad]: the hull load's yaw fins.
Definition Auv.h:1016
double m_axialDragCoeff
The hull drag coefficient on the frontal area.
Definition Auv.h:972
virtual void AddInternalForces(const double dT)
Adds the weight at COG and the buoyancy at the origin.
unsigned long m_IStateBattery
Global index of the battery energy state.
Definition Auv.h:1047
void WarnIfTheFinsCannotDive(const std::string &simObjectName, double diveAngle) const
unsigned long m_IStatePos
Global index of the NED position state.
Definition Auv.h:1043
bool HasJacobians() const override
double m_outBatteryFraction
Remaining battery energy as a fraction of InitialBattery.
Definition Auv.h:1087
static const double kInflowSpeedEpsilon
Definition Auv.h:801
int LocalIndex(unsigned long globalStateIndex) const
Definition Auv.h:1057
double m_thrusterPos[3]
The thruster position in the body frame, m.
Definition Auv.h:971
double m_outEuler[3]
Roll, pitch and yaw, rad.
Definition Auv.h:1082
double m_outSeaDepth
Seafloor depth below the surface, m.
Definition Auv.h:1086
static const double kCrossFlowSpeedEpsilon
Definition Auv.h:714
double ma_adRelVel_d[3]
The velocity of the body relative to the fluid, in the body frame, m/s.
Definition Auv.h:1072
const double * ma_adXVel_d
The body-frame velocity state.
Definition Auv.h:1069
PrintDuringExec * m_print
The simulation logger, null under a headless or mock host.
Definition Auv.h:1017
double m_outDepth
Depth below the surface, m.
Definition Auv.h:1083
virtual void CalcOutput(const double dT, const double *const adX)
Recomputes every output port from the given time and state.
double ma_adWaterVel_d[3]
The fluid velocity at the body, in the body frame, m/s.
Definition Auv.h:1066
unsigned long m_IStateOmega
Global index of the body-frame angular velocity state.
Definition Auv.h:1046
static void AxialDragWrench(const double relVel_d[3], double rho, double frontalArea, double axialDragCoeff, double wrench_d[6])
void PreOdeFcn(double T, const double *X, IStateUpdater *updater) override
Rebuilds the hull wake and the propeller jet when due (CastWake) and takes the other objects' wakes a...
AuvRudderProperties m_rudder
The fin geometry and coefficients.
Definition Auv.h:984
double ma_dPropulsionPower
The clamped propulsion power of the current derivative evaluation, W.
Definition Auv.h:1073
double m_hotelPower
The constant payload and computer load, W.
Definition Auv.h:970
double ma_mdR[3][3]
The body-to-NED rotation matrix.
Definition Auv.h:1064
unsigned long m_IStateBase
Global index of this object's first state, cached in the constructor.
Definition Auv.h:1048
AuvCaster m_caster
The vehicle for its wake and jet; declared before m_flow, which keeps a pointer to it.
Definition Auv.h:1010
double m_jetTime
The time of the last PreOdeFcn [s]: the jet's water velocity.
Definition Auv.h:1013
~Auv() override
double m_outAltitude
Height above the seafloor, m.
Definition Auv.h:1085
environment::wake::BodyFlowInteraction m_flow
The wakes the vehicle casts and receives.
Definition Auv.h:1011
virtual void CalcFoundation(const double dT, const double *const adX)
Zeroes the force accumulator and caches the pose, the rotation matrix and the fluid velocity.
AuvHullProperties m_hull
The derived radius, volume, mass and inertia.
Definition Auv.h:959
static void SlenderBodyLiftWrench(const double relVel_d[3], const double omega_d[3], double rho, int sectionCount, const double *sectionX, const double *sectionDiameter, const double *sectionLength, double wrench_d[6], double(*dWrench_dVelocity)[6]=nullptr)
double m_addedMass[6]
The diagonal of the added mass, AddedMass.
Definition Auv.h:963
bool HasPortJacobians() const override
virtual void AddHullHydroForces()
Adds the axial hull drag, the cross-flow strip wrench and the explicit roll damping.
double m_rollDampingLinear
The linear roll damping, N·m·s.
Definition Auv.h:979
const double * ma_adXBattery
The battery energy state.
Definition Auv.h:1071
double m_thrustPerPower
Thrust per watt of propulsion power, N/W.
Definition Auv.h:968
virtual double ComputeThrust(double propulsionPower, double surgeSpeed) const
double m_rhoWater
The density of the surrounding fluid, kg/m³.
Definition Auv.h:964
ISignalPort * m_inRudderYaw
Commanded yaw-plane fin deflection, rad.
Definition Auv.h:1021
Definition AuvFoil.h:82
Definition Auv.h:498
double izz
Yaw inertia about the body z axis, kg·m².
Definition Auv.h:505
double mass
Vehicle mass, kg.
Definition Auv.h:502
double iyy
Pitch inertia about the body y axis, kg·m².
Definition Auv.h:504
double frontalArea
Frontal area of the cylinder, pi r², m².
Definition Auv.h:501
double volume
Displaced volume, m³.
Definition Auv.h:500
double ixx
Roll inertia about the body x axis, kg·m².
Definition Auv.h:503
double radius
Hull radius, m.
Definition Auv.h:499
Everything one fin plane needs beyond its inflow and its commanded deflection.
Definition Auv.h:521
double rho
The density of the sea water, kg/m³.
Definition Auv.h:523
double pos[3]
Where the fin wrench acts, body frame, m.
Definition Auv.h:525
AuvFoilProperties foil
The lift and drag coefficient parameters.
Definition Auv.h:522
double area
The planform area of the fin plane, m².
Definition Auv.h:524
double maxDeflection
The mechanical stop on the command, rad.
Definition Auv.h:526