WSF
WsfRigidBodySixDOF_Utils.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2020 Infoscitex, a DCS Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFRIGIDBODYSIXDOFUTILS_HPP
13#define WSFRIGIDBODYSIXDOFUTILS_HPP
14
15#include "wsf_six_dof_export.h"
16
17#include <memory>
18#include <string>
19#include <vector>
20
21#include "UtVec3dX.hpp"
23#include "WsfSixDOF_Mover.hpp"
24#include "WsfSixDOF_Utils.hpp"
25
26namespace wsf
27{
28namespace six_dof
29{
31class RigidBodyMover;
32
33namespace utils
34{
35WSF_SIX_DOF_EXPORT RigidBodyMover* CastToRigidBody(Mover* aVehicle);
36
37WSF_SIX_DOF_EXPORT void Autotune(RigidBodyMover* aVehicle);
38WSF_SIX_DOF_EXPORT void CreateAutopilotConfigFile(const RigidBodyMover* aVehicle, const std::string& aFilename);
39WSF_SIX_DOF_EXPORT std::vector<Pid::Type> GetRelevantPids(const RigidBodyMover* aVehicle);
40
41// The throttle input assumes that 0 is idle, 1 is full power without
42// augmentation/afterburner (military power), and 2 is full power with
43// full augmentation/afterburner (full afterburner).
44WSF_SIX_DOF_EXPORT CanFlyAtReturnValue
45CanFlyAt(RigidBodyMover* aObject, double aAltitude_ft, double aVelocity_fps, double aThrottleForward, double aFlapsDown);
46
47// The filename is typically "autopilot_support_tables.txt"
48WSF_SIX_DOF_EXPORT void CreateAutopilotSupportFile(RigidBodyMover* aObject, const std::string& aFilename);
49
50// The filename is typically "autopilot_support_tables.txt"
51WSF_SIX_DOF_EXPORT void CreateAutopilotSupportFileWithMaxMach(RigidBodyMover* aObject,
52 const std::string& aFilename,
53 const double& aMaxMach);
54
55// This provides the processing that is common between CreateAutopilotSupportFile()
56// and CreateAutopilotSupportFileWithMaxMach()
57WSF_SIX_DOF_EXPORT void CommonCreateAutopilotSupportFile(RigidBodyTableTool& aTool, const std::string& aFilename);
58
59// This is used for the earth radius when mUseSphericalEarth is true
60// Note: The AFSIM cEARTH_RADIUS = 6366707.0194937074958 (6366.7 km)
61// Typical earth radius is 6371 km -- note the 4.3 km discrepancy
62// Distances from points on the surface to the center range from
63// 6,353 km to 6,384 km. Several different ways of modeling the
64// Earth as a sphere each yield a mean radius of 6,371 km.
65
66WSF_SIX_DOF_EXPORT double GetSphericalEarthRadius_m();
67} // namespace utils
68
69class WSF_SIX_DOF_EXPORT RigidBodyMachParamDataTable
70{
71public:
74
76
78
79 void CreateNewMach(double aMach);
80 void AddNewParamDataPair(double aParameter, double aData);
81
82 double GetValueAtMachParam(double aMach, double aParameter) const;
83
84 double GetMinParameterAtMach(double aMach) const;
85 double GetMaxParameterAtMach(double aMach) const;
86
87 double GetMinDataAtMach(double aMach) const;
88 double GetMaxDataAtMach(double aMach) const;
89
90 // aParameterType typically is "alpha" or "cl"
91 // aParameterUnitsString typically is "units deg" or "precision float"
92 void OutputToString(std::string& aInput,
93 const std::string& aTableName,
94 const std::string& aParameterType,
95 const std::string& aParameterUnitsString) const;
96
97protected:
99
101 {
102 double parameter; // This can be anything (for example, alpha_deg or CL)
103 double value;
104 };
105
107 {
108 double mach;
109 std::vector<paramDataPair*> paramDataList;
110 };
111
112 double GetParameterAtMach(double aMach, bool aGetMin) const;
113 double GetMinParameter(const machParamDataListPair* aMachParamDataListPair) const;
114 double GetMaxParameter(const machParamDataListPair* aMachParamDataListPair) const;
115
116 double GetDataAtMach(double aMach, bool aGetMin) const;
117 double GetMinData(const machParamDataListPair* aMachParamDataListPair) const;
118 double GetMaxData(const machParamDataListPair* aMachParamDataListPair) const;
119
120 double GetValueAtParam(std::vector<paramDataPair*>& aList, double aParameter) const;
121
122 std::vector<machParamDataListPair*> mMachParamDataList;
123
125};
126
127// -------------------------------------------------------------------------------
128
129class WSF_SIX_DOF_EXPORT RigidBodyMachDataTable
130{
131public:
134
136
138
139 void CreateNewMachValuePair(double aMach, double aValue);
140
141 double GetValueAtMach(double aMach) const;
142
143 void OutputToString(std::string& aInput, const std::string& aTableName) const;
144
145protected:
147
149 {
150 double mach;
151 double value;
152 };
153
154 std::vector<machDataPair*> mMachDataList;
155};
156
157// -------------------------------------------------------------------------------
158
159class WSF_SIX_DOF_EXPORT RigidBodyTableTool
160{
161public:
162 explicit RigidBodyTableTool(RigidBodyMover* aObject);
164
165 void InitializeTableMachValues(double aMaxMach);
166
167 // Returns true if everything worked properly
169
170 // These functions output tabular data to a string, useful
171 // for outputting data to a file
172 void OutputCLMaxMachTableToInputString(std::string& aInput) const;
173 void OutputCLMinMachTableToInputString(std::string& aInput) const;
174 void OutputAlphaMaxMachTableToInputString(std::string& aInput) const;
175 void OutputAlphaMinMachTableToInputString(std::string& aInput) const;
176 void OutputAlphaMachCLTableToInputString(std::string& aInput) const;
177 void OutputStickMachAlphaTablesToInputString(std::string& aInput) const;
178 void OutputCLMachAlphaTableToInputString(std::string& aInput) const;
179
180protected:
181 double CalcCLFromCLArea(double aCLArea);
182
183 void CreateMachTestList(double aMaxMach);
184
185 bool CalculateStickForZeroMoment(double aMach,
186 double aAlpha_rad,
187 bool aIsPowerOn,
188 double& aThrustProduced_lbs,
189 double& aStickBack);
190
191 bool CalculateStickForZeroMoment(double aMach, double aAlpha_rad, double& aStickBack);
192
193 void AddStickAndCL(double aMach, double aAlpha_rad, double& aStickBack, bool& aMachAdded, bool aLowPoint, bool aHighPoint);
194
195 bool CalcStickAndCL(double aMach,
196 double aAlpha_rad,
197 double& aStickBackBaseline,
198 double& aStickBackThrustShift,
199 double& aStickBackXCmShift,
200 double& aStickBackZCmShift);
201
202 // Here, we pre-compute the stick and CL values. This is redundant, but gives us an
203 // avenue to check data points before we add an uncontrollable mach to our table.
204 int CountValidStickAndCL(double aMach, std::vector<double> aAlphaVector_deg);
205
206 void AddAlphaVsMachCL(double aMach, double aCL, double aMinAlpha_deg, double aMaxAlpha_deg, bool& aMachAdded);
207
209 std::unique_ptr<RigidBodyMachDataTable> mCLMaxVsMachTable;
210 std::unique_ptr<RigidBodyMachDataTable> mCLMinVsMachTable;
211 std::unique_ptr<RigidBodyMachDataTable> mAlphaMax_degVsMachTable;
212 std::unique_ptr<RigidBodyMachDataTable> mAlphaMin_degVsMachTable;
213 std::unique_ptr<RigidBodyMachParamDataTable> mStickForZeroMomentVsMachAlphaTablePtr; // Mach-Alpha
214 std::unique_ptr<RigidBodyMachParamDataTable> mThrustDeltaStickForZeroMomentVsMachAlphaTablePtr; // Mach-Alpha
215 std::unique_ptr<RigidBodyMachParamDataTable> mXcgDeltaStickForZeroMomentVsMachAlphaTablePtr; // Mach-Alpha
216 std::unique_ptr<RigidBodyMachParamDataTable> mZcgDeltaStickForZeroMomentVsMachAlphaTablePtr; // Mach-Alpha
217 std::unique_ptr<RigidBodyMachParamDataTable> mCLVsMachAlphaTable;
218 std::unique_ptr<RigidBodyMachParamDataTable> mAlphaVsMachCLTable;
219
220 // These lists are used to store effective lists of mach, alpha,
221 // and beta values for generating tabular data.
222 std::vector<double> mMachTestList;
224
225private:
226 void Initialize();
227 bool CreateCLMaxAndAlphaMaxTables();
228 bool CreateCLMinAndAlphaMinTables();
229 bool CreateStickForZeroMomentTable();
230 bool CreateAlphaVsMachCLTable();
231};
232} // namespace six_dof
233} // namespace wsf
234
235#endif
aObjectPtr Autotune()
double GetValueAtMach(double aMach) const
Definition WsfRigidBodySixDOF_Utils.cpp:1219
RigidBodyMachDataTable()
Definition WsfRigidBodySixDOF_Utils.cpp:1187
void OutputToString(std::string &aInput, const std::string &aTableName) const
Definition WsfRigidBodySixDOF_Utils.cpp:1246
RigidBodyMachDataTable & operator=(const RigidBodyMachDataTable &other)=delete
RigidBodyMachDataTable * Clone() const
Definition WsfRigidBodySixDOF_Utils.cpp:1206
std::vector< machDataPair * > mMachDataList
Definition WsfRigidBodySixDOF_Utils.hpp:154
void CreateNewMachValuePair(double aMach, double aValue)
Definition WsfRigidBodySixDOF_Utils.cpp:1211
double GetMinParameter(const machParamDataListPair *aMachParamDataListPair) const
Definition WsfRigidBodySixDOF_Utils.cpp:840
void CreateNewMach(double aMach)
Definition WsfRigidBodySixDOF_Utils.cpp:593
double GetValueAtMachParam(double aMach, double aParameter) const
Definition WsfRigidBodySixDOF_Utils.cpp:612
double GetMaxParameterAtMach(double aMach) const
Definition WsfRigidBodySixDOF_Utils.cpp:648
void OutputToString(std::string &aInput, const std::string &aTableName, const std::string &aParameterType, const std::string &aParameterUnitsString) const
Definition WsfRigidBodySixDOF_Utils.cpp:1142
double GetMinData(const machParamDataListPair *aMachParamDataListPair) const
Definition WsfRigidBodySixDOF_Utils.cpp:1065
RigidBodyMachParamDataTable()
Definition WsfRigidBodySixDOF_Utils.cpp:554
double GetParameterAtMach(double aMach, bool aGetMin) const
Definition WsfRigidBodySixDOF_Utils.cpp:663
double GetMaxParameter(const machParamDataListPair *aMachParamDataListPair) const
Definition WsfRigidBodySixDOF_Utils.cpp:864
RigidBodyMachParamDataTable * Clone() const
Definition WsfRigidBodySixDOF_Utils.cpp:588
machParamDataListPair * mCurrentMachParamDataPairPtr
Definition WsfRigidBodySixDOF_Utils.hpp:124
void AddNewParamDataPair(double aParameter, double aData)
Definition WsfRigidBodySixDOF_Utils.cpp:602
double GetValueAtParam(std::vector< paramDataPair * > &aList, double aParameter) const
Definition WsfRigidBodySixDOF_Utils.cpp:1113
double GetMinDataAtMach(double aMach) const
Definition WsfRigidBodySixDOF_Utils.cpp:653
double GetMaxData(const machParamDataListPair *aMachParamDataListPair) const
Definition WsfRigidBodySixDOF_Utils.cpp:1089
RigidBodyMachParamDataTable & operator=(const RigidBodyMachParamDataTable &other)=delete
double GetMinParameterAtMach(double aMach) const
Definition WsfRigidBodySixDOF_Utils.cpp:643
double GetDataAtMach(double aMach, bool aGetMin) const
Definition WsfRigidBodySixDOF_Utils.cpp:888
std::vector< machParamDataListPair * > mMachParamDataList
Definition WsfRigidBodySixDOF_Utils.hpp:122
double GetMaxDataAtMach(double aMach) const
Definition WsfRigidBodySixDOF_Utils.cpp:658
Definition WsfRigidBodySixDOF_Mover.hpp:38
Definition WsfRigidBodySixDOF_Utils.hpp:160
std::unique_ptr< RigidBodyMachParamDataTable > mAlphaVsMachCLTable
Definition WsfRigidBodySixDOF_Utils.hpp:218
int CountValidStickAndCL(double aMach, std::vector< double > aAlphaVector_deg)
Definition WsfRigidBodySixDOF_Utils.cpp:1708
bool CalcStickAndCL(double aMach, double aAlpha_rad, double &aStickBackBaseline, double &aStickBackThrustShift, double &aStickBackXCmShift, double &aStickBackZCmShift)
Definition WsfRigidBodySixDOF_Utils.cpp:1660
void AddAlphaVsMachCL(double aMach, double aCL, double aMinAlpha_deg, double aMaxAlpha_deg, bool &aMachAdded)
Definition WsfRigidBodySixDOF_Utils.cpp:1579
void AddStickAndCL(double aMach, double aAlpha_rad, double &aStickBack, bool &aMachAdded, bool aLowPoint, bool aHighPoint)
Definition WsfRigidBodySixDOF_Utils.cpp:1730
void CreateMachTestList(double aMaxMach)
Definition WsfRigidBodySixDOF_Utils.cpp:1957
std::vector< double > mMachTestList
Definition WsfRigidBodySixDOF_Utils.hpp:222
std::unique_ptr< RigidBodyMachDataTable > mCLMinVsMachTable
Definition WsfRigidBodySixDOF_Utils.hpp:210
void OutputCLMaxMachTableToInputString(std::string &aInput) const
Definition WsfRigidBodySixDOF_Utils.cpp:1858
std::unique_ptr< RigidBodyMachParamDataTable > mZcgDeltaStickForZeroMomentVsMachAlphaTablePtr
Definition WsfRigidBodySixDOF_Utils.hpp:216
void OutputStickMachAlphaTablesToInputString(std::string &aInput) const
Definition WsfRigidBodySixDOF_Utils.cpp:1910
RigidBodyTableTool(RigidBodyMover *aObject)
Definition WsfRigidBodySixDOF_Utils.cpp:1261
std::unique_ptr< RigidBodyMachParamDataTable > mStickForZeroMomentVsMachAlphaTablePtr
Definition WsfRigidBodySixDOF_Utils.hpp:213
void OutputAlphaMaxMachTableToInputString(std::string &aInput) const
Definition WsfRigidBodySixDOF_Utils.cpp:1878
void InitializeTableMachValues(double aMaxMach)
Definition WsfRigidBodySixDOF_Utils.cpp:1952
void OutputAlphaMinMachTableToInputString(std::string &aInput) const
Definition WsfRigidBodySixDOF_Utils.cpp:1888
RigidBodyMover * mObject
Definition WsfRigidBodySixDOF_Utils.hpp:208
std::unique_ptr< RigidBodyMachDataTable > mAlphaMax_degVsMachTable
Definition WsfRigidBodySixDOF_Utils.hpp:211
void OutputCLMinMachTableToInputString(std::string &aInput) const
Definition WsfRigidBodySixDOF_Utils.cpp:1868
std::unique_ptr< RigidBodyMachDataTable > mCLMaxVsMachTable
Definition WsfRigidBodySixDOF_Utils.hpp:209
double CalcCLFromCLArea(double aCLArea)
Definition WsfRigidBodySixDOF_Utils.cpp:1526
bool mTableListsInitialized
Definition WsfRigidBodySixDOF_Utils.hpp:223
std::unique_ptr< RigidBodyMachParamDataTable > mThrustDeltaStickForZeroMomentVsMachAlphaTablePtr
Definition WsfRigidBodySixDOF_Utils.hpp:214
void OutputAlphaMachCLTableToInputString(std::string &aInput) const
Definition WsfRigidBodySixDOF_Utils.cpp:1898
bool CreateAutopilotTables()
Definition WsfRigidBodySixDOF_Utils.cpp:1547
bool CalculateStickForZeroMoment(double aMach, double aAlpha_rad, bool aIsPowerOn, double &aThrustProduced_lbs, double &aStickBack)
Definition WsfRigidBodySixDOF_Utils.cpp:1284
std::unique_ptr< RigidBodyMachDataTable > mAlphaMin_degVsMachTable
Definition WsfRigidBodySixDOF_Utils.hpp:212
std::unique_ptr< RigidBodyMachParamDataTable > mXcgDeltaStickForZeroMomentVsMachAlphaTablePtr
Definition WsfRigidBodySixDOF_Utils.hpp:215
void OutputCLMachAlphaTableToInputString(std::string &aInput) const
Definition WsfRigidBodySixDOF_Utils.cpp:1940
std::unique_ptr< RigidBodyMachParamDataTable > mCLVsMachAlphaTable
Definition WsfRigidBodySixDOF_Utils.hpp:217
Definition WsfPointMassSixDOF_Utils.hpp:34
WSF_SIX_DOF_EXPORT void CreateAutopilotConfigFile(PointMassMover *aVehicle, const std::string &aFilename)
Definition WsfPointMassSixDOF_Utils.cpp:49
WSF_SIX_DOF_EXPORT std::vector< Pid::Type > GetRelevantPids(const RigidBodyMover *aVehicle)
Definition WsfRigidBodySixDOF_Utils.cpp:414
WSF_SIX_DOF_EXPORT void CommonCreateAutopilotSupportFile(PointMassTableTool &aTool, const std::string &aFilename)
Definition WsfPointMassSixDOF_Utils.cpp:273
WSF_SIX_DOF_EXPORT RigidBodyMover * CastToRigidBody(Mover *aVehicle)
Definition WsfRigidBodySixDOF_Utils.cpp:44
WSF_SIX_DOF_EXPORT double GetSphericalEarthRadius_m()
WSF_SIX_DOF_EXPORT void CreateAutopilotSupportFileWithMaxMach(PointMassMover *aObject, const std::string &aFilename, const double &aMaxMach)
Definition WsfPointMassSixDOF_Utils.cpp:262
WSF_SIX_DOF_EXPORT CanFlyAtReturnValue CanFlyAt(PointMassMover *aObject, double aAltitude_ft, double aVelocity_fps, double aThrottleForward, double aFlapsDown)
Definition WsfPointMassSixDOF_Utils.cpp:200
CanFlyAtReturnValue
Definition WsfSixDOF_Utils.hpp:31
WSF_SIX_DOF_EXPORT void CreateAutopilotSupportFile(PointMassMover *aObject, const std::string &aFilename)
Definition WsfPointMassSixDOF_Utils.cpp:252
Definition WsfSA_Processor.hpp:35
Function definitions for those who need run-time access to the version.
Definition WsfComm.cpp:32
Definition WsfRigidBodySixDOF_Utils.hpp:149
double value
Definition WsfRigidBodySixDOF_Utils.hpp:151
double mach
Definition WsfRigidBodySixDOF_Utils.hpp:150
Definition WsfRigidBodySixDOF_Utils.hpp:107
double mach
Definition WsfRigidBodySixDOF_Utils.hpp:108
std::vector< paramDataPair * > paramDataList
Definition WsfRigidBodySixDOF_Utils.hpp:109
Definition WsfRigidBodySixDOF_Utils.hpp:101
double value
Definition WsfRigidBodySixDOF_Utils.hpp:103
double parameter
Definition WsfRigidBodySixDOF_Utils.hpp:102
Copyrights Multiple, All Rights Reserved