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