FlightGear next
FGThruster.cpp
Go to the documentation of this file.
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 <iostream>
39#include <sstream>
40
41#include "FGFDMExec.h"
43#include "FGThruster.h"
45
46using namespace std;
47
48namespace JSBSim {
49
50/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51CLASS IMPLEMENTATION
52%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
54
56{
57 Element* thruster_element = el->GetParent();
58 Element* element;
59 FGColumnVector3 location, orientation, pointing;
60
61 Type = ttDirect;
63
64 Name = el->GetAttributeValue("name");
65
66 GearRatio = 1.0;
67 EngineNum = num;
68 FGPropertyManager* 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,
110 }
111
112 }
113
114 ResetToIC();
115
116 Debug(0);
117}
118
119//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120
122{
123 Debug(1);
124}
125
126//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127
129{
130 ReverserAngle = 0.0;
131 Thrust = 0.0;
133}
134
135//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136
137string 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
148string 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
176void 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}
JSBSim::FGFDMExec * FDMExec
Definition JSBSim.cpp:88
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.
Element * GetParent(void)
Returns a pointer to the parent of an element.
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
Element * FindElement(const std::string &el="")
Searches for a specified element.
This class implements a 3 element column vector.
void SetTransformType(TransformType ii)
Definition FGForce.h:302
void SetYaw(double yaw)
Definition FGForce.h:294
double GetPitch(void) const
Definition FGForce.h:296
double GetYaw(void) const
Definition FGForce.h:297
FGColumnVector3 vXYZn
Definition FGForce.h:314
FGMatrix33 mT
Definition FGForce.h:316
FGForce(FGFDMExec *FDMExec)
Constructor.
Definition FGForce.cpp:53
void SetAnglesToBody(double broll, double bpitch, double byaw)
Definition FGForce.cpp:147
void SetActingLocation(double x, double y, double z)
Acting point of application.
Definition FGForce.h:257
void SetLocation(double x, double y, double z)
Definition FGForce.h:242
void SetPitch(double pitch)
Definition FGForce.h:293
static char reset[5]
resets text properties
Definition FGJSBBase.h:129
static char fgred[6]
red text
Definition FGJSBBase.h:139
static short debug_lvl
Definition FGJSBBase.h:190
static std::string CreateIndexedPropertyName(const std::string &Property, int index)
void Tie(const std::string &name, T *pointer)
Tie a property to an external variable.
virtual void Debug(int from)
virtual std::string GetThrusterValues(int id, const std::string &delimeter)
std::string Name
Definition FGThruster.h:125
virtual std::string GetThrusterLabels(int id, const std::string &delimeter)
double GetReverserAngle(void) const
Definition FGThruster.h:100
virtual void ResetToIC(void)
virtual ~FGThruster()
Destructor.
FGThruster(FGFDMExec *FDMExec, Element *el, int num)
Constructor.
void SetReverserAngle(double angle)
Definition FGThruster.h:99