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)
82 if (!FGModel::Run()) {
84 if (Type == otSocket) {
86 } else if (Type == otCSV) {
87 if (Filename != "COUT" && Filename != "cout" && Filename.size() > 0) {
88 DelimitedOutput(Filename);
92 } else if (Type == otTerminal) {
94 } else if (Type == otNone) {
97 // Not a valid type of output
106 /******************************************************************************/
108 void FGOutput::SetType(string type)
112 } else if (type == "TABULAR") {
114 } else if (type == "SOCKET") {
116 } else if (type == "TERMINAL") {
118 } else if (type != "NONE"){
120 cerr << "Unknown type of output specified in config file" << endl;
124 /******************************************************************************/
126 void FGOutput::DelimitedOutput(void)
130 if (SubSystems & FGAircraft::ssSimulation) {
133 if (SubSystems & FGAircraft::ssAerosurfaces) {
135 cout << "Throttle, ";
136 cout << "Aileron Cmd, ";
137 cout << "Elevator Cmd, ";
138 cout << "Rudder Cmd, ";
139 cout << "Aileron Pos, ";
140 cout << "Elevator Pos, ";
141 cout << "Rudder Pos";
143 if (SubSystems & FGAircraft::ssRates) {
147 if (SubSystems & FGAircraft::ssVelocities) {
152 cout << "Vn, Ve, Vd";
154 if (SubSystems & FGAircraft::ssForces) {
156 cout << "XsForce, YsForce, ZsForce, ";
157 cout << "Xforce, Yforce, Zforce";
159 if (SubSystems & FGAircraft::ssMoments) {
163 if (SubSystems & FGAircraft::ssAtmosphere) {
167 if (SubSystems & FGAircraft::ssMassProps) {
174 cout << "Xcg, Ycg, Zcg";
176 if (SubSystems & FGAircraft::ssPosition) {
178 cout << "Altitude, ";
179 cout << "Phi, Tht, Psi, ";
181 cout << "Latitude, ";
182 cout << "Longitude, ";
183 cout << "Distance AGL, ";
184 cout << "Runway Radius";
186 if (SubSystems & FGAircraft::ssCoefficients) {
188 cout << Aircraft->GetCoefficientStrings();
190 if (SubSystems & FGAircraft::ssGroundReactions) {
192 cout << Aircraft->GetGroundReactionStrings();
199 cout << State->Getsim_time();
200 if (SubSystems & FGAircraft::ssSimulation) {
202 if (SubSystems & FGAircraft::ssAerosurfaces) {
204 cout << FCS->GetThrottlePos(0) << ", ";
205 cout << FCS->GetDaCmd() << ", ";
206 cout << FCS->GetDeCmd() << ", ";
207 cout << FCS->GetDrCmd() << ", ";
208 cout << FCS->GetDaPos() << ", ";
209 cout << FCS->GetDePos() << ", ";
210 cout << FCS->GetDrPos();
212 if (SubSystems & FGAircraft::ssRates) {
214 cout << Rotation->GetPQR();
216 if (SubSystems & FGAircraft::ssVelocities) {
218 cout << Translation->Getqbar() << ", ";
219 cout << Translation->GetVt() << ", ";
220 cout << Translation->GetUVW() << ", ";
221 cout << Position->GetVel();
223 if (SubSystems & FGAircraft::ssForces) {
225 cout << Aircraft->GetvFs() << ", ";
226 cout << Aircraft->GetForces();
228 if (SubSystems & FGAircraft::ssMoments) {
230 cout << Aircraft->GetMoments();
232 if (SubSystems & FGAircraft::ssAtmosphere) {
234 cout << Atmosphere->GetDensity();
236 if (SubSystems & FGAircraft::ssMassProps) {
238 cout << Aircraft->GetIxx() << ", ";
239 cout << Aircraft->GetIyy() << ", ";
240 cout << Aircraft->GetIzz() << ", ";
241 cout << Aircraft->GetIxz() << ", ";
242 cout << Aircraft->GetMass() << ", ";
243 cout << Aircraft->GetXYZcg();
245 if (SubSystems & FGAircraft::ssPosition) {
247 cout << Position->Geth() << ", ";
248 cout << Rotation->GetEuler() << ", ";
249 cout << Translation->Getalpha() << ", ";
250 cout << Position->GetLatitude() << ", ";
251 cout << Position->GetLongitude() << ", ";
252 cout << Position->GetDistanceAGL() << ", ";
253 cout << Position->GetRunwayRadius();
255 if (SubSystems & FGAircraft::ssCoefficients) {
257 cout << Aircraft->GetCoefficientValues();
259 if (SubSystems & FGAircraft::ssGroundReactions) {
261 cout << Aircraft->GetGroundReactionValues();
266 /******************************************************************************/
268 void FGOutput::DelimitedOutput(string fname)
271 datafile.open(fname.c_str());
273 if (SubSystems & FGAircraft::ssSimulation) {
276 if (SubSystems & FGAircraft::ssAerosurfaces) {
278 datafile << "Throttle, ";
279 datafile << "Aileron Cmd, ";
280 datafile << "Elevator Cmd, ";
281 datafile << "Rudder Cmd, ";
282 datafile << "Aileron Pos, ";
283 datafile << "Elevator Pos, ";
284 datafile << "Rudder Pos";
286 if (SubSystems & FGAircraft::ssRates) {
288 datafile << "P, Q, R";
290 if (SubSystems & FGAircraft::ssVelocities) {
292 datafile << "QBar, ";
293 datafile << "Vtotal, ";
294 datafile << "U, V, W, ";
295 datafile << "Vn, Ve, Vd";
297 if (SubSystems & FGAircraft::ssForces) {
299 datafile << "XsForce, YsForce, ZsForce, ";
300 datafile << "Xforce, Yforce, Zforce";
302 if (SubSystems & FGAircraft::ssMoments) {
304 datafile << "L, M, N";
306 if (SubSystems & FGAircraft::ssAtmosphere) {
310 if (SubSystems & FGAircraft::ssMassProps) {
316 datafile << "Mass, ";
317 datafile << "Xcg, Ycg, Zcg";
319 if (SubSystems & FGAircraft::ssPosition) {
321 datafile << "Altitude, ";
322 datafile << "Phi, Tht, Psi, ";
323 datafile << "Alpha, ";
324 datafile << "Latitude, ";
325 datafile << "Longitude, ";
326 datafile << "Distance AGL, ";
327 datafile << "Runway Radius";
329 if (SubSystems & FGAircraft::ssCoefficients) {
331 datafile << Aircraft->GetCoefficientStrings();
333 if (SubSystems & FGAircraft::ssGroundReactions) {
335 datafile << Aircraft->GetGroundReactionStrings();
341 datafile << State->Getsim_time();
342 if (SubSystems & FGAircraft::ssSimulation) {
344 if (SubSystems & FGAircraft::ssAerosurfaces) {
346 datafile << FCS->GetThrottlePos(0) << ", ";
347 datafile << FCS->GetDaCmd() << ", ";
348 datafile << FCS->GetDeCmd() << ", ";
349 datafile << FCS->GetDrCmd() << ", ";
350 datafile << FCS->GetDaPos() << ", ";
351 datafile << FCS->GetDePos() << ", ";
352 datafile << FCS->GetDrPos();
354 if (SubSystems & FGAircraft::ssRates) {
356 datafile << Rotation->GetPQR();
358 if (SubSystems & FGAircraft::ssVelocities) {
360 datafile << Translation->Getqbar() << ", ";
361 datafile << Translation->GetVt() << ", ";
362 datafile << Translation->GetUVW() << ", ";
363 datafile << Position->GetVel();
365 if (SubSystems & FGAircraft::ssForces) {
367 datafile << Aircraft->GetvFs() << ", ";
368 datafile << Aircraft->GetForces();
370 if (SubSystems & FGAircraft::ssMoments) {
372 datafile << Aircraft->GetMoments();
374 if (SubSystems & FGAircraft::ssAtmosphere) {
376 datafile << Atmosphere->GetDensity();
378 if (SubSystems & FGAircraft::ssMassProps) {
380 datafile << Aircraft->GetIxx() << ", ";
381 datafile << Aircraft->GetIyy() << ", ";
382 datafile << Aircraft->GetIzz() << ", ";
383 datafile << Aircraft->GetIxz() << ", ";
384 datafile << Aircraft->GetMass() << ", ";
385 datafile << Aircraft->GetXYZcg();
387 if (SubSystems & FGAircraft::ssPosition) {
389 datafile << Position->Geth() << ", ";
390 datafile << Rotation->GetEuler() << ", ";
391 datafile << Translation->Getalpha() << ", ";
392 datafile << Position->GetLatitude() << ", ";
393 datafile << Position->GetLongitude() << ", ";
394 datafile << Position->GetDistanceAGL() << ", ";
395 datafile << Position->GetRunwayRadius();
397 if (SubSystems & FGAircraft::ssCoefficients) {
399 datafile << Aircraft->GetCoefficientValues();
401 if (SubSystems & FGAircraft::ssGroundReactions) {
403 datafile << Aircraft->GetGroundReactionValues();
409 /******************************************************************************/
411 void FGOutput::SocketOutput(void)
415 if (socket == NULL) return;
419 socket->Append("<LABELS>");
420 socket->Append("Time");
421 socket->Append("Altitude");
422 socket->Append("Phi");
423 socket->Append("Tht");
424 socket->Append("Psi");
425 socket->Append("Rho");
426 socket->Append("Vtotal");
430 socket->Append("Vn");
431 socket->Append("Ve");
432 socket->Append("Vd");
433 socket->Append("Udot");
434 socket->Append("Vdot");
435 socket->Append("Wdot");
439 socket->Append("PDot");
440 socket->Append("QDot");
441 socket->Append("RDot");
442 socket->Append("Fx");
443 socket->Append("Fy");
444 socket->Append("Fz");
445 socket->Append("Latitude");
446 socket->Append("Longitude");
447 socket->Append("QBar");
448 socket->Append("Alpha");
452 socket->Append("Throttle");
453 socket->Append("Aileron");
454 socket->Append("Elevator");
455 socket->Append("Rudder");
461 socket->Append(State->Getsim_time());
462 socket->Append(Position->Geth());
463 socket->Append(Rotation->Getphi());
464 socket->Append(Rotation->Gettht());
465 socket->Append(Rotation->Getpsi());
466 socket->Append(Atmosphere->GetDensity());
467 socket->Append(Translation->GetVt());
468 socket->Append(Translation->GetU());
469 socket->Append(Translation->GetV());
470 socket->Append(Translation->GetW());
471 socket->Append(Position->GetVn());
472 socket->Append(Position->GetVe());
473 socket->Append(Position->GetVd());
474 socket->Append(Translation->GetUdot());
475 socket->Append(Translation->GetVdot());
476 socket->Append(Translation->GetWdot());
477 socket->Append(Rotation->GetP());
478 socket->Append(Rotation->GetQ());
479 socket->Append(Rotation->GetR());
480 socket->Append(Rotation->GetPdot());
481 socket->Append(Rotation->GetQdot());
482 socket->Append(Rotation->GetRdot());
483 socket->Append(Aircraft->GetFx());
484 socket->Append(Aircraft->GetFy());
485 socket->Append(Aircraft->GetFz());
486 socket->Append(Position->GetLatitude());
487 socket->Append(Position->GetLongitude());
488 socket->Append(Translation->Getqbar());
489 socket->Append(Translation->Getalpha());
490 socket->Append(Aircraft->GetL());
491 socket->Append(Aircraft->GetM());
492 socket->Append(Aircraft->GetN());
493 socket->Append(FCS->GetThrottle(0));
494 socket->Append(FCS->GetDa());
495 socket->Append(FCS->GetDe());
496 socket->Append(FCS->GetDr());
500 /******************************************************************************/
502 void FGOutput::SocketStatusOutput(string out_str)
506 if (socket == NULL) return;
509 asciiData = string("<STATUS>") + out_str;
510 socket->Append(asciiData.c_str());
514 /******************************************************************************/