]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGOutput.cpp
Updates to help work the kinks out of JSBsim.
[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. Some machines may not support the ncurses console output. Borland is one
32 of those environments which does not, so the ncurses stuff is commented out.
33
34 HISTORY
35 --------------------------------------------------------------------------------
36 12/02/98   JSB   Created
37
38 ********************************************************************************
39 INCLUDES
40 *******************************************************************************/
41
42 #include "FGOutput.h"
43 #include "FGState.h"
44 #include "FGFDMExec.h"
45 #include "FGAtmosphere.h"
46 #include "FGFCS.h"
47 #include "FGAircraft.h"
48 #include "FGTranslation.h"
49 #include "FGRotation.h"
50 #include "FGPosition.h"
51 #include "FGAuxiliary.h"
52
53 /*******************************************************************************
54 ************************************ CODE **************************************
55 *******************************************************************************/
56
57 FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
58 {
59   Name = "FGOutput";
60   sFirstPass = dFirstPass = true;
61
62 #ifdef FG_WITH_JSBSIM_SOCKET
63   socket = new FGfdmSocket("localhost",1138);
64 #endif
65 }
66
67
68 FGOutput::~FGOutput(void)
69 {
70   if (socket) delete socket;
71 }
72
73
74 bool FGOutput::Run(void)
75 {
76   if (!FGModel::Run()) {
77 //    SocketOutput();
78     DelimitedOutput("JSBSimData.csv");
79   } else {
80   }
81   return false;
82 }
83
84
85 void FGOutput::DelimitedOutput(void)
86 {
87   if (dFirstPass) {
88     cout << "Time,";
89     cout << "Altitude,";
90     cout << "Phi,";
91     cout << "Tht,";
92     cout << "Psi,";
93     cout << "Rho,";
94     cout << "Vtotal,";
95     cout << "U,";
96     cout << "V,";
97     cout << "W,";
98     cout << "Vn,";
99     cout << "Ve,";
100     cout << "Vd,";
101     cout << "Udot,";
102     cout << "Vdot,";
103     cout << "Wdot,";
104     cout << "P,";
105     cout << "Q,";
106     cout << "R,";
107     cout << "PDot,";
108     cout << "QDot,";
109     cout << "RDot,";
110     cout << "Fx,";
111     cout << "Fy,";
112     cout << "Fz,";
113     cout << "Latitude,";
114     cout << "Longitude,";
115     cout << "QBar,";
116     cout << "Alpha,";
117     cout << "L,";
118     cout << "M,";
119     cout << "N,";
120     cout << "Throttle,";
121     cout << "Aileron,";
122     cout << "Elevator,";
123     cout << "Rudder";
124     cout << endl;
125     dFirstPass = false;
126   }
127
128   cout << State->Getsim_time() << ",";
129   cout << State->Geth() << ",";
130   cout << Rotation->Getphi() << ",";
131   cout << Rotation->Gettht() << ",";
132   cout << Rotation->Getpsi() << ",";
133   cout << Atmosphere->GetDensity() << ",";
134   cout << State->GetVt() << ",";
135   cout << Translation->GetU() << ",";
136   cout << Translation->GetV() << ",";
137   cout << Translation->GetW() << ",";
138   cout << Position->GetVn() << ",";
139   cout << Position->GetVe() << ",";
140   cout << Position->GetVd() << ",";
141   cout << Translation->GetUdot() << ",";
142   cout << Translation->GetVdot() << ",";
143   cout << Translation->GetWdot() << ",";
144   cout << Rotation->GetP() << ",";
145   cout << Rotation->GetQ() << ",";
146   cout << Rotation->GetR() << ",";
147   cout << Rotation->GetPdot() << ",";
148   cout << Rotation->GetQdot() << ",";
149   cout << Rotation->GetRdot() << ",";
150   cout << Aircraft->GetFx() << ",";
151   cout << Aircraft->GetFy() << ",";
152   cout << Aircraft->GetFz() << ",";
153   cout << State->Getlatitude() << ",";
154   cout << State->Getlongitude() << ",";
155   cout << State->Getqbar() << ",";
156   cout << Translation->Getalpha() << ",";
157   cout << Aircraft->GetL() << ",";
158   cout << Aircraft->GetM() << ",";
159   cout << Aircraft->GetN() << ",";
160   cout << FCS->GetThrottle(0) << ",";
161   cout << FCS->GetDa() << ",";
162   cout << FCS->GetDe() << ",";
163   cout << FCS->GetDr() << "";
164   cout << endl;
165
166 }
167
168
169 void FGOutput::DelimitedOutput(string fname)
170 {
171   if (sFirstPass) {
172     datafile.open(fname.c_str());
173     datafile << "Time,";
174     datafile << "Altitude,";
175     datafile << "Phi,";
176     datafile << "Tht,";
177     datafile << "Psi,";
178     datafile << "Rho,";
179     datafile << "Vtotal,";
180     datafile << "U,";
181     datafile << "V,";
182     datafile << "W,";
183     datafile << "Vn,";
184     datafile << "Ve,";
185     datafile << "Vd,";
186     datafile << "Udot,";
187     datafile << "Vdot,";
188     datafile << "Wdot,";
189     datafile << "P,";
190     datafile << "Q,";
191     datafile << "R,";
192     datafile << "PDot,";
193     datafile << "QDot,";
194     datafile << "RDot,";
195     datafile << "Fx,";
196     datafile << "Fy,";
197     datafile << "Fz,";
198     datafile << "Latitude,";
199     datafile << "Longitude,";
200     datafile << "QBar,";
201     datafile << "Alpha,";
202     datafile << "L,";
203     datafile << "M,";
204     datafile << "N,";
205     datafile << "Throttle,";
206     datafile << "Aileron,";
207     datafile << "Elevator,";
208     datafile << "Rudder";
209     datafile << endl;
210     sFirstPass = false;
211   }
212
213   datafile << State->Getsim_time() << ",";
214   datafile << State->Geth() << ",";
215   datafile << Rotation->Getphi() << ",";
216   datafile << Rotation->Gettht() << ",";
217   datafile << Rotation->Getpsi() << ",";
218   datafile << Atmosphere->GetDensity() << ",";
219   datafile << State->GetVt() << ",";
220   datafile << Translation->GetU() << ",";
221   datafile << Translation->GetV() << ",";
222   datafile << Translation->GetW() << ",";
223   datafile << Position->GetVn() << ",";
224   datafile << Position->GetVe() << ",";
225   datafile << Position->GetVd() << ",";
226   datafile << Translation->GetUdot() << ",";
227   datafile << Translation->GetVdot() << ",";
228   datafile << Translation->GetWdot() << ",";
229   datafile << Rotation->GetP() << ",";
230   datafile << Rotation->GetQ() << ",";
231   datafile << Rotation->GetR() << ",";
232   datafile << Rotation->GetPdot() << ",";
233   datafile << Rotation->GetQdot() << ",";
234   datafile << Rotation->GetRdot() << ",";
235   datafile << Aircraft->GetFx() << ",";
236   datafile << Aircraft->GetFy() << ",";
237   datafile << Aircraft->GetFz() << ",";
238   datafile << State->Getlatitude() << ",";
239   datafile << State->Getlongitude() << ",";
240   datafile << State->Getqbar() << ",";
241   datafile << Translation->Getalpha() << ",";
242   datafile << Aircraft->GetL() << ",";
243   datafile << Aircraft->GetM() << ",";
244   datafile << Aircraft->GetN() << ",";
245   datafile << FCS->GetThrottle(0) << ",";
246   datafile << FCS->GetDa() << ",";
247   datafile << FCS->GetDe() << ",";
248   datafile << FCS->GetDr() << "";
249   datafile << endl;
250   datafile.flush();
251 }
252
253 void FGOutput::SocketOutput(void)
254 {
255   string asciiData;
256
257   if (socket <= 0) return;
258
259   socket->Clear();
260   if (sFirstPass) {
261     socket->Append("<LABELS>");
262     socket->Append("Time");
263     socket->Append("Altitude");
264     socket->Append("Phi");
265     socket->Append("Tht");
266     socket->Append("Psi");
267     socket->Append("Rho");
268     socket->Append("Vtotal");
269     socket->Append("U");
270     socket->Append("V");
271     socket->Append("W");
272     socket->Append("Vn");
273     socket->Append("Ve");
274     socket->Append("Vd");
275     socket->Append("Udot");
276     socket->Append("Vdot");
277     socket->Append("Wdot");
278     socket->Append("P");
279     socket->Append("Q");
280     socket->Append("R");
281     socket->Append("PDot");
282     socket->Append("QDot");
283     socket->Append("RDot");
284     socket->Append("Fx");
285     socket->Append("Fy");
286     socket->Append("Fz");
287     socket->Append("Latitude");
288     socket->Append("Longitude");
289     socket->Append("QBar");
290     socket->Append("Alpha");
291     socket->Append("L");
292     socket->Append("M");
293     socket->Append("N");
294     sFirstPass = false;
295     socket->Send();
296   }
297
298   socket->Clear();
299   socket->Append(State->Getsim_time());
300   socket->Append(State->Geth());
301   socket->Append(Rotation->Getphi());
302   socket->Append(Rotation->Gettht());
303   socket->Append(Rotation->Getpsi());
304   socket->Append(Atmosphere->GetDensity());
305   socket->Append(State->GetVt());
306   socket->Append(Translation->GetU());
307   socket->Append(Translation->GetV());
308   socket->Append(Translation->GetW());
309   socket->Append(Position->GetVn());
310   socket->Append(Position->GetVe());
311   socket->Append(Position->GetVd());
312   socket->Append(Translation->GetUdot());
313   socket->Append(Translation->GetVdot());
314   socket->Append(Translation->GetWdot());
315   socket->Append(Rotation->GetP());
316   socket->Append(Rotation->GetQ());
317   socket->Append(Rotation->GetR());
318   socket->Append(Rotation->GetPdot());
319   socket->Append(Rotation->GetQdot());
320   socket->Append(Rotation->GetRdot());
321   socket->Append(Aircraft->GetFx());
322   socket->Append(Aircraft->GetFy());
323   socket->Append(Aircraft->GetFz());
324   socket->Append(State->Getlatitude());
325   socket->Append(State->Getlongitude());
326   socket->Append(State->Getqbar());
327   socket->Append(Translation->Getalpha());
328   socket->Append(Aircraft->GetL());
329   socket->Append(Aircraft->GetM());
330   socket->Append(Aircraft->GetN());
331   socket->Send();
332 }
333
334
335 void FGOutput::SocketStatusOutput(string out_str)
336 {
337   string asciiData;
338
339   if (socket <= 0) return;
340
341   socket->Clear();
342   asciiData = string("<STATUS>") + out_str;
343   socket->Append(asciiData.c_str());
344   socket->Send();
345 }
346