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";
66 #ifdef FG_WITH_JSBSIM_SOCKET
67 socket = new FGfdmSocket("localhost",1138);
71 /******************************************************************************/
73 FGOutput::~FGOutput(void)
75 if (socket) delete socket;
78 /******************************************************************************/
80 bool FGOutput::Run(void)
83 if (!FGModel::Run()) {
85 if (Type == otSocket) {
87 } else if (Type == otCSV) {
88 if (Filename != "COUT" && Filename != "cout" && Filename.size() > 0) {
89 DelimitedOutput(Filename);
93 } else if (Type == otTerminal) {
95 } else if (Type == otNone) {
98 // Not a valid type of output
107 /******************************************************************************/
109 void FGOutput::SetType(string type)
113 } else if (type == "TABULAR") {
115 } else if (type == "SOCKET") {
117 } else if (type == "TERMINAL") {
119 } else if (type != "NONE"){
121 cerr << "Unknown type of output specified in config file" << endl;
125 /******************************************************************************/
127 void FGOutput::DelimitedOutput(void)
131 if (SubSystems & FGAircraft::ssSimulation) {
134 if (SubSystems & FGAircraft::ssAerosurfaces) {
136 cout << "Throttle, ";
137 cout << "Aileron Cmd, ";
138 cout << "Elevator Cmd, ";
139 cout << "Rudder Cmd, ";
140 cout << "Aileron Pos, ";
141 cout << "Elevator Pos, ";
142 cout << "Rudder Pos";
144 if (SubSystems & FGAircraft::ssRates) {
148 if (SubSystems & FGAircraft::ssVelocities) {
153 cout << "Vn, Ve, Vd";
155 if (SubSystems & FGAircraft::ssForces) {
157 cout << "XsForce, YsForce, ZsForce, ";
158 cout << "Xforce, Yforce, Zforce";
160 if (SubSystems & FGAircraft::ssMoments) {
164 if (SubSystems & FGAircraft::ssAtmosphere) {
168 if (SubSystems & FGAircraft::ssMassProps) {
175 cout << "Xcg, Ycg, Zcg";
177 if (SubSystems & FGAircraft::ssPosition) {
179 cout << "Altitude, ";
180 cout << "Phi, Tht, Psi, ";
182 cout << "Latitude, ";
183 cout << "Longitude, ";
184 cout << "Distance AGL, ";
185 cout << "Runway Radius";
187 if (SubSystems & FGAircraft::ssCoefficients) {
189 cout << Aircraft->GetCoefficientStrings();
191 if (SubSystems & FGAircraft::ssGroundReactions) {
193 cout << Aircraft->GetGroundReactionStrings();
200 cout << State->Getsim_time();
201 if (SubSystems & FGAircraft::ssSimulation) {
203 if (SubSystems & FGAircraft::ssAerosurfaces) {
205 cout << FCS->GetThrottlePos(0) << ", ";
206 cout << FCS->GetDaCmd() << ", ";
207 cout << FCS->GetDeCmd() << ", ";
208 cout << FCS->GetDrCmd() << ", ";
209 cout << FCS->GetDaPos() << ", ";
210 cout << FCS->GetDePos() << ", ";
211 cout << FCS->GetDrPos();
213 if (SubSystems & FGAircraft::ssRates) {
215 cout << Rotation->GetPQR();
217 if (SubSystems & FGAircraft::ssVelocities) {
219 cout << Translation->Getqbar() << ", ";
220 cout << Translation->GetVt() << ", ";
221 cout << Translation->GetUVW() << ", ";
222 cout << Position->GetVel();
224 if (SubSystems & FGAircraft::ssForces) {
226 cout << Aircraft->GetvFs() << ", ";
227 cout << Aircraft->GetForces();
229 if (SubSystems & FGAircraft::ssMoments) {
231 cout << Aircraft->GetMoments();
233 if (SubSystems & FGAircraft::ssAtmosphere) {
235 cout << Atmosphere->GetDensity();
237 if (SubSystems & FGAircraft::ssMassProps) {
239 cout << Aircraft->GetIxx() << ", ";
240 cout << Aircraft->GetIyy() << ", ";
241 cout << Aircraft->GetIzz() << ", ";
242 cout << Aircraft->GetIxz() << ", ";
243 cout << Aircraft->GetMass() << ", ";
244 cout << Aircraft->GetXYZcg();
246 if (SubSystems & FGAircraft::ssPosition) {
248 cout << Position->Geth() << ", ";
249 cout << Rotation->GetEuler() << ", ";
250 cout << Translation->Getalpha() << ", ";
251 cout << Position->GetLatitude() << ", ";
252 cout << Position->GetLongitude() << ", ";
253 cout << Position->GetDistanceAGL() << ", ";
254 cout << Position->GetRunwayRadius();
256 if (SubSystems & FGAircraft::ssCoefficients) {
258 cout << Aircraft->GetCoefficientValues();
260 if (SubSystems & FGAircraft::ssGroundReactions) {
262 cout << Aircraft->GetGroundReactionValues();
267 /******************************************************************************/
269 void FGOutput::DelimitedOutput(string fname)
272 datafile.open(fname.c_str());
274 if (SubSystems & FGAircraft::ssSimulation) {
277 if (SubSystems & FGAircraft::ssAerosurfaces) {
279 datafile << "Throttle, ";
280 datafile << "Aileron Cmd, ";
281 datafile << "Elevator Cmd, ";
282 datafile << "Rudder Cmd, ";
283 datafile << "Aileron Pos, ";
284 datafile << "Elevator Pos, ";
285 datafile << "Rudder Pos";
287 if (SubSystems & FGAircraft::ssRates) {
289 datafile << "P, Q, R";
291 if (SubSystems & FGAircraft::ssVelocities) {
293 datafile << "QBar, ";
294 datafile << "Vtotal, ";
295 datafile << "U, V, W, ";
296 datafile << "Vn, Ve, Vd";
298 if (SubSystems & FGAircraft::ssForces) {
300 datafile << "XsForce, YsForce, ZsForce, ";
301 datafile << "Xforce, Yforce, Zforce";
303 if (SubSystems & FGAircraft::ssMoments) {
305 datafile << "L, M, N";
307 if (SubSystems & FGAircraft::ssAtmosphere) {
311 if (SubSystems & FGAircraft::ssMassProps) {
317 datafile << "Mass, ";
318 datafile << "Xcg, Ycg, Zcg";
320 if (SubSystems & FGAircraft::ssPosition) {
322 datafile << "Altitude, ";
323 datafile << "Phi, Tht, Psi, ";
324 datafile << "Alpha, ";
325 datafile << "Latitude, ";
326 datafile << "Longitude, ";
327 datafile << "Distance AGL, ";
328 datafile << "Runway Radius";
330 if (SubSystems & FGAircraft::ssCoefficients) {
332 datafile << Aircraft->GetCoefficientStrings();
334 if (SubSystems & FGAircraft::ssGroundReactions) {
336 datafile << Aircraft->GetGroundReactionStrings();
342 datafile << State->Getsim_time();
343 if (SubSystems & FGAircraft::ssSimulation) {
345 if (SubSystems & FGAircraft::ssAerosurfaces) {
347 datafile << FCS->GetThrottlePos(0) << ", ";
348 datafile << FCS->GetDaCmd() << ", ";
349 datafile << FCS->GetDeCmd() << ", ";
350 datafile << FCS->GetDrCmd() << ", ";
351 datafile << FCS->GetDaPos() << ", ";
352 datafile << FCS->GetDePos() << ", ";
353 datafile << FCS->GetDrPos();
355 if (SubSystems & FGAircraft::ssRates) {
357 datafile << Rotation->GetPQR();
359 if (SubSystems & FGAircraft::ssVelocities) {
361 datafile << Translation->Getqbar() << ", ";
362 datafile << Translation->GetVt() << ", ";
363 datafile << Translation->GetUVW() << ", ";
364 datafile << Position->GetVel();
366 if (SubSystems & FGAircraft::ssForces) {
368 datafile << Aircraft->GetvFs() << ", ";
369 datafile << Aircraft->GetForces();
371 if (SubSystems & FGAircraft::ssMoments) {
373 datafile << Aircraft->GetMoments();
375 if (SubSystems & FGAircraft::ssAtmosphere) {
377 datafile << Atmosphere->GetDensity();
379 if (SubSystems & FGAircraft::ssMassProps) {
381 datafile << Aircraft->GetIxx() << ", ";
382 datafile << Aircraft->GetIyy() << ", ";
383 datafile << Aircraft->GetIzz() << ", ";
384 datafile << Aircraft->GetIxz() << ", ";
385 datafile << Aircraft->GetMass() << ", ";
386 datafile << Aircraft->GetXYZcg();
388 if (SubSystems & FGAircraft::ssPosition) {
390 datafile << Position->Geth() << ", ";
391 datafile << Rotation->GetEuler() << ", ";
392 datafile << Translation->Getalpha() << ", ";
393 datafile << Position->GetLatitude() << ", ";
394 datafile << Position->GetLongitude() << ", ";
395 datafile << Position->GetDistanceAGL() << ", ";
396 datafile << Position->GetRunwayRadius();
398 if (SubSystems & FGAircraft::ssCoefficients) {
400 datafile << Aircraft->GetCoefficientValues();
402 if (SubSystems & FGAircraft::ssGroundReactions) {
404 datafile << Aircraft->GetGroundReactionValues();
410 /******************************************************************************/
412 void FGOutput::SocketOutput(void)
416 if (socket == NULL) return;
420 socket->Append("<LABELS>");
421 socket->Append("Time");
422 socket->Append("Altitude");
423 socket->Append("Phi");
424 socket->Append("Tht");
425 socket->Append("Psi");
426 socket->Append("Rho");
427 socket->Append("Vtotal");
431 socket->Append("Vn");
432 socket->Append("Ve");
433 socket->Append("Vd");
434 socket->Append("Udot");
435 socket->Append("Vdot");
436 socket->Append("Wdot");
440 socket->Append("PDot");
441 socket->Append("QDot");
442 socket->Append("RDot");
443 socket->Append("Fx");
444 socket->Append("Fy");
445 socket->Append("Fz");
446 socket->Append("Latitude");
447 socket->Append("Longitude");
448 socket->Append("QBar");
449 socket->Append("Alpha");
453 socket->Append("Throttle");
454 socket->Append("Aileron");
455 socket->Append("Elevator");
456 socket->Append("Rudder");
462 socket->Append(State->Getsim_time());
463 socket->Append(Position->Geth());
464 socket->Append(Rotation->Getphi());
465 socket->Append(Rotation->Gettht());
466 socket->Append(Rotation->Getpsi());
467 socket->Append(Atmosphere->GetDensity());
468 socket->Append(Translation->GetVt());
469 socket->Append(Translation->GetU());
470 socket->Append(Translation->GetV());
471 socket->Append(Translation->GetW());
472 socket->Append(Position->GetVn());
473 socket->Append(Position->GetVe());
474 socket->Append(Position->GetVd());
475 socket->Append(Translation->GetUdot());
476 socket->Append(Translation->GetVdot());
477 socket->Append(Translation->GetWdot());
478 socket->Append(Rotation->GetP());
479 socket->Append(Rotation->GetQ());
480 socket->Append(Rotation->GetR());
481 socket->Append(Rotation->GetPdot());
482 socket->Append(Rotation->GetQdot());
483 socket->Append(Rotation->GetRdot());
484 socket->Append(Aircraft->GetFx());
485 socket->Append(Aircraft->GetFy());
486 socket->Append(Aircraft->GetFz());
487 socket->Append(Position->GetLatitude());
488 socket->Append(Position->GetLongitude());
489 socket->Append(Translation->Getqbar());
490 socket->Append(Translation->Getalpha());
491 socket->Append(Aircraft->GetL());
492 socket->Append(Aircraft->GetM());
493 socket->Append(Aircraft->GetN());
494 socket->Append(FCS->GetThrottle(0));
495 socket->Append(FCS->GetDa());
496 socket->Append(FCS->GetDe());
497 socket->Append(FCS->GetDr());
501 /******************************************************************************/
503 void FGOutput::SocketStatusOutput(string out_str)
507 if (socket == NULL) return;
510 asciiData = string("<STATUS>") + out_str;
511 socket->Append(asciiData.c_str());
515 /******************************************************************************/