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