]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGOutput.cpp
Updated JSBsim 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. 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   socket = 0;
62 #ifdef FG_WITH_JSBSIM_SOCKET
63   socket = new FGfdmSocket("localhost",1138);
64 #endif
65 }
66
67 /******************************************************************************/
68
69 FGOutput::~FGOutput(void)
70 {
71   if (socket) delete socket;
72 }
73
74 /******************************************************************************/
75
76 bool FGOutput::Run(void)
77 {
78   if (!FGModel::Run()) {
79 //    SocketOutput();
80 //    DelimitedOutput("JSBSimData.csv");
81 //    DelimitedOutput();
82   } else {
83   }
84   return false;
85 }
86
87 /******************************************************************************/
88
89 void FGOutput::DelimitedOutput(void)
90 {
91   if (dFirstPass) {
92     cout << "Time,";
93     cout << "QBar,";
94     cout << "Vtotal,";
95     cout << "Throttle,";
96     cout << "Aileron,";
97     cout << "Elevator,";
98     cout << "Rudder,";
99     cout << "Rho,";
100     cout << "Ixx,";
101     cout << "Iyy,";
102     cout << "Izz,";
103     cout << "Ixz,";
104     cout << "Mass,";
105     cout << "Xcg, Ycg, Zcg, ";
106     cout << "Xforce, Yforce, Zforce,";
107     cout << "L, M, N, ";
108     cout << "Altitude,";
109     cout << "Phi, Tht, Psi,";
110     cout << "P, Q, R, ";
111     cout << "U, V, W, ";
112     cout << "Alpha,";
113     cout << "Vn, Ve, Vd, ";
114     cout << "Latitude,";
115     cout << "Longitude";
116     cout << endl;
117     dFirstPass = false;
118   }
119
120   cout << State->Getsim_time() << ",";
121   cout << State->Getqbar() << ",";
122   cout << State->GetVt() << ",";
123   cout << FCS->GetThrottlePos(0) << ",";
124   cout << FCS->GetDaPos() << ",";
125   cout << FCS->GetDePos() << ",";
126   cout << FCS->GetDrPos() << ",";
127   cout << Atmosphere->GetDensity() << ",";
128   cout << Aircraft->GetIxx() << ",";
129   cout << Aircraft->GetIyy() << ",";
130   cout << Aircraft->GetIzz() << ",";
131   cout << Aircraft->GetIxz() << ",";
132   cout << Aircraft->GetMass() << ",";
133   cout << Aircraft->GetXYZcg() << ",";
134   cout << Aircraft->GetForces() << ",";
135   cout << Aircraft->GetMoments() << ",";
136   cout << State->Geth() << ",";
137   cout << Rotation->GetEuler() << ",";
138   cout << Rotation->GetPQR() << ",";
139   cout << Translation->GetUVW() << ",";
140   cout << Translation->Getalpha() << ",";
141   cout << Position->GetVel() << ",";
142   cout << State->Getlatitude() << ",";
143   cout << State->Getlongitude();
144   cout << endl;
145 }
146
147 /******************************************************************************/
148
149 void FGOutput::DelimitedOutput(string fname)
150 {
151   if (sFirstPass) {
152     datafile.open(fname.c_str());
153     datafile << "Time,";
154     datafile << "QBar,";
155     datafile << "Vtotal,";
156     datafile << "Throttle,";
157     datafile << "Aileron,";
158     datafile << "Elevator,";
159     datafile << "Rudder,";
160     datafile << "Rho,";
161     datafile << "Ixx,";
162     datafile << "Iyy,";
163     datafile << "Izz,";
164     datafile << "Ixz,";
165     datafile << "Mass,";
166     datafile << "Xcg, Ycg, Zcg, ";
167     datafile << "Xforce, Yforce, Zforce, ";
168     datafile << "L, M, N, ";
169     datafile << "Altitude,";
170     datafile << "Phi, Tht, Psi,";
171     datafile << "P, Q, R, ";
172     datafile << "U, V, W, ";
173     datafile << "Alpha,";
174     datafile << "Vn, Ve, Vd, ";
175     datafile << "Latitude,";
176     datafile << "Longitude";
177     datafile << endl;
178     sFirstPass = false;
179   }
180
181   datafile << State->Getsim_time() << ",";
182   datafile << State->Getqbar() << ",";
183   datafile << State->GetVt() << ",";
184   datafile << FCS->GetThrottlePos(0) << ",";
185   datafile << FCS->GetDaPos() << ",";
186   datafile << FCS->GetDePos() << ",";
187   datafile << FCS->GetDrPos() << ",";
188   datafile << Atmosphere->GetDensity() << ",";
189   datafile << Aircraft->GetIxx() << ",";
190   datafile << Aircraft->GetIyy() << ",";
191   datafile << Aircraft->GetIzz() << ",";
192   datafile << Aircraft->GetIxz() << ",";
193   datafile << Aircraft->GetMass() << ",";
194   datafile << Aircraft->GetXYZcg() << ",";
195   datafile << Aircraft->GetForces() << ",";
196   datafile << Aircraft->GetMoments() << ",";
197   datafile << State->Geth() << ",";
198   datafile << Rotation->GetEuler() << ",";
199   datafile << Rotation->GetPQR() << ",";
200   datafile << Translation->GetUVW() << ",";
201   datafile << Translation->Getalpha() << ",";
202   datafile << Position->GetVel() << ",";
203   datafile << State->Getlatitude() << ",";
204   datafile << State->Getlongitude();
205   datafile << endl;
206   datafile.flush();
207 }
208
209 /******************************************************************************/
210
211 void FGOutput::SocketOutput(void)
212 {
213   string asciiData;
214   /*
215   if (socket <= 0) return;
216
217   socket->Clear();
218   if (sFirstPass) {
219     socket->Append("<LABELS>");
220     socket->Append("Time");
221     socket->Append("Altitude");
222     socket->Append("Phi");
223     socket->Append("Tht");
224     socket->Append("Psi");
225     socket->Append("Rho");
226     socket->Append("Vtotal");
227     socket->Append("U");
228     socket->Append("V");
229     socket->Append("W");
230     socket->Append("Vn");
231     socket->Append("Ve");
232     socket->Append("Vd");
233     socket->Append("Udot");
234     socket->Append("Vdot");
235     socket->Append("Wdot");
236     socket->Append("P");
237     socket->Append("Q");
238     socket->Append("R");
239     socket->Append("PDot");
240     socket->Append("QDot");
241     socket->Append("RDot");
242     socket->Append("Fx");
243     socket->Append("Fy");
244     socket->Append("Fz");
245     socket->Append("Latitude");
246     socket->Append("Longitude");
247     socket->Append("QBar");
248     socket->Append("Alpha");
249     socket->Append("L");
250     socket->Append("M");
251     socket->Append("N");
252     socket->Append("Throttle");
253     socket->Append("Aileron");
254     socket->Append("Elevator");
255     socket->Append("Rudder");
256     sFirstPass = false;
257     socket->Send();
258   }
259
260   socket->Clear();
261   socket->Append(State->Getsim_time());
262   socket->Append(State->Geth());
263   socket->Append(Rotation->Getphi());
264   socket->Append(Rotation->Gettht());
265   socket->Append(Rotation->Getpsi());
266   socket->Append(Atmosphere->GetDensity());
267   socket->Append(State->GetVt());
268   socket->Append(Translation->GetU());
269   socket->Append(Translation->GetV());
270   socket->Append(Translation->GetW());
271   socket->Append(Position->GetVn());
272   socket->Append(Position->GetVe());
273   socket->Append(Position->GetVd());
274   socket->Append(Translation->GetUdot());
275   socket->Append(Translation->GetVdot());
276   socket->Append(Translation->GetWdot());
277   socket->Append(Rotation->GetP());
278   socket->Append(Rotation->GetQ());
279   socket->Append(Rotation->GetR());
280   socket->Append(Rotation->GetPdot());
281   socket->Append(Rotation->GetQdot());
282   socket->Append(Rotation->GetRdot());
283   socket->Append(Aircraft->GetFx());
284   socket->Append(Aircraft->GetFy());
285   socket->Append(Aircraft->GetFz());
286   socket->Append(State->Getlatitude());
287   socket->Append(State->Getlongitude());
288   socket->Append(State->Getqbar());
289   socket->Append(Translation->Getalpha());
290   socket->Append(Aircraft->GetL());
291   socket->Append(Aircraft->GetM());
292   socket->Append(Aircraft->GetN());
293   socket->Append(FCS->GetThrottle(0));
294   socket->Append(FCS->GetDa());
295   socket->Append(FCS->GetDe());
296   socket->Append(FCS->GetDr());
297   socket->Send(); */
298 }
299
300 /******************************************************************************/
301
302 void FGOutput::SocketStatusOutput(string out_str)
303 {
304   string asciiData;
305
306   if (socket <= 0) return;
307
308   socket->Clear();
309   asciiData = string("<STATUS>") + out_str;
310   socket->Append(asciiData.c_str());
311   socket->Send();
312 }
313
314 /******************************************************************************/
315