FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
Auv.h
1#pragma once
2
350#include "AuvFoil.h"
351#include "AuvHullLaw.h"
352
353#include <fhsim/simobject/SimObject.h>
354#include <fhsim_base/body/HydroBody.h>
355#include <fhsim_environment/BodyFlowInteraction.h>
356#include <fhsim_environment/EnvironmentProvider.h>
357#include <fhsim_environment/WakeSourceSet.h>
358#include <string>
359
360class PrintDuringExec;
361
362class Auv : public SimObject
363{
364public:
365 Auv(std::string simObjectName, ISimObjectCreator* creator);
366
373 ~Auv() override;
374
376 void OdeFcn(const double dT, const double* const adX, double* const adXDot) const override;
377
380
416 bool HasJacobians() const override;
417 void OdeJacobian(double T, const double* X, double* J, int nStates) override;
418 int GetJacobianSparsity(int nStates, int* rowPtr, int* colIdx) override;
419
469 bool HasPortJacobians() const override;
470 void InputPortJacobian(const std::string& portName, double T, const double* X,
471 double* dF_dInput, int portSize, int nStates) override;
472 void OutputPortJacobian(const std::string& portName, double T, const double* X,
473 double* dPort_dX, int portSize, int nStates, int index) override;
475
476 void FinalSetup(const double dT, const double* const adX, ISimObjectCreator* const creator) override;
477
479 void PreOdeFcn(double T, const double* X) override;
480
481#ifdef FH_VISUALIZATION
493 void RenderInit(Ogre::Root* const ogreRoot, ISimObjectCreator* const creator) override;
494
505 void RenderUpdate(const double dT, const double* const adX) override;
506#endif
507
508protected:
515 hydro_body::Wrench SumLoads(double T, const double* X, const hydro_body::FlowFrame& frame, double& propulsionPower) const;
516
518 void AddExternalForces(double T, const double* X, const hydro_body::FlowFrame& frame, hydro_body::Wrench& wrench) const;
519
521 void AddInternalForces(double T, const hydro_body::FlowFrame& frame, hydro_body::Wrench& wrench) const;
522
524 double AddThrustForces(double T, const double* X, const hydro_body::FlowFrame& frame, hydro_body::Wrench& wrench) const;
525
528 {
529 double dive = 0.0;
530 double yaw = 0.0;
531 };
532
534 RudderCommands ReadRudderCommands(double T, const double* X) const;
535
545 void WarnIfTheFinsCannotDive(const std::string& simObjectName, double diveAngle) const;
546
549
560 virtual double ComputeThrust(double propulsionPower, double surgeSpeed) const;
561
563 double ClampedPropulsionPower(double commandedPower) const;
564
566 virtual void CalcOutput(const double dT, const double* const adX);
567
569 void CalcThrust(const double dT, const double* const adX);
570
572 void CalcOutputCommon(const double dT, const double* const adX) const;
573
576 const double* OutPos(const double dT, const double* const adX);
577 const double* OutVel(const double dT, const double* const adX);
578 const double* OutQuater(const double dT, const double* const adX);
579 const double* OutEuler(const double dT, const double* const adX);
580 const double* OutHeading(const double dT, const double* const adX);
581 const double* OutPitch(const double dT, const double* const adX);
582 const double* OutDepth(const double dT, const double* const adX);
583 const double* OutSpeed(const double dT, const double* const adX);
584 const double* OutAltitude(const double dT, const double* const adX);
585 const double* OutSeaDepth(const double dT, const double* const adX);
586 const double* OutBattery(const double dT, const double* const adX);
587 const double* OutBatteryFraction(const double dT, const double* const adX);
588 const double* OutThrust(const double dT, const double* const adX);
590
591 // Geometry and mass, all derived from Length, Diameter and AverageDensity.
592 double m_length = 0.0;
594 double m_cOG[3];
595 double m_rhoWater;
597
598 // Propulsion, drag and the hotel load.
602 double m_thrusterPos[3];
603
604 // Cross-flow strip theory and the roll damping it cannot supply, with the drag coefficients.
607
608 // The fins. One set of properties serves both planes; they differ only in which
609 // transverse component of the inflow they see.
611
615 class AuvCaster final : public environment::wake::PropelledObject
616 {
617 public:
618 explicit AuvCaster(const Auv& auv)
619 : m_auv(auv)
620 {
621 }
622
624 environment::wake::WakeCastState Reference(double T, const double* X) const override;
626 void CurrentLoad(double T, const double* X, const double freeStream[3], const double flowDir[3], double force[3], double& frontalArea,
627 double rearCentre[3]) const override;
629 environment::wake::PropellerJetInput PropellerJet(double T, const double* X) const override;
630
631 private:
632 const Auv& m_auv;
633 };
634
635 environment::EnvironmentProvider* m_environment = nullptr;
637 environment::wake::BodyFlowInteraction m_flow;
639 double m_propellerDiameter = 0.0;
640 PrintDuringExec* m_print = nullptr;
641
642 // Input ports
643 ISignalPort* m_inThrustPower = nullptr;
644 ISignalPort* m_inRudderYaw = nullptr;
645 ISignalPort* m_inRudderDive = nullptr;
646 ISignalPort* m_inExternalForce = nullptr;
647
648 ICommonComputation* m_commonCalc = nullptr;
649
666 unsigned long m_IStatePos = 0;
667 unsigned long m_IStateQuater = 0;
668 unsigned long m_IStateLocalVel = 0;
669 unsigned long m_IStateOmega = 0;
670 unsigned long m_IStateBattery = 0;
671 unsigned long m_IStateBase = 0;
673
680 int LocalIndex(unsigned long globalStateIndex) const
681 {
682 return static_cast<int>(globalStateIndex - m_IStateBase);
683 }
684
689 {
690 double power = 0.0;
691 double rudderDive = 0.0;
692 double rudderYaw = 0.0;
693 };
695
696 // Output port storage, written by CalcOutput (and m_outThrust by CalcThrust).
697 double m_outPos[3] = {0, 0, 0};
698 double m_outVel[3] = {0, 0, 0};
699 double m_outQuater[4] = {1, 0, 0, 0};
700 double m_outEuler[3] = {0, 0, 0};
701 double m_outDepth = 0.0;
702 double m_outSpeed = 0.0;
703 double m_outAltitude = 0.0;
704 double m_outSeaDepth = 0.0;
705 double m_outBatteryFraction = 0.0;
706 double m_outThrust = 0.0;
707
708#ifdef FH_VISUALIZATION
719 double HullRadiusAt(double bodyX) const;
720
725 void BuildHullSurface(Ogre::ManualObject* const hull) const;
726
737 void BuildFinPlane(Ogre::ManualObject* const fins, auv_hull::RudderPlane plane) const;
738
739 Ogre::SceneManager* m_sceneMgr = nullptr;
740 Ogre::SceneNode* m_renderNode = nullptr;
741 Ogre::SceneNode* m_diveFinNode = nullptr;
742 Ogre::SceneNode* m_yawFinNode = nullptr;
743 Ogre::ManualObject* m_hullObject = nullptr;
744 Ogre::ManualObject* m_diveFinObject = nullptr;
745 Ogre::ManualObject* m_yawFinObject = nullptr;
746#endif
747};
Definition Auv.h:616
void CurrentLoad(double T, 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(double T, const double *X) const override
The body origin and its velocity in NED.
environment::wake::PropellerJetInput PropellerJet(double T, const double *X) const override
The thruster at ThrusterPos, shaft along body x, T_eff = ComputeThrust() (no thrust deduction),...
Definition Auv.h:363
double m_maxPropulsionPower
The largest propulsion power accepted, W.
Definition Auv.h:600
double m_length
The hull length, m. Kept because the visualisation draws it.
Definition Auv.h:592
double m_outThrust
Thrust along body x, N.
Definition Auv.h:706
unsigned long m_IStateQuater
Global index of the attitude quaternion state.
Definition Auv.h:667
void AddInternalForces(double T, const hydro_body::FlowFrame &frame, hydro_body::Wrench &wrench) const
Adds the weight at COG and the buoyancy at the origin.
auv_hull::Coefficients m_coefficients
The drag and roll damping coefficients; rho copies m_rhoWater.
Definition Auv.h:606
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:668
void CalcOutputCommon(const double dT, const double *const adX) const
Trampoline registered as the common computation of every output port.
double m_cOG[3]
The centre of gravity in the body frame, m.
Definition Auv.h:594
double m_outPos[3]
Position in NED, m.
Definition Auv.h:697
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:648
ISignalPort * m_inRudderDive
Commanded dive-plane fin deflection, rad.
Definition Auv.h:645
ISignalPort * m_inExternalForce
An external force in NED, N.
Definition Auv.h:646
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:596
ISignalPort * m_inThrustPower
Commanded propulsion power, W.
Definition Auv.h:643
double m_outVel[3]
Velocity in NED, m/s.
Definition Auv.h:698
double m_propellerDiameter
PropellerDiameter [m], read with CastWake only.
Definition Auv.h:639
double AddThrustForces(double T, const double *X, const hydro_body::FlowFrame &frame, hydro_body::Wrench &wrench) const
Adds the thruster wrench; returns the clamped propulsion power the battery pays for,...
double m_outSpeed
Forward speed through the water, m/s.
Definition Auv.h:702
double m_outQuater[4]
Attitude quaternion.
Definition Auv.h:699
environment::EnvironmentProvider * m_environment
m_flow's Environment, from FinalSetup.
Definition Auv.h:635
unsigned long m_IStateBattery
Global index of the battery energy state.
Definition Auv.h:670
void WarnIfTheFinsCannotDive(const std::string &simObjectName, double diveAngle) const
unsigned long m_IStatePos
Global index of the NED position state.
Definition Auv.h:666
auv_hull::Hull m_hull
The derived radius, volume, mass and inertia.
Definition Auv.h:593
auv_hull::Rudder m_rudder
The fin geometry and coefficients.
Definition Auv.h:610
bool HasJacobians() const override
double m_outBatteryFraction
Remaining battery energy as a fraction of InitialBattery.
Definition Auv.h:705
int LocalIndex(unsigned long globalStateIndex) const
Definition Auv.h:680
double m_thrusterPos[3]
The thruster position in the body frame, m.
Definition Auv.h:602
HydroBody m_body
The states Pos, Quater, LocalVel and Omega, the mass matrix (rigid body and AddedMass) and the deriva...
Definition Auv.h:638
double m_outEuler[3]
Roll, pitch and yaw, rad.
Definition Auv.h:700
auv_hull::Sections m_sections
The strip-theory sections of the hull.
Definition Auv.h:605
double m_outSeaDepth
Seafloor depth below the surface, m.
Definition Auv.h:704
PrintDuringExec * m_print
The simulation logger, null under a headless or mock host.
Definition Auv.h:640
void CalcThrust(const double dT, const double *const adX)
Recomputes the Thrust output, the only one that reads an input port (ThrustPower)....
double m_outDepth
Depth below the mean free surface, m.
Definition Auv.h:701
virtual void CalcOutput(const double dT, const double *const adX)
Recomputes every output port but Thrust from the given time and state; none reads an input port.
unsigned long m_IStateOmega
Global index of the body-frame angular velocity state.
Definition Auv.h:669
RudderCommands ReadRudderCommands(double T, const double *X) const
Reads both fin ports and returns the deflections. Caches them (PortCommands).
double m_hotelPower
The constant payload and computer load, W.
Definition Auv.h:601
hydro_body::Wrench SumLoads(double T, const double *X, const hydro_body::FlowFrame &frame, double &propulsionPower) const
unsigned long m_IStateBase
Global index of this object's first state, cached in the constructor.
Definition Auv.h:671
AuvCaster m_caster
The vehicle for its wake and jet; declared before m_flow, which keeps a pointer to it.
Definition Auv.h:636
~Auv() override
double m_outAltitude
Height above the seafloor, m.
Definition Auv.h:703
environment::wake::BodyFlowInteraction m_flow
The wakes the vehicle casts and receives.
Definition Auv.h:637
bool HasPortJacobians() const override
double m_thrustPerPower
Thrust per watt of propulsion power, N/W.
Definition Auv.h:599
void AddExternalForces(double T, const double *X, const hydro_body::FlowFrame &frame, hydro_body::Wrench &wrench) const
Adds the ExternalForce input port, at the body origin.
virtual double ComputeThrust(double propulsionPower, double surgeSpeed) const
double m_rhoWater
The density of the surrounding fluid, kg/m³.
Definition Auv.h:595
PortCommands m_lastCommands
See PortCommands.
Definition Auv.h:694
void PreOdeFcn(double T, const double *X) override
Rebuilds the hull wake and the propeller jet when due (CastWake) and takes the other objects' wakes a...
ISignalPort * m_inRudderYaw
Commanded yaw-plane fin deflection, rad.
Definition Auv.h:644
Definition HydroBody.h:101
RudderPlane
Definition AuvHullLaw.h:192
Definition Auv.h:689
double rudderDive
RudderDive [rad].
Definition Auv.h:691
double rudderYaw
RudderYaw [rad].
Definition Auv.h:692
double power
ThrustPower [W].
Definition Auv.h:690
The commanded deflections of the two fin planes, rad.
Definition Auv.h:528
double dive
The dive plane.
Definition Auv.h:529
double yaw
The yaw plane.
Definition Auv.h:530
The coefficients of the hull laws. rho is a copy of the water density of the host (as Rudder::rho is)...
Definition AuvHullLaw.h:284
Definition AuvHullLaw.h:176
Everything one fin plane needs beyond its inflow and its commanded deflection.
Definition AuvHullLaw.h:199
The strip-theory sections of the hull, kSectionCount of each array.
Definition AuvHullLaw.h:276
Definition HydroBody.h:42
The sum of the loads on a body: the force [0..2] and the moment about the origin [3....
Definition HydroBody.h:57