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
34 --------------------------------------------------------------------------------
37 ********************************************************************************
39 *******************************************************************************/
43 #include "FGFDMExec.h"
44 #include "FGAtmosphere.h"
46 #include "FGAircraft.h"
47 #include "FGTranslation.h"
48 #include "FGRotation.h"
49 #include "FGPosition.h"
50 #include "FGAuxiliary.h"
52 /*******************************************************************************
53 ************************************ CODE **************************************
54 *******************************************************************************/
56 FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
59 sFirstPass = dFirstPass = true;
62 Filename = "JSBSim.out";
65 #ifdef FG_WITH_JSBSIM_SOCKET
66 socket = new FGfdmSocket("localhost",1138);
70 /******************************************************************************/
72 FGOutput::~FGOutput(void)
74 if (socket) delete socket;
77 /******************************************************************************/
79 bool FGOutput::Run(void)
81 if (!FGModel::Run()) {
83 if (Type == otSocket) {
85 } else if (Type == otCSV) {
86 if (Filename != "COUT" && Filename != "cout" && Filename.size() > 0) {
87 DelimitedOutput(Filename);
91 } else if (Type == otTerminal) {
93 } else if (Type == otNone) {
96 // Not a valid type of output
105 /******************************************************************************/
107 void FGOutput::SetType(string type)
111 } else if (type == "TABULAR") {
113 } else if (type == "SOCKET") {
115 } else if (type == "TERMINAL") {
117 } else if (type != "NONE"){
119 cerr << "Unknown type of output specified in config file" << endl;
123 /******************************************************************************/
125 void FGOutput::DelimitedOutput(void)
129 if (SubSystems & FGAircraft::ssSimulation) {
132 if (SubSystems & FGAircraft::ssAerosurfaces) {
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";
142 if (SubSystems & FGAircraft::ssRates) {
146 if (SubSystems & FGAircraft::ssVelocities) {
151 cout << "Vn, Ve, Vd";
153 if (SubSystems & FGAircraft::ssForces) {
155 cout << "XsForce, YsForce, ZsForce, ";
156 cout << "Xforce, Yforce, Zforce";
158 if (SubSystems & FGAircraft::ssMoments) {
162 if (SubSystems & FGAircraft::ssAtmosphere) {
166 if (SubSystems & FGAircraft::ssMassProps) {
173 cout << "Xcg, Ycg, Zcg";
175 if (SubSystems & FGAircraft::ssPosition) {
177 cout << "Altitude, ";
178 cout << "Phi, Tht, Psi, ";
180 cout << "Latitude, ";
183 if (SubSystems & FGAircraft::ssCoefficients) {
185 cout << Aircraft->GetCoefficientStrings();
192 cout << State->Getsim_time();
193 if (SubSystems & FGAircraft::ssSimulation) {
195 if (SubSystems & FGAircraft::ssAerosurfaces) {
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();
205 if (SubSystems & FGAircraft::ssRates) {
207 cout << Rotation->GetPQR();
209 if (SubSystems & FGAircraft::ssVelocities) {
211 cout << Translation->Getqbar() << ", ";
212 cout << Translation->GetVt() << ", ";
213 cout << Translation->GetUVW() << ", ";
214 cout << Position->GetVel();
216 if (SubSystems & FGAircraft::ssForces) {
218 cout << Aircraft->GetvFs() << ", ";
219 cout << Aircraft->GetForces();
221 if (SubSystems & FGAircraft::ssMoments) {
223 cout << Aircraft->GetMoments();
225 if (SubSystems & FGAircraft::ssAtmosphere) {
227 cout << Atmosphere->GetDensity();
229 if (SubSystems & FGAircraft::ssMassProps) {
231 cout << Aircraft->GetIxx() << ", ";
232 cout << Aircraft->GetIyy() << ", ";
233 cout << Aircraft->GetIzz() << ", ";
234 cout << Aircraft->GetIxz() << ", ";
235 cout << Aircraft->GetMass() << ", ";
236 cout << Aircraft->GetXYZcg();
238 if (SubSystems & FGAircraft::ssPosition) {
240 cout << Position->Geth() << ", ";
241 cout << Rotation->GetEuler() << ", ";
242 cout << Translation->Getalpha() << ", ";
243 cout << Position->GetLatitude() << ", ";
244 cout << Position->GetLongitude();
246 if (SubSystems & FGAircraft::ssCoefficients) {
248 cout << Aircraft->GetCoefficientValues();
253 /******************************************************************************/
255 void FGOutput::DelimitedOutput(string fname)
258 datafile.open(fname.c_str());
260 if (SubSystems & FGAircraft::ssSimulation) {
263 if (SubSystems & FGAircraft::ssAerosurfaces) {
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";
273 if (SubSystems & FGAircraft::ssRates) {
275 datafile << "P, Q, R";
277 if (SubSystems & FGAircraft::ssVelocities) {
279 datafile << "QBar, ";
280 datafile << "Vtotal, ";
281 datafile << "U, V, W, ";
282 datafile << "Vn, Ve, Vd";
284 if (SubSystems & FGAircraft::ssForces) {
286 datafile << "XsForce, YsForce, ZsForce, ";
287 datafile << "Xforce, Yforce, Zforce";
289 if (SubSystems & FGAircraft::ssMoments) {
291 datafile << "L, M, N";
293 if (SubSystems & FGAircraft::ssAtmosphere) {
297 if (SubSystems & FGAircraft::ssMassProps) {
303 datafile << "Mass, ";
304 datafile << "Xcg, Ycg, Zcg";
306 if (SubSystems & FGAircraft::ssPosition) {
308 datafile << "Altitude, ";
309 datafile << "Phi, Tht, Psi, ";
310 datafile << "Alpha, ";
311 datafile << "Latitude, ";
312 datafile << "Longitude";
314 if (SubSystems & FGAircraft::ssCoefficients) {
316 datafile << Aircraft->GetCoefficientStrings();
322 datafile << State->Getsim_time();
323 if (SubSystems & FGAircraft::ssSimulation) {
325 if (SubSystems & FGAircraft::ssAerosurfaces) {
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();
335 if (SubSystems & FGAircraft::ssRates) {
337 datafile << Rotation->GetPQR();
339 if (SubSystems & FGAircraft::ssVelocities) {
341 datafile << Translation->Getqbar() << ", ";
342 datafile << Translation->GetVt() << ", ";
343 datafile << Translation->GetUVW() << ", ";
344 datafile << Position->GetVel();
346 if (SubSystems & FGAircraft::ssForces) {
348 datafile << Aircraft->GetvFs() << ", ";
349 datafile << Aircraft->GetForces();
351 if (SubSystems & FGAircraft::ssMoments) {
353 datafile << Aircraft->GetMoments();
355 if (SubSystems & FGAircraft::ssAtmosphere) {
357 datafile << Atmosphere->GetDensity();
359 if (SubSystems & FGAircraft::ssMassProps) {
361 datafile << Aircraft->GetIxx() << ", ";
362 datafile << Aircraft->GetIyy() << ", ";
363 datafile << Aircraft->GetIzz() << ", ";
364 datafile << Aircraft->GetIxz() << ", ";
365 datafile << Aircraft->GetMass() << ", ";
366 datafile << Aircraft->GetXYZcg();
368 if (SubSystems & FGAircraft::ssPosition) {
370 datafile << Position->Geth() << ", ";
371 datafile << Rotation->GetEuler() << ", ";
372 datafile << Translation->Getalpha() << ", ";
373 datafile << Position->GetLatitude() << ", ";
374 datafile << Position->GetLongitude();
376 if (SubSystems & FGAircraft::ssCoefficients) {
378 datafile << Aircraft->GetCoefficientValues();
384 /******************************************************************************/
386 void FGOutput::SocketOutput(void)
390 if (socket <= 0) return;
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");
405 socket->Append("Vn");
406 socket->Append("Ve");
407 socket->Append("Vd");
408 socket->Append("Udot");
409 socket->Append("Vdot");
410 socket->Append("Wdot");
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");
427 socket->Append("Throttle");
428 socket->Append("Aileron");
429 socket->Append("Elevator");
430 socket->Append("Rudder");
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());
475 /******************************************************************************/
477 void FGOutput::SocketStatusOutput(string out_str)
481 if (socket <= 0) return;
484 asciiData = string("<STATUS>") + out_str;
485 socket->Append(asciiData.c_str());
489 /******************************************************************************/