JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGThruster.cpp
1/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 Module: FGThruster.cpp
4 Author: Jon S. Berndt
5 Date started: 08/23/00
6 Purpose: Encapsulates the thruster object
7
8 ------------- Copyright (C) 2000 Jon S. Berndt (jon@jsbsim.org) -------------
9
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU Lesser General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
13 version.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18 details.
19
20 You should have received a copy of the GNU Lesser General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22 Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 Further information about the GNU Lesser General Public License can also be found on
25 the world wide web at http://www.gnu.org.
26
27FUNCTIONAL DESCRIPTION
28--------------------------------------------------------------------------------
29
30HISTORY
31--------------------------------------------------------------------------------
3208/23/00 JSB Created
33
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35INCLUDES
36%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37
38#include "FGFDMExec.h"
39#include "input_output/FGPropertyManager.h"
40#include "FGThruster.h"
41#include "input_output/FGXMLElement.h"
42#include "input_output/FGLog.h"
43
44using namespace std;
45
46namespace JSBSim {
47
48/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49CLASS IMPLEMENTATION
50%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51
52
53FGThruster::FGThruster(FGFDMExec *FDMExec, Element *el, int num ): FGForce(FDMExec)
54{
55 Element* thruster_element = el->GetParent();
56 Element* element;
57 FGColumnVector3 location, orientation, pointing;
58
59 Type = ttDirect;
60 SetTransformType(FGForce::tCustom);
61
62 Name = el->GetAttributeValue("name");
63
64 GearRatio = 1.0;
65 EngineNum = num;
66 auto PropertyManager = FDMExec->GetPropertyManager();
67
68// Determine the initial location and orientation of this thruster and load the
69// thruster with this information.
70
71 element = thruster_element->FindElement("location");
72 if (element) location = element->FindElementTripletConvertTo("IN");
73 else {
74 FGXMLLogging log(thruster_element, LogLevel::ERROR);
75 log << LogFormat::RED << " No thruster location found."
76 << LogFormat::RESET << "\n";
77 }
78
79 SetLocation(location);
80
81 string property_name, base_property_name;
82 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNum);
83
84 property_name = base_property_name + "/x-reference-position";
85 PropertyManager->Tie(property_name.c_str(), (FGForce*)this, &FGForce::GetLocationX);
86 property_name = base_property_name + "/y-reference-position";
87 PropertyManager->Tie(property_name.c_str(), (FGForce*)this, &FGForce::GetLocationY);
88 property_name = base_property_name + "/z-reference-position";
89 PropertyManager->Tie(property_name.c_str(), (FGForce*)this, &FGForce::GetLocationZ);
90 property_name = base_property_name + "/x-position";
91 PropertyManager->Tie(property_name.c_str(), (FGForce*)this, &FGForce::GetActingLocationX, &FGForce::SetActingLocationX);
92 property_name = base_property_name + "/y-position";
93 PropertyManager->Tie(property_name.c_str(), (FGForce*)this, &FGForce::GetActingLocationY, &FGForce::SetActingLocationY);
94 property_name = base_property_name + "/z-position";
95 PropertyManager->Tie(property_name.c_str(), (FGForce*)this, &FGForce::GetActingLocationZ, &FGForce::SetActingLocationZ);
96
97 element = thruster_element->FindElement("pointing");
98 if (element) {
99
100 // This defines a fixed nozzle that has no public interface property to gimbal or reverse it.
101 pointing = element->FindElementTripletConvertTo("RAD"); // The specification of RAD here is superfluous,
102 // and simply precludes a conversion.
103 mT.InitMatrix();
104 mT(1,1) = pointing(1);
105 mT(2,1) = pointing(2);
106 mT(3,1) = pointing(3);
107
108 } else {
109
110 element = thruster_element->FindElement("orient");
111 if (element) orientation = element->FindElementTripletConvertTo("RAD");
112
113 SetAnglesToBody(orientation);
114 property_name = base_property_name + "/pitch-angle-rad";
115 PropertyManager->Tie( property_name.c_str(), (FGForce *)this, &FGForce::GetPitch, &FGForce::SetPitch);
116 property_name = base_property_name + "/yaw-angle-rad";
117 PropertyManager->Tie( property_name.c_str(), (FGForce *)this, &FGForce::GetYaw, &FGForce::SetYaw);
118
119 if (el->GetName() == "direct") // this is a direct thruster. At this time
120 // only a direct thruster can be reversed.
121 {
122 property_name = base_property_name + "/reverser-angle-rad";
123 PropertyManager->Tie( property_name.c_str(), (FGThruster *)this, &FGThruster::GetReverserAngle,
124 &FGThruster::SetReverserAngle);
125 }
126
127 }
128
129 ResetToIC();
130
131 Debug(0);
132}
133
134//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135
137{
138 Debug(1);
139}
140
141//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142
143void FGThruster::ResetToIC(void)
144{
145 ReverserAngle = 0.0;
146 Thrust = 0.0;
147 SetActingLocation(vXYZn);
148}
149
150//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151
152string FGThruster::GetThrusterLabels(int id, const string& delimeter)
153{
154 std::ostringstream buf;
155
156 buf << Name << " Thrust (engine " << id << " in lbs)";
157
158 return buf.str();
159}
160
161//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162
163string FGThruster::GetThrusterValues(int id, const string& delimeter)
164{
165 std::ostringstream buf;
166
167 buf << Thrust;
168
169 return buf.str();
170}
171
172//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173// The bitmasked value choices are as follows:
174// unset: In this case (the default) JSBSim would only print
175// out the normally expected messages, essentially echoing
176// the config files as they are read. If the environment
177// variable is not set, debug_lvl is set to 1 internally
178// 0: This requests JSBSim not to output any messages
179// whatsoever.
180// 1: This value explicity requests the normal JSBSim
181// startup messages
182// 2: This value asks for a message to be printed out when
183// a class is instantiated
184// 4: When this value is set, a message is displayed when a
185// FGModel object executes its Run() method
186// 8: When this value is set, various runtime state variables
187// are printed out periodically
188// 16: When set various parameters are sanity checked and
189// a message is printed out when they go out of bounds
190
191void FGThruster::Debug(int from)
192{
193 if (debug_lvl <= 0) return;
194
195 if (debug_lvl & 1) { // Standard console startup message output
196 if (from == 0) { // Constructor
197
198 }
199 }
200 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
201 FGLogging log(LogLevel::DEBUG);
202 if (from == 0) log << "Instantiated: FGThruster\n";
203 if (from == 1) log << "Destroyed: FGThruster\n";
204 }
205 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
206 }
207 if (debug_lvl & 8 ) { // Runtime state variables
208 }
209 if (debug_lvl & 16) { // Sanity checking
210 }
211 if (debug_lvl & 64) {
212 if (from == 0) { // Constructor
213 }
214 }
215}
216}
Element * FindElement(const std::string &el="")
Searches for a specified element.
const std::string & GetName(void) const
Retrieves the element name.
FGColumnVector3 FindElementTripletConvertTo(const std::string &target_units)
Composes a 3-element column vector for the supplied location or orientation.
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
Element * GetParent(void)
Returns a pointer to the parent of an element.
This class implements a 3 element column vector.
Encapsulates the JSBSim simulation executive.
Definition FGFDMExec.h:185
std::shared_ptr< FGPropertyManager > GetPropertyManager(void) const
Returns a pointer to the property manager object.
Definition FGFDMExec.h:422
Utility class that aids in the conversion of forces between coordinate systems and calculation of mom...
Definition FGForce.h:222
void SetActingLocation(double x, double y, double z)
Acting point of application.
Definition FGForce.h:256
void InitMatrix(void)
Initialize the matrix.
Base class for specific thrusting devices such as propellers, nozzles, etc.
Definition FGThruster.h:77
virtual ~FGThruster()
Destructor.
FGThruster(FGFDMExec *FDMExec, Element *el, int num)
Constructor.
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71