FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
Auv.h
1#pragma once
2
399#include "AuvFoil.h"
400
401#include <fhsim/simobject/SimObject.h>
402#include <fhsim_environment/EnvironmentProvider.h>
403#include <string>
404
405class PrintDuringExec;
406
413{
414 double radius = 0.0;
415 double volume = 0.0;
416 double frontalArea = 0.0;
417 double mass = 0.0;
418 double ixx = 0.0;
419 double iyy = 0.0;
420 double izz = 0.0;
421};
422
428enum class AuvRudderPlane
429{
430 Dive,
431 Yaw
432};
433
436{
438 double rho = 1025.0;
439 double area = 0.016;
440 double pos[3] = {-0.85, 0.0, 0.0};
441 double maxDeflection = 0.35;
442};
443
444class Auv : public SimObject
445{
446public:
447 Auv(std::string simObjectName, ISimObjectCreator* creator);
448
455 ~Auv() override;
456
458 void OdeFcn(const double dT, const double* const adX, double* const adXDot) const override;
459
462
496 bool HasJacobians() const override;
497 void OdeJacobian(double T, const double* X, double* J, int nStates) override;
498 int GetJacobianSparsity(int nStates, int* rowPtr, int* colIdx) override;
499
549 bool HasPortJacobians() const override;
550 void InputPortJacobian(const std::string& portName, double T, const double* X,
551 double* dF_dInput, int portSize, int nStates) override;
552 void OutputPortJacobian(const std::string& portName, double T, const double* X,
553 double* dPort_dX, int portSize, int nStates, int index) override;
555
556 void FinalSetup(const double dT, const double* const adX, ISimObjectCreator* const creator) override;
557
568 static AuvHullProperties HullPropertiesOf(double length, double diameter, double averageDensity);
569
590 static double SubmergedFraction(double axisDepth, double radius);
591
609 static void AxialDragWrench(const double relVel_d[3], double rho, double frontalArea,
610 double axialDragCoeff, double wrench_d[6]);
611
613 static const int kSectionCount = 3;
614
624 static const double kCrossFlowSpeedEpsilon;
625
654 static void CrossFlowStripWrench(const double relVel_d[3], const double omega_d[3],
655 double rho, double crossFlowDragCoeff, int sectionCount, const double* sectionX,
656 const double* sectionDiameter, const double* sectionLength, double wrench_d[6]);
657
668 static double RollDampingMoment(double rollRate, double linear, double quadratic);
669
677 static const double kInflowSpeedEpsilon;
678
696 static void RudderWrench(AuvRudderPlane plane, const double relVel_d[3], const double omega_d[3],
697 double deflection, const AuvRudderProperties& rudder, double wrench_d[6]);
698
728 static void RudderWrenchJacobian(AuvRudderPlane plane, const double relVel_d[3],
729 const double omega_d[3], double deflection, const AuvRudderProperties& rudder,
730 double dWrench_dVelocity[6][6], double dWrench_dDeflection[6]);
731
732#ifdef FH_VISUALIZATION
744 void RenderInit(Ogre::Root* const ogreRoot, ISimObjectCreator* const creator) override;
745
756 void RenderUpdate(const double dT, const double* const adX) override;
757#endif
758
759protected:
761 virtual void CalcFoundation(const double dT, const double* const adX);
762
764 virtual void AddExternalForces(const double dT, const double* const adX);
765
767 virtual void AddInternalForces(const double dT);
768
770 virtual void AddThrustForces(const double dT, const double* const adX);
771
773 virtual void AddHullHydroForces();
774
776 virtual void AddRudderForces(const double dT, const double* const adX);
777
787 void WarnIfTheFinsCannotDive(const std::string& simObjectName, double diveAngle) const;
788
791
802 virtual double ComputeThrust(double propulsionPower, double surgeSpeed) const;
803
805 double ClampedPropulsionPower(double commandedPower) const;
806
808 virtual void CalcDerivatives(double* const adXDot);
809
811 virtual void CalcOutput(const double dT, const double* const adX);
812
814 void CalcOutputCommon(const double dT, const double* const adX) const;
815
818 const double* OutPos(const double dT, const double* const adX);
819 const double* OutVel(const double dT, const double* const adX);
820 const double* OutQuater(const double dT, const double* const adX);
821 const double* OutEuler(const double dT, const double* const adX);
822 const double* OutHeading(const double dT, const double* const adX);
823 const double* OutPitch(const double dT, const double* const adX);
824 const double* OutDepth(const double dT, const double* const adX);
825 const double* OutSpeed(const double dT, const double* const adX);
826 const double* OutAltitude(const double dT, const double* const adX);
827 const double* OutSeaDepth(const double dT, const double* const adX);
828 const double* OutBattery(const double dT, const double* const adX);
829 const double* OutBatteryFraction(const double dT, const double* const adX);
830 const double* OutThrust(const double dT, const double* const adX);
832
833 // Geometry and mass, all derived from Length, Diameter and AverageDensity.
834 double m_length = 0.0;
836 double m_cOG[3];
837 double m_massInverse[6][6];
838 double m_rhoWater;
840
841 // Propulsion, drag and the hotel load.
845 double m_thrusterPos[3];
847
848 // Cross-flow strip theory and the roll damping it cannot supply.
855
856 // The fins. One set of properties serves both planes; they differ only in which
857 // transverse component of the inflow they see.
859
860 environment::EnvironmentProvider* m_environment = nullptr;
861 PrintDuringExec* m_print = nullptr;
862
863 // Input ports
864 ISignalPort* m_inThrustPower = nullptr;
865 ISignalPort* m_inRudderYaw = nullptr;
866 ISignalPort* m_inRudderDive = nullptr;
867 ISignalPort* m_inExternalForce = nullptr;
868
869 ICommonComputation* m_commonCalc = nullptr;
870
887 unsigned long m_IStatePos = 0;
888 unsigned long m_IStateQuater = 0;
889 unsigned long m_IStateLocalVel = 0;
890 unsigned long m_IStateOmega = 0;
891 unsigned long m_IStateBattery = 0;
892 unsigned long m_IStateBase = 0;
894
901 int LocalIndex(unsigned long globalStateIndex) const
902 {
903 return static_cast<int>(globalStateIndex - m_IStateBase);
904 }
905
906 // Working set of the derivative evaluation, in the style of TrawlDoorBase.
907 double ma_adSumForces[6] = {0, 0, 0, 0, 0, 0};
908 double ma_mdR[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
909 double ma_adXVel_n[3] = {0, 0, 0};
910 double ma_adWaterVel_d[3] = {0, 0, 0};
911 const double* ma_adXPos_n = nullptr;
912 const double* ma_adXQuater = nullptr;
913 const double* ma_adXVel_d = nullptr;
914 const double* ma_adXOmega = nullptr;
915 const double* ma_adXBattery = nullptr;
916 double ma_adRelVel_d[3] = {0, 0, 0};
917 double ma_dPropulsionPower = 0.0;
918 double ma_dCommandedPower = 0.0;
919 double ma_dRudderDive = 0.0;
920 double ma_dRudderYaw = 0.0;
921
922 // Output port storage, all written by CalcOutput.
923 double m_outPos[3] = {0, 0, 0};
924 double m_outVel[3] = {0, 0, 0};
925 double m_outQuater[4] = {1, 0, 0, 0};
926 double m_outEuler[3] = {0, 0, 0};
927 double m_outDepth = 0.0;
928 double m_outSpeed = 0.0;
929 double m_outAltitude = 0.0;
930 double m_outSeaDepth = 0.0;
931 double m_outBatteryFraction = 0.0;
932 double m_outThrust = 0.0;
933
934#ifdef FH_VISUALIZATION
945 double HullRadiusAt(double bodyX) const;
946
951 void BuildHullSurface(Ogre::ManualObject* const hull) const;
952
963 void BuildFinPlane(Ogre::ManualObject* const fins, AuvRudderPlane plane) const;
964
965 Ogre::SceneManager* m_sceneMgr = nullptr;
966 Ogre::SceneNode* m_renderNode = nullptr;
967 Ogre::SceneNode* m_diveFinNode = nullptr;
968 Ogre::SceneNode* m_yawFinNode = nullptr;
969 Ogre::ManualObject* m_hullObject = nullptr;
970 Ogre::ManualObject* m_diveFinObject = nullptr;
971 Ogre::ManualObject* m_yawFinObject = nullptr;
972#endif
973};
Definition Auv.h:445
double ma_dCommandedPower
The commanded propulsion power of the current derivative evaluation, W, before the clamp.
Definition Auv.h:918
double ma_dRudderYaw
The commanded yaw-plane deflection of the current derivative evaluation, rad, before the clamp.
Definition Auv.h:920
static AuvHullProperties HullPropertiesOf(double length, double diameter, double averageDensity)
double m_maxPropulsionPower
The largest propulsion power accepted, W.
Definition Auv.h:843
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:911
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:834
double m_sectionX[kSectionCount]
The body-frame x of each section centroid, m.
Definition Auv.h:850
double m_outThrust
Thrust along body x, N.
Definition Auv.h:932
double ma_adSumForces[6]
Body-frame force in [0..2] and moment about the origin in [3..5].
Definition Auv.h:907
unsigned long m_IStateQuater
Global index of the attitude quaternion state.
Definition Auv.h:888
double m_sectionDiameter[kSectionCount]
The cross-flow diameter of each section, m.
Definition Auv.h:851
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:837
static double SubmergedFraction(double axisDepth, double radius)
double m_sectionLength[kSectionCount]
The length of each section, m.
Definition Auv.h:852
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:889
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:849
const double * ma_adXQuater
The attitude quaternion state.
Definition Auv.h:912
double m_cOG[3]
The centre of gravity in the body frame, m.
Definition Auv.h:836
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:923
void OdeFcn(const double dT, const double *const adX, double *const adXDot) const override
Calculates the state derivatives.
ICommonComputation * m_commonCalc
Shared recomputation behind every output port.
Definition Auv.h:869
double ma_dRudderDive
The commanded dive-plane deflection of the current derivative evaluation, rad, before the clamp.
Definition Auv.h:919
double ma_adXVel_n[3]
The velocity of the origin in NED, m/s.
Definition Auv.h:909
ISignalPort * m_inRudderDive
Commanded dive-plane fin deflection, rad.
Definition Auv.h:866
ISignalPort * m_inExternalForce
An external force in NED, N.
Definition Auv.h:867
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:839
ISignalPort * m_inThrustPower
Commanded propulsion power, W.
Definition Auv.h:864
double m_outVel[3]
Velocity in NED, m/s.
Definition Auv.h:924
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_rollDampingQuadratic
The quadratic roll damping, N·m·s².
Definition Auv.h:854
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:928
double m_outQuater[4]
Attitude quaternion.
Definition Auv.h:925
const double * ma_adXOmega
The body-frame angular velocity state.
Definition Auv.h:914
static const int kSectionCount
The number of hull sections the cross-flow strip theory divides the hull into.
Definition Auv.h:613
environment::EnvironmentProvider * m_environment
The shared environment.
Definition Auv.h:860
double m_axialDragCoeff
The hull drag coefficient on the frontal area.
Definition Auv.h:846
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:891
void WarnIfTheFinsCannotDive(const std::string &simObjectName, double diveAngle) const
unsigned long m_IStatePos
Global index of the NED position state.
Definition Auv.h:887
bool HasJacobians() const override
double m_outBatteryFraction
Remaining battery energy as a fraction of InitialBattery.
Definition Auv.h:931
static const double kInflowSpeedEpsilon
Definition Auv.h:677
int LocalIndex(unsigned long globalStateIndex) const
Definition Auv.h:901
double m_thrusterPos[3]
The thruster position in the body frame, m.
Definition Auv.h:845
double m_outEuler[3]
Roll, pitch and yaw, rad.
Definition Auv.h:926
double m_outSeaDepth
Seafloor depth below the surface, m.
Definition Auv.h:930
static const double kCrossFlowSpeedEpsilon
Definition Auv.h:624
double ma_adRelVel_d[3]
The velocity of the body relative to the fluid, in the body frame, m/s.
Definition Auv.h:916
const double * ma_adXVel_d
The body-frame velocity state.
Definition Auv.h:913
PrintDuringExec * m_print
The simulation logger, null under a headless or mock host.
Definition Auv.h:861
double m_outDepth
Depth below the surface, m.
Definition Auv.h:927
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:910
unsigned long m_IStateOmega
Global index of the body-frame angular velocity state.
Definition Auv.h:890
static void AxialDragWrench(const double relVel_d[3], double rho, double frontalArea, double axialDragCoeff, double wrench_d[6])
AuvRudderProperties m_rudder
The fin geometry and coefficients.
Definition Auv.h:858
double ma_dPropulsionPower
The clamped propulsion power of the current derivative evaluation, W.
Definition Auv.h:917
double m_hotelPower
The constant payload and computer load, W.
Definition Auv.h:844
double ma_mdR[3][3]
The body-to-NED rotation matrix.
Definition Auv.h:908
unsigned long m_IStateBase
Global index of this object's first state, cached in the constructor.
Definition Auv.h:892
~Auv() override
double m_outAltitude
Height above the seafloor, m.
Definition Auv.h:929
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:835
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:853
const double * ma_adXBattery
The battery energy state.
Definition Auv.h:915
double m_thrustPerPower
Thrust per watt of propulsion power, N/W.
Definition Auv.h:842
virtual double ComputeThrust(double propulsionPower, double surgeSpeed) const
double m_rhoWater
The density of the surrounding fluid, kg/m³.
Definition Auv.h:838
ISignalPort * m_inRudderYaw
Commanded yaw-plane fin deflection, rad.
Definition Auv.h:865
Definition AuvFoil.h:82
Definition Auv.h:413
double izz
Yaw inertia about the body z axis, kg·m².
Definition Auv.h:420
double mass
Vehicle mass, kg.
Definition Auv.h:417
double iyy
Pitch inertia about the body y axis, kg·m².
Definition Auv.h:419
double frontalArea
Frontal area of the cylinder, pi r², m².
Definition Auv.h:416
double volume
Displaced volume, m³.
Definition Auv.h:415
double ixx
Roll inertia about the body x axis, kg·m².
Definition Auv.h:418
double radius
Hull radius, m.
Definition Auv.h:414
Everything one fin plane needs beyond its inflow and its commanded deflection.
Definition Auv.h:436
double rho
The density of the sea water, kg/m³.
Definition Auv.h:438
double pos[3]
Where the fin wrench acts, body frame, m.
Definition Auv.h:440
AuvFoilProperties foil
The lift and drag coefficient parameters.
Definition Auv.h:437
double area
The planform area of the fin plane, m².
Definition Auv.h:439
double maxDeflection
The mechanical stop on the command, rad.
Definition Auv.h:441