]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGOutput.cpp
FG_HAVE_STD_INCLUDES -> SG_HAVE_STD_INCLUDES
[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 "FGAircraft.h"
47 #include "FGTranslation.h"
48 #include "FGRotation.h"
49 #include "FGPosition.h"
50 #include "FGAuxiliary.h"
51
52 static const char *IdSrc = "$Header$";
53 static const char *IdHdr = ID_OUTPUT;
54
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 CLASS IMPLEMENTATION
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58
59 FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
60 {
61   Name = "FGOutput";
62   sFirstPass = dFirstPass = true;
63   socket = 0;
64   Type = otNone;
65   Filename = "JSBSim.out";
66   SubSystems = 0;
67   enabled = true;
68   
69 #ifdef FG_WITH_JSBSIM_SOCKET
70   socket = new FGfdmSocket("localhost",1138);
71 #endif
72 }
73
74 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75
76 FGOutput::~FGOutput(void)
77 {
78   if (socket) delete socket;
79 }
80
81 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82
83 bool FGOutput::Run(void)
84 {
85   if (enabled) {
86     if (!FGModel::Run()) {
87
88       if (Type == otSocket) {
89         SocketOutput();
90       } else if (Type == otCSV) {
91         if (Filename != "COUT" && Filename != "cout" && Filename.size() > 0) {
92           DelimitedOutput(Filename);
93         } else {
94           DelimitedOutput();
95         }
96       } else if (Type == otTerminal) {
97         // Not done yet
98       } else if (Type == otNone) {
99         // Do nothing
100       } else {
101         // Not a valid type of output
102       }
103
104     } else {
105     }
106   }
107   return false;
108 }
109
110 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111
112 void FGOutput::SetType(string type)
113 {
114   if (type == "CSV") {
115     Type = otCSV;
116   } else if (type == "TABULAR") {
117     Type = otTab;
118   } else if (type == "SOCKET") {
119     Type = otSocket;
120   } else if (type == "TERMINAL") {
121     Type = otTerminal;
122   } else if (type != "NONE"){
123     Type = otUnknown;
124     cerr << "Unknown type of output specified in config file" << endl;
125   }
126 }
127
128 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129
130 void FGOutput::DelimitedOutput(void)
131 {
132   if (dFirstPass) {
133     cout << "Time";
134     if (SubSystems & FGAircraft::ssSimulation) {
135       // Nothing here, yet
136     }
137     if (SubSystems & FGAircraft::ssAerosurfaces) {
138       cout << ", ";
139       cout << "Throttle, ";
140       cout << "Aileron Cmd, ";
141       cout << "Elevator Cmd, ";
142       cout << "Rudder Cmd, ";
143       cout << "Aileron Pos, ";
144       cout << "Elevator Pos, ";
145       cout << "Rudder Pos";
146     }
147     if (SubSystems & FGAircraft::ssRates) {
148       cout << ", ";
149       cout << "P, Q, R";
150     }
151     if (SubSystems & FGAircraft::ssVelocities) {
152       cout << ", ";
153       cout << "QBar, ";
154       cout << "Vtotal, ";
155       cout << "U, V, W, ";
156       cout << "Vn, Ve, Vd";
157     }
158     if (SubSystems & FGAircraft::ssForces) {
159       cout << ", ";
160       cout << "XsForce, YsForce, ZsForce, ";
161       cout << "Xforce, Yforce, Zforce";
162     }
163     if (SubSystems & FGAircraft::ssMoments) {
164       cout << ", ";
165       cout << "L, M, N";
166     }
167     if (SubSystems & FGAircraft::ssAtmosphere) {
168       cout << ", ";
169       cout << "Rho";
170     }
171     if (SubSystems & FGAircraft::ssMassProps) {
172       cout << ", ";
173       cout << "Ixx, ";
174       cout << "Iyy, ";
175       cout << "Izz, ";
176       cout << "Ixz, ";
177       cout << "Mass, ";
178       cout << "Xcg, Ycg, Zcg";
179     }
180     if (SubSystems & FGAircraft::ssPosition) {
181       cout << ", ";
182       cout << "Altitude, ";
183       cout << "Phi, Tht, Psi, ";
184       cout << "Alpha, ";
185       cout << "Latitude, ";
186       cout << "Longitude, ";
187       cout << "Distance AGL, ";
188       cout << "Runway Radius";
189     }
190     if (SubSystems & FGAircraft::ssCoefficients) {
191       cout << ", ";
192       cout << Aircraft->GetCoefficientStrings();
193     }
194     if (SubSystems & FGAircraft::ssGroundReactions) {
195       cout << ", ";
196       cout << Aircraft->GetGroundReactionStrings();
197     }
198
199     cout << endl;
200     dFirstPass = false;
201   }
202
203   cout << State->Getsim_time();
204   if (SubSystems & FGAircraft::ssSimulation) {
205   }
206   if (SubSystems & FGAircraft::ssAerosurfaces) {
207     cout << ", ";
208     cout << FCS->GetThrottlePos(0) << ", ";
209     cout << FCS->GetDaCmd() << ", ";
210     cout << FCS->GetDeCmd() << ", ";
211     cout << FCS->GetDrCmd() << ", ";
212     cout << FCS->GetDaPos() << ", ";
213     cout << FCS->GetDePos() << ", ";
214     cout << FCS->GetDrPos();
215   }
216   if (SubSystems & FGAircraft::ssRates) {
217     cout << ", ";
218     cout << Rotation->GetPQR();
219   }
220   if (SubSystems & FGAircraft::ssVelocities) {
221     cout << ", ";
222     cout << Translation->Getqbar() << ", ";
223     cout << Translation->GetVt() << ", ";
224     cout << Translation->GetUVW() << ", ";
225     cout << Position->GetVel();
226   }
227   if (SubSystems & FGAircraft::ssForces) {
228     cout << ", ";
229     cout << Aircraft->GetvFs() << ", ";
230     cout << Aircraft->GetForces();
231   }
232   if (SubSystems & FGAircraft::ssMoments) {
233     cout << ", ";
234     cout << Aircraft->GetMoments();
235   }
236   if (SubSystems & FGAircraft::ssAtmosphere) {
237     cout << ", ";
238     cout << Atmosphere->GetDensity();
239   }
240   if (SubSystems & FGAircraft::ssMassProps) {
241     cout << ", ";
242     cout << Aircraft->GetIxx() << ", ";
243     cout << Aircraft->GetIyy() << ", ";
244     cout << Aircraft->GetIzz() << ", ";
245     cout << Aircraft->GetIxz() << ", ";
246     cout << Aircraft->GetMass() << ", ";
247     cout << Aircraft->GetXYZcg();
248   }
249   if (SubSystems & FGAircraft::ssPosition) {
250     cout << ", ";
251     cout << Position->Geth() << ", ";
252     cout << Rotation->GetEuler() << ", ";
253     cout << Translation->Getalpha() << ", ";
254     cout << Position->GetLatitude() << ", ";
255     cout << Position->GetLongitude() << ", ";
256     cout << Position->GetDistanceAGL() << ", ";
257     cout << Position->GetRunwayRadius();
258   }
259   if (SubSystems & FGAircraft::ssCoefficients) {
260     cout << ", ";
261     cout << Aircraft->GetCoefficientValues();
262   }
263   if (SubSystems & FGAircraft::ssGroundReactions) {
264     cout << ", ";
265     cout << Aircraft->GetGroundReactionValues();
266   }
267   cout << endl;
268 }
269
270 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271
272 void FGOutput::DelimitedOutput(string fname)
273 {
274   if (sFirstPass) {
275     datafile.open(fname.c_str());
276     datafile << "Time";
277     if (SubSystems & FGAircraft::ssSimulation) {
278       // Nothing here, yet
279     }
280     if (SubSystems & FGAircraft::ssAerosurfaces) {
281       datafile << ", ";
282       datafile << "Throttle, ";
283       datafile << "Aileron Cmd, ";
284       datafile << "Elevator Cmd, ";
285       datafile << "Rudder Cmd, ";
286       datafile << "Aileron Pos, ";
287       datafile << "Elevator Pos, ";
288       datafile << "Rudder Pos";
289     }
290     if (SubSystems & FGAircraft::ssRates) {
291       datafile << ", ";
292       datafile << "P, Q, R";
293     }
294     if (SubSystems & FGAircraft::ssVelocities) {
295       datafile << ", ";
296       datafile << "QBar, ";
297       datafile << "Vtotal, ";
298       datafile << "U, V, W, ";
299       datafile << "Vn, Ve, Vd";
300     }
301     if (SubSystems & FGAircraft::ssForces) {
302       datafile << ", ";
303       datafile << "XsForce, YsForce, ZsForce, ";
304       datafile << "Xforce, Yforce, Zforce";
305     }
306     if (SubSystems & FGAircraft::ssMoments) {
307       datafile << ", ";
308       datafile << "L, M, N";
309     }
310     if (SubSystems & FGAircraft::ssAtmosphere) {
311       datafile << ", ";
312       datafile << "Rho";
313     }
314     if (SubSystems & FGAircraft::ssMassProps) {
315       datafile << ", ";
316       datafile << "Ixx, ";
317       datafile << "Iyy, ";
318       datafile << "Izz, ";
319       datafile << "Ixz, ";
320       datafile << "Mass, ";
321       datafile << "Xcg, Ycg, Zcg";
322     }
323     if (SubSystems & FGAircraft::ssPosition) {
324       datafile << ", ";
325       datafile << "Altitude, ";
326       datafile << "Phi, Tht, Psi, ";
327       datafile << "Alpha, ";
328       datafile << "Latitude, ";
329       datafile << "Longitude, ";
330       datafile << "Distance AGL, ";
331       datafile << "Runway Radius";
332     }
333     if (SubSystems & FGAircraft::ssCoefficients) {
334       datafile << ", ";
335       datafile << Aircraft->GetCoefficientStrings();
336     }
337     if (SubSystems & FGAircraft::ssGroundReactions) {
338       datafile << ", ";
339       datafile << Aircraft->GetGroundReactionStrings();
340     }
341     if (SubSystems & FGAircraft::ssFCS) {
342       datafile << ", ";
343       datafile << FCS->GetComponentStrings();
344     }
345     datafile << endl;
346     sFirstPass = false;
347   }
348
349   datafile << State->Getsim_time();
350   if (SubSystems & FGAircraft::ssSimulation) {
351   }
352   if (SubSystems & FGAircraft::ssAerosurfaces) {
353     datafile << ", ";
354     datafile << FCS->GetThrottlePos(0) << ", ";
355     datafile << FCS->GetDaCmd() << ", ";
356     datafile << FCS->GetDeCmd() << ", ";
357     datafile << FCS->GetDrCmd() << ", ";
358     datafile << FCS->GetDaPos() << ", ";
359     datafile << FCS->GetDePos() << ", ";
360     datafile << FCS->GetDrPos();
361   }
362   if (SubSystems & FGAircraft::ssRates) {
363     datafile << ", ";
364     datafile << Rotation->GetPQR();
365   }
366   if (SubSystems & FGAircraft::ssVelocities) {
367     datafile << ", ";
368     datafile << Translation->Getqbar() << ", ";
369     datafile << Translation->GetVt() << ", ";
370     datafile << Translation->GetUVW() << ", ";
371     datafile << Position->GetVel();
372   }
373   if (SubSystems & FGAircraft::ssForces) {
374     datafile << ", ";
375     datafile << Aircraft->GetvFs() << ", ";
376     datafile << Aircraft->GetForces();
377   }
378   if (SubSystems & FGAircraft::ssMoments) {
379     datafile << ", ";
380     datafile << Aircraft->GetMoments();
381   }
382   if (SubSystems & FGAircraft::ssAtmosphere) {
383     datafile << ", ";
384     datafile << Atmosphere->GetDensity();
385   }
386   if (SubSystems & FGAircraft::ssMassProps) {
387     datafile << ", ";
388     datafile << Aircraft->GetIxx() << ", ";
389     datafile << Aircraft->GetIyy() << ", ";
390     datafile << Aircraft->GetIzz() << ", ";
391     datafile << Aircraft->GetIxz() << ", ";
392     datafile << Aircraft->GetMass() << ", ";
393     datafile << Aircraft->GetXYZcg();
394   }
395   if (SubSystems & FGAircraft::ssPosition) {
396     datafile << ", ";
397     datafile << Position->Geth() << ", ";
398     datafile << Rotation->GetEuler() << ", ";
399     datafile << Translation->Getalpha() << ", ";
400     datafile << Position->GetLatitude() << ", ";
401     datafile << Position->GetLongitude() << ", ";
402     datafile << Position->GetDistanceAGL() << ", ";
403     datafile << Position->GetRunwayRadius();
404   }
405   if (SubSystems & FGAircraft::ssCoefficients) {
406     datafile << ", ";
407     datafile << Aircraft->GetCoefficientValues();
408   }
409   if (SubSystems & FGAircraft::ssGroundReactions) {
410     datafile << ", ";
411     datafile << Aircraft->GetGroundReactionValues();
412   }
413   if (SubSystems & FGAircraft::ssFCS) {
414     datafile << ", ";
415     datafile << FCS->GetComponentValues();
416   }
417   datafile << endl;
418   datafile.flush();
419 }
420
421 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
422
423 void FGOutput::SocketOutput(void)
424 {
425   string asciiData;
426   /*
427   if (socket == NULL) return;
428
429   socket->Clear();
430   if (sFirstPass) {
431     socket->Append("<LABELS>");
432     socket->Append("Time");
433     socket->Append("Altitude");
434     socket->Append("Phi");
435     socket->Append("Tht");
436     socket->Append("Psi");
437     socket->Append("Rho");
438     socket->Append("Vtotal");
439     socket->Append("U");
440     socket->Append("V");
441     socket->Append("W");
442     socket->Append("Vn");
443     socket->Append("Ve");
444     socket->Append("Vd");
445     socket->Append("Udot");
446     socket->Append("Vdot");
447     socket->Append("Wdot");
448     socket->Append("P");
449     socket->Append("Q");
450     socket->Append("R");
451     socket->Append("PDot");
452     socket->Append("QDot");
453     socket->Append("RDot");
454     socket->Append("Fx");
455     socket->Append("Fy");
456     socket->Append("Fz");
457     socket->Append("Latitude");
458     socket->Append("Longitude");
459     socket->Append("QBar");
460     socket->Append("Alpha");
461     socket->Append("L");
462     socket->Append("M");
463     socket->Append("N");
464     socket->Append("Throttle");
465     socket->Append("Aileron");
466     socket->Append("Elevator");
467     socket->Append("Rudder");
468     sFirstPass = false;
469     socket->Send();
470   }
471
472   socket->Clear();
473   socket->Append(State->Getsim_time());
474   socket->Append(Position->Geth());
475   socket->Append(Rotation->Getphi());
476   socket->Append(Rotation->Gettht());
477   socket->Append(Rotation->Getpsi());
478   socket->Append(Atmosphere->GetDensity());
479   socket->Append(Translation->GetVt());
480   socket->Append(Translation->GetU());
481   socket->Append(Translation->GetV());
482   socket->Append(Translation->GetW());
483   socket->Append(Position->GetVn());
484   socket->Append(Position->GetVe());
485   socket->Append(Position->GetVd());
486   socket->Append(Translation->GetUdot());
487   socket->Append(Translation->GetVdot());
488   socket->Append(Translation->GetWdot());
489   socket->Append(Rotation->GetP());
490   socket->Append(Rotation->GetQ());
491   socket->Append(Rotation->GetR());
492   socket->Append(Rotation->GetPdot());
493   socket->Append(Rotation->GetQdot());
494   socket->Append(Rotation->GetRdot());
495   socket->Append(Aircraft->GetFx());
496   socket->Append(Aircraft->GetFy());
497   socket->Append(Aircraft->GetFz());
498   socket->Append(Position->GetLatitude());
499   socket->Append(Position->GetLongitude());
500   socket->Append(Translation->Getqbar());
501   socket->Append(Translation->Getalpha());
502   socket->Append(Aircraft->GetL());
503   socket->Append(Aircraft->GetM());
504   socket->Append(Aircraft->GetN());
505   socket->Append(FCS->GetThrottle(0));
506   socket->Append(FCS->GetDa());
507   socket->Append(FCS->GetDe());
508   socket->Append(FCS->GetDr());
509   socket->Send(); */
510 }
511
512 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
513
514 void FGOutput::SocketStatusOutput(string out_str)
515 {
516   string asciiData;
517
518   if (socket == NULL) return;
519
520   socket->Clear();
521   asciiData = string("<STATUS>") + out_str;
522   socket->Append(asciiData.c_str());
523   socket->Send();
524 }
525
526 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
527