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