45 #include "FGThruster.h" 46 #include "input_output/FGXMLElement.h" 52 IDENT(IdSrc,
"$Id: FGRocket.cpp,v 1.39 2015/09/27 09:54:21 bcoconni Exp $");
53 IDENT(IdHdr,ID_ROCKET);
60 :
FGEngine(engine_number, input), isp_function(0L), FDMExec(exec)
65 Element* thrust_table_element = 0;
68 previousFuelNeedPerTank = 0.0;
69 previousOxiNeedPerTank = 0.0;
70 PropellantFlowRate = 0.0;
71 TotalPropellantExpended = 0.0;
72 FuelFlowRate = FuelExpended = 0.0;
73 OxidizerFlowRate = OxidizerExpended = 0.0;
74 SLOxiFlowMax = SLFuelFlowMax = PropFlowMax = 0.0;
78 ThrustVariation = 0.0;
79 TotalIspVariation = 0.0;
87 std::stringstream strEngineNumber;
88 strEngineNumber << EngineNumber;
91 bindmodel(PropertyManager);
104 throw(
"Specific Impulse <isp> must be specified for a rocket engine");
119 PropFlowMax = SLOxiFlowMax + SLFuelFlowMax;
120 MxR = SLOxiFlowMax/SLFuelFlowMax;
129 if (isp_function) Isp = isp_function->
GetValue();
131 thrust_table_element = el->
FindElement(
"thrust_table");
132 if (thrust_table_element) {
133 ThrustTable =
new FGTable(PropertyManager, thrust_table_element);
135 if (variation_element) {
165 PropellantFlowRate = (FuelExpended + OxidizerExpended)/in.TotalDeltaT;
166 TotalPropellantExpended += FuelExpended + OxidizerExpended;
169 if (isp_function) Isp = isp_function->
GetValue();
175 if (ThrustTable != 0L) {
177 if ((in.ThrottlePos[EngineNumber] == 1 || BurnTime > 0.0 ) && !Starved) {
179 VacThrust = ThrustTable->GetValue(TotalPropellantExpended)
180 * (ThrustVariation + 1)
181 * (TotalIspVariation + 1);
182 if (BurnTime <= BuildupTime && BuildupTime > 0.0) {
183 VacThrust *= sin((BurnTime/BuildupTime)*M_PI/2.0);
186 BurnTime += in.TotalDeltaT;
193 if (in.ThrottlePos[EngineNumber] < MinThrottle || Starved) {
203 PctPower = in.ThrottlePos[EngineNumber];
205 VacThrust = Isp * PropellantFlowRate;
211 LoadThrusterInputs();
212 It += Thruster->Calculate(VacThrust) * in.TotalDeltaT;
213 ItVac += VacThrust * in.TotalDeltaT;
227 if (ThrustTable != 0L) {
228 FuelFlowRate = VacThrust/Isp;
229 FuelFlowRate /= (1 + TotalIspVariation);
231 SLFuelFlowMax = PropFlowMax / (1 + MxR);
232 FuelFlowRate = SLFuelFlowMax * PctPower;
235 FuelExpended = FuelFlowRate * in.TotalDeltaT;
243 SLOxiFlowMax = PropFlowMax * MxR / (1 + MxR);
244 OxidizerFlowRate = SLOxiFlowMax * PctPower;
245 OxidizerExpended = OxidizerFlowRate * in.TotalDeltaT;
246 return OxidizerExpended;
251 string FGRocket::GetEngineLabels(
const string& delimiter)
253 std::ostringstream buf;
255 buf << Name <<
" Total Impulse (engine " << EngineNumber <<
" in lbf)" << delimiter
256 << Name <<
" Total Vacuum Impulse (engine " << EngineNumber <<
" in lbf)" << delimiter
257 << Name <<
" Roll Moment (engine " << EngineNumber <<
" in ft-lbf)" << delimiter
258 << Name <<
" Pitch Moment (engine " << EngineNumber <<
" in ft-lbf)" << delimiter
259 << Name <<
" Yaw Moment (engine " << EngineNumber <<
" in ft-lbf)" << delimiter
260 << Name <<
" X Force (engine " << EngineNumber <<
" in lbf)" << delimiter
261 << Name <<
" Y Force (engine " << EngineNumber <<
" in lbf)" << delimiter
262 << Name <<
" Z Force (engine " << EngineNumber <<
" in lbf)" << delimiter
263 << Thruster->GetThrusterLabels(EngineNumber, delimiter);
270 string FGRocket::GetEngineValues(
const string& delimiter)
272 std::ostringstream buf;
274 buf << It << delimiter
275 << ItVac << delimiter
276 << GetMoments().
Dump(delimiter) << delimiter
277 << Thruster->GetBodyForces().
Dump(delimiter) << delimiter
278 << Thruster->GetThrusterValues(EngineNumber, delimiter);
289 string property_name, base_property_name;
290 base_property_name = CreateIndexedPropertyName(
"propulsion/engine", EngineNumber);
292 property_name = base_property_name +
"/total-impulse";
294 property_name = base_property_name +
"/total-vac-impulse";
296 property_name = base_property_name +
"/vacuum-thrust_lbs";
297 PropertyManager->
Tie( property_name.c_str(),
this, &FGRocket::GetVacThrust);
300 property_name = base_property_name +
"/thrust-variation_pct";
303 property_name = base_property_name +
"/total-isp-variation_pct";
307 property_name = base_property_name +
"/oxi-flow-rate-pps";
308 PropertyManager->
Tie( property_name.c_str(),
this, &FGRocket::GetOxiFlowRate);
309 property_name = base_property_name +
"/mixture-ratio";
310 PropertyManager->
Tie( property_name.c_str(),
this, &FGRocket::GetMixtureRatio,
311 &FGRocket::SetMixtureRatio);
312 property_name = base_property_name +
"/isp";
313 PropertyManager->
Tie( property_name.c_str(),
this, &FGRocket::GetIsp,
337 void FGRocket::Debug(
int from)
339 if (debug_lvl <= 0)
return;
343 cout <<
" Engine Name: " << Name << endl;
344 cout <<
" Vacuum Isp = " << Isp << endl;
345 cout <<
" Maximum Throttle = " << MaxThrottle << endl;
346 cout <<
" Minimum Throttle = " << MinThrottle << endl;
347 cout <<
" Fuel Flow (max) = " << SLFuelFlowMax << endl;
348 cout <<
" Oxidizer Flow (max) = " << SLOxiFlowMax << endl;
349 if (SLFuelFlowMax > 0)
350 cout <<
" Mixture ratio = " << SLOxiFlowMax/SLFuelFlowMax << endl;
353 if (debug_lvl & 2 ) {
354 if (from == 0) cout <<
"Instantiated: FGRocket" << endl;
355 if (from == 1) cout <<
"Destroyed: FGRocket" << endl;
357 if (debug_lvl & 4 ) {
359 if (debug_lvl & 8 ) {
361 if (debug_lvl & 16) {
363 if (debug_lvl & 64) {
365 cout << IdSrc << endl;
366 cout << IdHdr << endl;
~FGRocket(void)
Destructor.
double FindElementValueAsNumberConvertTo(const std::string &el, const std::string &target_units)
Searches for the named element and converts and returns the data belonging to it. ...
double GetTotalIspVariation(void) const
Returns the Total Isp variation, if any.
double CalcFuelNeed(void)
The fuel need is calculated based on power levels and flow rate for that power level.
Element * FindElement(const std::string &el="")
Searches for a specified element.
double FindElementValueAsNumber(const std::string &el="")
Searches for the named element and returns the data belonging to it as a number.
void Calculate(void)
Determines the thrust.
double GetValue(void) const
Retrieves the value of the function object.
FGPropertyManager * GetPropertyManager(void)
Returns a pointer to the property manager object.
std::string Dump(const std::string &delimeter) const
Prints the contents of the vector.
void Tie(const std::string &name, bool *pointer, bool useDefault=true)
Tie a property to an external bool variable.
double GetTotalImpulse(void) const
Gets the total impulse of the rocket.
void SetThrustVariation(double var)
Sets the thrust variation for a solid rocket engine.
Represents a mathematical function.
double GetThrustVariation(void) const
Returns the thrust variation, if any.
double CalcOxidizerNeed(void)
The oxidizer need is calculated based on power levels and flow rate for that power level...
bool IntegrationSuspended(void) const
Returns the simulation suspension state.
Base class for all engines.
void SetTotalIspVariation(double var)
Sets the variation in total motor energy.
Encapsulates the JSBSim simulation executive.
double GetVacTotalImpulse(void) const
Gets the total impulse of the rocket.