JSBSim Flight Dynamics Model  1.2.0 (05 Nov 2023)
An Open Source Flight Dynamics and Control Software Library in C++
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 
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29 
30 HISTORY
31 --------------------------------------------------------------------------------
32 08/23/00 JSB Created
33 
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 INCLUDES
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37 
38 #include <iostream>
39 #include <sstream>
40 
41 #include "FGFDMExec.h"
42 #include "input_output/FGPropertyManager.h"
43 #include "FGThruster.h"
44 #include "input_output/FGXMLElement.h"
45 
46 using namespace std;
47 
48 namespace JSBSim {
49 
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 CLASS IMPLEMENTATION
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53 
54 
55 FGThruster::FGThruster(FGFDMExec *FDMExec, Element *el, int num ): FGForce(FDMExec)
56 {
57  Element* thruster_element = el->GetParent();
58  Element* element;
59  FGColumnVector3 location, orientation, pointing;
60 
61  Type = ttDirect;
62  SetTransformType(FGForce::tCustom);
63 
64  Name = el->GetAttributeValue("name");
65 
66  GearRatio = 1.0;
67  EngineNum = num;
68  auto PropertyManager = FDMExec->GetPropertyManager();
69 
70 // Determine the initial location and orientation of this thruster and load the
71 // thruster with this information.
72 
73  element = thruster_element->FindElement("location");
74  if (element) location = element->FindElementTripletConvertTo("IN");
75  else cerr << fgred << " No thruster location found." << reset << endl;
76 
77  SetLocation(location);
78 
79  string property_name, base_property_name;
80  base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNum);
81 
82  element = thruster_element->FindElement("pointing");
83  if (element) {
84 
85  // This defines a fixed nozzle that has no public interface property to gimbal or reverse it.
86  pointing = element->FindElementTripletConvertTo("RAD"); // The specification of RAD here is superfluous,
87  // and simply precludes a conversion.
88  mT.InitMatrix();
89  mT(1,1) = pointing(1);
90  mT(2,1) = pointing(2);
91  mT(3,1) = pointing(3);
92 
93  } else {
94 
95  element = thruster_element->FindElement("orient");
96  if (element) orientation = element->FindElementTripletConvertTo("RAD");
97 
98  SetAnglesToBody(orientation);
99  property_name = base_property_name + "/pitch-angle-rad";
100  PropertyManager->Tie( property_name.c_str(), (FGForce *)this, &FGForce::GetPitch, &FGForce::SetPitch);
101  property_name = base_property_name + "/yaw-angle-rad";
102  PropertyManager->Tie( property_name.c_str(), (FGForce *)this, &FGForce::GetYaw, &FGForce::SetYaw);
103 
104  if (el->GetName() == "direct") // this is a direct thruster. At this time
105  // only a direct thruster can be reversed.
106  {
107  property_name = base_property_name + "/reverser-angle-rad";
108  PropertyManager->Tie( property_name.c_str(), (FGThruster *)this, &FGThruster::GetReverserAngle,
109  &FGThruster::SetReverserAngle);
110  }
111 
112  }
113 
114  ResetToIC();
115 
116  Debug(0);
117 }
118 
119 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 
122 {
123  Debug(1);
124 }
125 
126 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127 
128 void FGThruster::ResetToIC(void)
129 {
130  ReverserAngle = 0.0;
131  Thrust = 0.0;
132  SetActingLocation(vXYZn);
133 }
134 
135 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 
137 string FGThruster::GetThrusterLabels(int id, const string& delimeter)
138 {
139  std::ostringstream buf;
140 
141  buf << Name << " Thrust (engine " << id << " in lbs)";
142 
143  return buf.str();
144 }
145 
146 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147 
148 string FGThruster::GetThrusterValues(int id, const string& delimeter)
149 {
150  std::ostringstream buf;
151 
152  buf << Thrust;
153 
154  return buf.str();
155 }
156 
157 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158 // The bitmasked value choices are as follows:
159 // unset: In this case (the default) JSBSim would only print
160 // out the normally expected messages, essentially echoing
161 // the config files as they are read. If the environment
162 // variable is not set, debug_lvl is set to 1 internally
163 // 0: This requests JSBSim not to output any messages
164 // whatsoever.
165 // 1: This value explicity requests the normal JSBSim
166 // startup messages
167 // 2: This value asks for a message to be printed out when
168 // a class is instantiated
169 // 4: When this value is set, a message is displayed when a
170 // FGModel object executes its Run() method
171 // 8: When this value is set, various runtime state variables
172 // are printed out periodically
173 // 16: When set various parameters are sanity checked and
174 // a message is printed out when they go out of bounds
175 
176 void FGThruster::Debug(int from)
177 {
178  if (debug_lvl <= 0) return;
179 
180  if (debug_lvl & 1) { // Standard console startup message output
181  if (from == 0) { // Constructor
182 
183  }
184  }
185  if (debug_lvl & 2 ) { // Instantiation/Destruction notification
186  if (from == 0) cout << "Instantiated: FGThruster" << endl;
187  if (from == 1) cout << "Destroyed: FGThruster" << endl;
188  }
189  if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
190  }
191  if (debug_lvl & 8 ) { // Runtime state variables
192  }
193  if (debug_lvl & 16) { // Sanity checking
194  }
195  if (debug_lvl & 64) {
196  if (from == 0) { // Constructor
197  }
198  }
199 }
200 }
Element * FindElement(const std::string &el="")
Searches for a specified element.
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.
Definition: FGXMLElement.h:225
const std::string & GetName(void) const
Retrieves the element name.
Definition: FGXMLElement.h:179
This class implements a 3 element column vector.
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:184
std::shared_ptr< FGPropertyManager > GetPropertyManager(void) const
Returns a pointer to the property manager object.
Definition: FGFDMExec.h:421
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
static char fgred[6]
red text
Definition: FGJSBBase.h:167
static char reset[5]
resets text properties
Definition: FGJSBBase.h:157
void InitMatrix(void)
Initialize the matrix.
Definition: FGMatrix33.cpp:259
Base class for specific thrusting devices such as propellers, nozzles, etc.
Definition: FGThruster.h:77
virtual ~FGThruster()
Destructor.
Definition: FGThruster.cpp:121