]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGOutput.cpp
Syncing with the very latest JSBSim development code.
[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 << "Aileron Cmd, ";
155       outstream << "Elevator Cmd, ";
156       outstream << "Rudder Cmd, ";
157       outstream << "Aileron Pos, ";
158       outstream << "Elevator Pos, ";
159       outstream << "Rudder Pos";
160     }
161     if (SubSystems & FGAircraft::ssRates) {
162       outstream << ", ";
163       outstream << "P, Q, R";
164     }
165     if (SubSystems & FGAircraft::ssVelocities) {
166       outstream << ", ";
167       outstream << "QBar, ";
168       outstream << "Vtotal, ";
169       outstream << "UBody, VBody, WBody, ";
170       outstream << "UAero, VAero, WAero, ";
171       outstream << "Vn, Ve, Vd";
172     }
173     if (SubSystems & FGAircraft::ssForces) {
174       outstream << ", ";
175       outstream << "Drag, Side, Lift, ";
176       outstream << "L/D, ";
177       outstream << "Xforce, Yforce, Zforce";
178     }
179     if (SubSystems & FGAircraft::ssMoments) {
180       outstream << ", ";
181       outstream << "L, M, N";
182     }
183     if (SubSystems & FGAircraft::ssAtmosphere) {
184       outstream << ", ";
185       outstream << "Rho";
186     }
187     if (SubSystems & FGAircraft::ssMassProps) {
188       outstream << ", ";
189       outstream << "Ixx, ";
190       outstream << "Iyy, ";
191       outstream << "Izz, ";
192       outstream << "Ixz, ";
193       outstream << "Mass, ";
194       outstream << "Xcg, Ycg, Zcg";
195     }
196     if (SubSystems & FGAircraft::ssPosition) {
197       outstream << ", ";
198       outstream << "Altitude, ";
199       outstream << "Phi, Tht, Psi, ";
200       outstream << "Alpha, ";
201       outstream << "Latitude, ";
202       outstream << "Longitude, ";
203       outstream << "Distance AGL, ";
204       outstream << "Runway Radius";
205     }
206     if (SubSystems & FGAircraft::ssCoefficients) {
207       outstream << ", ";
208       outstream << Aerodynamics->GetCoefficientStrings();
209     }
210     if (SubSystems & FGAircraft::ssGroundReactions) {
211       outstream << ", ";
212       outstream << GroundReactions->GetGroundReactionStrings();
213     }
214     if (SubSystems & FGAircraft::ssPropulsion) {
215       outstream << ", ";
216       outstream << Propulsion->GetPropulsionStrings();
217     }
218
219     outstream << endl;
220     dFirstPass = false;
221   }
222
223   outstream << State->Getsim_time();
224   if (SubSystems & FGAircraft::ssSimulation) {
225   }
226   if (SubSystems & FGAircraft::ssAerosurfaces) {
227     outstream << ", ";
228     outstream << FCS->GetThrottlePos(0) << ", ";
229     outstream << FCS->GetDaCmd() << ", ";
230     outstream << FCS->GetDeCmd() << ", ";
231     outstream << FCS->GetDrCmd() << ", ";
232     outstream << FCS->GetDaPos() << ", ";
233     outstream << FCS->GetDePos() << ", ";
234     outstream << FCS->GetDrPos();
235   }
236   if (SubSystems & FGAircraft::ssRates) {
237     outstream << ", ";
238     outstream << Rotation->GetPQR();
239   }
240   if (SubSystems & FGAircraft::ssVelocities) {
241     outstream << ", ";
242     outstream << Translation->Getqbar() << ", ";
243     outstream << Translation->GetVt() << ", ";
244     outstream << Translation->GetUVW() << ", ";
245     outstream << Translation->GetvAero() << ", ";
246     outstream << Position->GetVel();
247   }
248   if (SubSystems & FGAircraft::ssForces) {
249     outstream << ", ";
250     outstream << Aerodynamics->GetvFs() << ", ";
251     outstream << Aerodynamics->GetLoD() << ", ";
252     outstream << Aircraft->GetForces();
253   }
254   if (SubSystems & FGAircraft::ssMoments) {
255     outstream << ", ";
256     outstream << Aircraft->GetMoments();
257   }
258   if (SubSystems & FGAircraft::ssAtmosphere) {
259     outstream << ", ";
260     outstream << Atmosphere->GetDensity();
261   }
262   if (SubSystems & FGAircraft::ssMassProps) {
263     outstream << ", ";
264     outstream << MassBalance->GetIxx() << ", ";
265     outstream << MassBalance->GetIyy() << ", ";
266     outstream << MassBalance->GetIzz() << ", ";
267     outstream << MassBalance->GetIxz() << ", ";
268     outstream << MassBalance->GetMass() << ", ";
269     outstream << MassBalance->GetXYZcg();
270   }
271   if (SubSystems & FGAircraft::ssPosition) {
272     outstream << ", ";
273     outstream << Position->Geth() << ", ";
274     outstream << Rotation->GetEuler() << ", ";
275     outstream << Translation->Getalpha() << ", ";
276     outstream << Position->GetLatitude() << ", ";
277     outstream << Position->GetLongitude() << ", ";
278     outstream << Position->GetDistanceAGL() << ", ";
279     outstream << Position->GetRunwayRadius();
280   }
281   if (SubSystems & FGAircraft::ssCoefficients) {
282     outstream << ", ";
283     outstream << Aerodynamics->GetCoefficientValues();
284   }
285   if (SubSystems & FGAircraft::ssGroundReactions) {
286     outstream << ", ";
287     outstream << GroundReactions->GetGroundReactionValues();
288   }
289   if (SubSystems & FGAircraft::ssPropulsion) {
290     outstream << ", ";
291     outstream << Propulsion->GetPropulsionValues();
292   }
293
294   outstream << endl;
295   outstream.flush();
296 }
297
298 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
299
300 void FGOutput::SocketOutput(void)
301 {
302   string asciiData;
303   /*
304   if (socket == NULL) return;
305
306   socket->Clear();
307   if (sFirstPass) {
308     socket->Append("<LABELS>");
309     socket->Append("Time");
310     socket->Append("Altitude");
311     socket->Append("Phi");
312     socket->Append("Tht");
313     socket->Append("Psi");
314     socket->Append("Rho");
315     socket->Append("Vtotal");
316     socket->Append("UBody");
317     socket->Append("VBody");
318     socket->Append("WBody");
319     socket->Append("UAero");
320     socket->Append("VAero");
321     socket->Append("WAero");
322     socket->Append("Vn");
323     socket->Append("Ve");
324     socket->Append("Vd");
325     socket->Append("Udot");
326     socket->Append("Vdot");
327     socket->Append("Wdot");
328     socket->Append("P");
329     socket->Append("Q");
330     socket->Append("R");
331     socket->Append("PDot");
332     socket->Append("QDot");
333     socket->Append("RDot");
334     socket->Append("Fx");
335     socket->Append("Fy");
336     socket->Append("Fz");
337     socket->Append("Latitude");
338     socket->Append("Longitude");
339     socket->Append("QBar");
340     socket->Append("Alpha");
341     socket->Append("L");
342     socket->Append("M");
343     socket->Append("N");
344     socket->Append("Throttle");
345     socket->Append("Aileron");
346     socket->Append("Elevator");
347     socket->Append("Rudder");
348     sFirstPass = false;
349     socket->Send();
350   }
351
352   socket->Clear();
353   socket->Append(State->Getsim_time());
354   socket->Append(Position->Geth());
355   socket->Append(Rotation->Getphi());
356   socket->Append(Rotation->Gettht());
357   socket->Append(Rotation->Getpsi());
358   socket->Append(Atmosphere->GetDensity());
359   socket->Append(Translation->GetVt());
360   socket->Append(Translation->GetUVW(eU));
361   socket->Append(Translation->GetUVW(eV));
362   socket->Append(Translation->GetUVW(eW));
363   socket->Append(Translation->GetvAero(eU));
364   socket->Append(Translation->GetvAero(eV));
365   socket->Append(Translation->GetvAero(eW));
366   socket->Append(Position->GetVn());
367   socket->Append(Position->GetVe());
368   socket->Append(Position->GetVd());
369   socket->Append(Translation->GetUdot());
370   socket->Append(Translation->GetVdot());
371   socket->Append(Translation->GetWdot());
372   socket->Append(Rotation->GetP());
373   socket->Append(Rotation->GetQ());
374   socket->Append(Rotation->GetR());
375   socket->Append(Rotation->GetPdot());
376   socket->Append(Rotation->GetQdot());
377   socket->Append(Rotation->GetRdot());
378   socket->Append(Aircraft->GetFx());
379   socket->Append(Aircraft->GetFy());
380   socket->Append(Aircraft->GetFz());
381   socket->Append(Position->GetLatitude());
382   socket->Append(Position->GetLongitude());
383   socket->Append(Translation->Getqbar());
384   socket->Append(Translation->Getalpha());
385   socket->Append(Aircraft->GetL());
386   socket->Append(Aircraft->GetM());
387   socket->Append(Aircraft->GetN());
388   socket->Append(FCS->GetThrottle(0));
389   socket->Append(FCS->GetDa());
390   socket->Append(FCS->GetDe());
391   socket->Append(FCS->GetDr());
392   socket->Send(); */
393 }
394
395 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
396
397 void FGOutput::SocketStatusOutput(string out_str)
398 {
399   string asciiData;
400
401   if (socket == NULL) return;
402
403   socket->Clear();
404   asciiData = string("<STATUS>") + out_str;
405   socket->Append(asciiData.c_str());
406   socket->Send();
407 }
408
409 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
410
411 void FGOutput::Debug(void)
412 {
413     //TODO: Add your source code here
414 }
415