]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGOutput.cpp
Latest updates from the JSBSim project.
[flightgear.git] / src / FDM / JSBSim / FGOutput.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGOutput.cpp
4  Author:       Jon Berndt
5  Date started: 12/02/98
6  Purpose:      Manage output of sim parameters to file or stdout
7  Called by:    FGSimExec
8
9  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
10
11  This program is free software; you can redistribute it and/or modify it under
12  the terms of the GNU General Public License as published by the Free Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  version.
15
16  This program is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  details.
20
21  You should have received a copy of the GNU General Public License along with
22  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23  Place - Suite 330, Boston, MA  02111-1307, USA.
24
25  Further information about the GNU General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This is the place where you create output routines to dump data for perusal
31 later. 
32
33 HISTORY
34 --------------------------------------------------------------------------------
35 12/02/98   JSB   Created
36
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include "FGOutput.h"
42 #include "FGState.h"
43 #include "FGFDMExec.h"
44 #include "FGAtmosphere.h"
45 #include "FGFCS.h"
46 #include "FGAerodynamics.h"
47 #include "FGGroundReactions.h"
48 #include "FGAircraft.h"
49 #include "FGMassBalance.h"
50 #include "FGTranslation.h"
51 #include "FGRotation.h"
52 #include "FGPosition.h"
53 #include "FGAuxiliary.h"
54
55 static const char *IdSrc = "$Id$";
56 static const char *IdHdr = ID_OUTPUT;
57
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 CLASS IMPLEMENTATION
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61
62 FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
63 {
64   Name = "FGOutput";
65   sFirstPass = dFirstPass = true;
66   socket = 0;
67   Type = otNone;
68   Filename = "JSBSim.out";
69   SubSystems = 0;
70   enabled = true;
71   
72 #ifdef FG_WITH_JSBSIM_SOCKET
73   socket = new FGfdmSocket("localhost",1138);
74 #endif
75   if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
76 }
77
78 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79
80 FGOutput::~FGOutput()
81 {
82   if (socket) delete socket;
83   if (debug_lvl & 2) cout << "Destroyed:    FGOutput" << endl;
84 }
85
86 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87
88 bool FGOutput::Run(void)
89 {
90   if (enabled) {
91     if (!FGModel::Run()) {
92
93       if (Type == otSocket) {
94         SocketOutput();
95       } else if (Type == otCSV) {
96         DelimitedOutput(Filename);
97       } else if (Type == otTerminal) {
98         // Not done yet
99       } else if (Type == otNone) {
100         // Do nothing
101       } else {
102         // Not a valid type of output
103       }
104
105     } else {
106     }
107   }
108   return false;
109 }
110
111 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112
113 void FGOutput::SetType(string type)
114 {
115   if (type == "CSV") {
116     Type = otCSV;
117   } else if (type == "TABULAR") {
118     Type = otTab;
119   } else if (type == "SOCKET") {
120     Type = otSocket;
121   } else if (type == "TERMINAL") {
122     Type = otTerminal;
123   } else if (type != "NONE"){
124     Type = otUnknown;
125     cerr << "Unknown type of output specified in config file" << endl;
126   }
127 }
128
129 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130
131 void FGOutput::DelimitedOutput(string fname)
132 {
133 # if defined(sgi) && !defined(__GNUC__)
134   ostream_withassign outstream;
135 # else
136   _IO_ostream_withassign outstream;
137 # endif
138
139   if (fname == "COUT" || fname == "cout") {
140     outstream = cout;
141   } else {
142     datafile.open(fname.c_str());
143     outstream = datafile;
144   }
145
146   if (dFirstPass) {
147     outstream << "Time";
148     if (SubSystems & FGAircraft::ssSimulation) {
149       // Nothing here, yet
150     }
151     if (SubSystems & FGAircraft::ssAerosurfaces) {
152       outstream << ", ";
153       outstream << "Throttle, ";
154       outstream << "Mixture, ";
155       outstream << "Aileron Cmd, ";
156       outstream << "Elevator Cmd, ";
157       outstream << "Rudder Cmd, ";
158       outstream << "Aileron Pos, ";
159       outstream << "Elevator Pos, ";
160       outstream << "Rudder Pos";
161     }
162     if (SubSystems & FGAircraft::ssRates) {
163       outstream << ", ";
164       outstream << "P, Q, R";
165     }
166     if (SubSystems & FGAircraft::ssVelocities) {
167       outstream << ", ";
168       outstream << "QBar, ";
169       outstream << "Vtotal, ";
170       outstream << "UBody, VBody, WBody, ";
171       outstream << "UAero, VAero, WAero, ";
172       outstream << "Vn, Ve, Vd";
173     }
174     if (SubSystems & FGAircraft::ssForces) {
175       outstream << ", ";
176       outstream << "Drag, Side, Lift, ";
177       outstream << "L/D, ";
178       outstream << "Xforce, Yforce, Zforce";
179     }
180     if (SubSystems & FGAircraft::ssMoments) {
181       outstream << ", ";
182       outstream << "L, M, N";
183     }
184     if (SubSystems & FGAircraft::ssAtmosphere) {
185       outstream << ", ";
186       outstream << "Rho";
187     }
188     if (SubSystems & FGAircraft::ssMassProps) {
189       outstream << ", ";
190       outstream << "Ixx, ";
191       outstream << "Iyy, ";
192       outstream << "Izz, ";
193       outstream << "Ixz, ";
194       outstream << "Mass, ";
195       outstream << "Xcg, Ycg, Zcg";
196     }
197     if (SubSystems & FGAircraft::ssPosition) {
198       outstream << ", ";
199       outstream << "Altitude, ";
200       outstream << "Phi, Tht, Psi, ";
201       outstream << "Alpha, ";
202       outstream << "Latitude, ";
203       outstream << "Longitude, ";
204       outstream << "Distance AGL, ";
205       outstream << "Runway Radius";
206     }
207     if (SubSystems & FGAircraft::ssCoefficients) {
208       outstream << ", ";
209       outstream << Aerodynamics->GetCoefficientStrings();
210     }
211     if (SubSystems & FGAircraft::ssGroundReactions) {
212       outstream << ", ";
213       outstream << GroundReactions->GetGroundReactionStrings();
214     }
215     if (SubSystems & FGAircraft::ssPropulsion) {
216       outstream << ", ";
217       outstream << Propulsion->GetPropulsionStrings();
218     }
219
220     outstream << endl;
221     dFirstPass = false;
222   }
223
224   outstream << State->Getsim_time();
225   if (SubSystems & FGAircraft::ssSimulation) {
226   }
227   if (SubSystems & FGAircraft::ssAerosurfaces) {
228     outstream << ", ";
229     outstream << FCS->GetThrottlePos(0) << ", ";
230     outstream << FCS->GetMixturePos(0) << ", ";
231     outstream << FCS->GetDaCmd() << ", ";
232     outstream << FCS->GetDeCmd() << ", ";
233     outstream << FCS->GetDrCmd() << ", ";
234     outstream << FCS->GetDaPos() << ", ";
235     outstream << FCS->GetDePos() << ", ";
236     outstream << FCS->GetDrPos();
237   }
238   if (SubSystems & FGAircraft::ssRates) {
239     outstream << ", ";
240     outstream << Rotation->GetPQR();
241   }
242   if (SubSystems & FGAircraft::ssVelocities) {
243     outstream << ", ";
244     outstream << Translation->Getqbar() << ", ";
245     outstream << Translation->GetVt() << ", ";
246     outstream << Translation->GetUVW() << ", ";
247     outstream << Translation->GetvAero() << ", ";
248     outstream << Position->GetVel();
249   }
250   if (SubSystems & FGAircraft::ssForces) {
251     outstream << ", ";
252     outstream << Aerodynamics->GetvFs() << ", ";
253     outstream << Aerodynamics->GetLoD() << ", ";
254     outstream << Aircraft->GetForces();
255   }
256   if (SubSystems & FGAircraft::ssMoments) {
257     outstream << ", ";
258     outstream << Aircraft->GetMoments();
259   }
260   if (SubSystems & FGAircraft::ssAtmosphere) {
261     outstream << ", ";
262     outstream << Atmosphere->GetDensity();
263   }
264   if (SubSystems & FGAircraft::ssMassProps) {
265     outstream << ", ";
266     outstream << MassBalance->GetIxx() << ", ";
267     outstream << MassBalance->GetIyy() << ", ";
268     outstream << MassBalance->GetIzz() << ", ";
269     outstream << MassBalance->GetIxz() << ", ";
270     outstream << MassBalance->GetMass() << ", ";
271     outstream << MassBalance->GetXYZcg();
272   }
273   if (SubSystems & FGAircraft::ssPosition) {
274     outstream << ", ";
275     outstream << Position->Geth() << ", ";
276     outstream << Rotation->GetEuler() << ", ";
277     outstream << Translation->Getalpha() << ", ";
278     outstream << Position->GetLatitude() << ", ";
279     outstream << Position->GetLongitude() << ", ";
280     outstream << Position->GetDistanceAGL() << ", ";
281     outstream << Position->GetRunwayRadius();
282   }
283   if (SubSystems & FGAircraft::ssCoefficients) {
284     outstream << ", ";
285     outstream << Aerodynamics->GetCoefficientValues();
286   }
287   if (SubSystems & FGAircraft::ssGroundReactions) {
288     outstream << ", ";
289     outstream << GroundReactions->GetGroundReactionValues();
290   }
291   if (SubSystems & FGAircraft::ssPropulsion) {
292     outstream << ", ";
293     outstream << Propulsion->GetPropulsionValues();
294   }
295
296   outstream << endl;
297   outstream.flush();
298 }
299
300 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301
302 void FGOutput::SocketOutput(void)
303 {
304   string asciiData;
305   /*
306   if (socket == NULL) return;
307
308   socket->Clear();
309   if (sFirstPass) {
310     socket->Append("<LABELS>");
311     socket->Append("Time");
312     socket->Append("Altitude");
313     socket->Append("Phi");
314     socket->Append("Tht");
315     socket->Append("Psi");
316     socket->Append("Rho");
317     socket->Append("Vtotal");
318     socket->Append("UBody");
319     socket->Append("VBody");
320     socket->Append("WBody");
321     socket->Append("UAero");
322     socket->Append("VAero");
323     socket->Append("WAero");
324     socket->Append("Vn");
325     socket->Append("Ve");
326     socket->Append("Vd");
327     socket->Append("Udot");
328     socket->Append("Vdot");
329     socket->Append("Wdot");
330     socket->Append("P");
331     socket->Append("Q");
332     socket->Append("R");
333     socket->Append("PDot");
334     socket->Append("QDot");
335     socket->Append("RDot");
336     socket->Append("Fx");
337     socket->Append("Fy");
338     socket->Append("Fz");
339     socket->Append("Latitude");
340     socket->Append("Longitude");
341     socket->Append("QBar");
342     socket->Append("Alpha");
343     socket->Append("L");
344     socket->Append("M");
345     socket->Append("N");
346     socket->Append("Throttle");
347     socket->Append("Aileron");
348     socket->Append("Elevator");
349     socket->Append("Rudder");
350     sFirstPass = false;
351     socket->Send();
352   }
353
354   socket->Clear();
355   socket->Append(State->Getsim_time());
356   socket->Append(Position->Geth());
357   socket->Append(Rotation->Getphi());
358   socket->Append(Rotation->Gettht());
359   socket->Append(Rotation->Getpsi());
360   socket->Append(Atmosphere->GetDensity());
361   socket->Append(Translation->GetVt());
362   socket->Append(Translation->GetUVW(eU));
363   socket->Append(Translation->GetUVW(eV));
364   socket->Append(Translation->GetUVW(eW));
365   socket->Append(Translation->GetvAero(eU));
366   socket->Append(Translation->GetvAero(eV));
367   socket->Append(Translation->GetvAero(eW));
368   socket->Append(Position->GetVn());
369   socket->Append(Position->GetVe());
370   socket->Append(Position->GetVd());
371   socket->Append(Translation->GetUdot());
372   socket->Append(Translation->GetVdot());
373   socket->Append(Translation->GetWdot());
374   socket->Append(Rotation->GetP());
375   socket->Append(Rotation->GetQ());
376   socket->Append(Rotation->GetR());
377   socket->Append(Rotation->GetPdot());
378   socket->Append(Rotation->GetQdot());
379   socket->Append(Rotation->GetRdot());
380   socket->Append(Aircraft->GetFx());
381   socket->Append(Aircraft->GetFy());
382   socket->Append(Aircraft->GetFz());
383   socket->Append(Position->GetLatitude());
384   socket->Append(Position->GetLongitude());
385   socket->Append(Translation->Getqbar());
386   socket->Append(Translation->Getalpha());
387   socket->Append(Aircraft->GetL());
388   socket->Append(Aircraft->GetM());
389   socket->Append(Aircraft->GetN());
390   socket->Append(FCS->GetThrottle(0));
391   socket->Append(FCS->GetDa());
392   socket->Append(FCS->GetDe());
393   socket->Append(FCS->GetDr());
394   socket->Send(); */
395 }
396
397 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
398
399 void FGOutput::SocketStatusOutput(string out_str)
400 {
401   string asciiData;
402
403   if (socket == NULL) return;
404
405   socket->Clear();
406   asciiData = string("<STATUS>") + out_str;
407   socket->Append(asciiData.c_str());
408   socket->Send();
409 }
410
411 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
412
413 void FGOutput::Debug(void)
414 {
415     //TODO: Add your source code here
416 }
417