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