1 /*******************************************************************************
6 Purpose: Manage output of sim parameters to file or stdout
9 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
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
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
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.
25 Further information about the GNU General Public License can also be found on
26 the world wide web at http://www.gnu.org.
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.
35 --------------------------------------------------------------------------------
38 ********************************************************************************
40 *******************************************************************************/
44 #include "FGFDMExec.h"
45 #include "FGAtmosphere.h"
47 #include "FGAircraft.h"
48 #include "FGTranslation.h"
49 #include "FGRotation.h"
50 #include "FGPosition.h"
51 #include "FGAuxiliary.h"
53 /*******************************************************************************
54 ************************************ CODE **************************************
55 *******************************************************************************/
57 FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
60 sFirstPass = dFirstPass = true;
62 #ifdef FG_WITH_JSBSIM_SOCKET
63 socket = new FGfdmSocket("localhost",1138);
68 FGOutput::~FGOutput(void)
70 if (socket) delete socket;
74 bool FGOutput::Run(void)
76 if (!FGModel::Run()) {
78 DelimitedOutput("JSBSimData.csv");
85 void FGOutput::DelimitedOutput(void)
114 cout << "Longitude,";
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() << "";
169 void FGOutput::DelimitedOutput(string fname)
172 datafile.open(fname.c_str());
174 datafile << "Altitude,";
179 datafile << "Vtotal,";
198 datafile << "Latitude,";
199 datafile << "Longitude,";
201 datafile << "Alpha,";
205 datafile << "Throttle,";
206 datafile << "Aileron,";
207 datafile << "Elevator,";
208 datafile << "Rudder";
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() << "";
253 void FGOutput::SocketOutput(void)
257 if (socket <= 0) return;
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");
272 socket->Append("Vn");
273 socket->Append("Ve");
274 socket->Append("Vd");
275 socket->Append("Udot");
276 socket->Append("Vdot");
277 socket->Append("Wdot");
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");
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());
335 void FGOutput::SocketStatusOutput(string out_str)
339 if (socket <= 0) return;
342 asciiData = string("<STATUS>") + out_str;
343 socket->Append(asciiData.c_str());