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, ";
181 cout << "Longitude, ";
182 cout << "Distance AGL, ";
183 cout << "Runway Radius";
185 if (SubSystems & FGAircraft::ssCoefficients) {
187 cout << Aircraft->GetCoefficientStrings();
189 if (SubSystems & FGAircraft::ssGroundReactions) {
191 cout << Aircraft->GetGroundReactionStrings();
198 cout << State->Getsim_time();
199 if (SubSystems & FGAircraft::ssSimulation) {
201 if (SubSystems & FGAircraft::ssAerosurfaces) {
203 cout << FCS->GetThrottlePos(0) << ", ";
204 cout << FCS->GetDaCmd() << ", ";
205 cout << FCS->GetDeCmd() << ", ";
206 cout << FCS->GetDrCmd() << ", ";
207 cout << FCS->GetDaPos() << ", ";
208 cout << FCS->GetDePos() << ", ";
209 cout << FCS->GetDrPos();
211 if (SubSystems & FGAircraft::ssRates) {
213 cout << Rotation->GetPQR();
215 if (SubSystems & FGAircraft::ssVelocities) {
217 cout << Translation->Getqbar() << ", ";
218 cout << Translation->GetVt() << ", ";
219 cout << Translation->GetUVW() << ", ";
220 cout << Position->GetVel();
222 if (SubSystems & FGAircraft::ssForces) {
224 cout << Aircraft->GetvFs() << ", ";
225 cout << Aircraft->GetForces();
227 if (SubSystems & FGAircraft::ssMoments) {
229 cout << Aircraft->GetMoments();
231 if (SubSystems & FGAircraft::ssAtmosphere) {
233 cout << Atmosphere->GetDensity();
235 if (SubSystems & FGAircraft::ssMassProps) {
237 cout << Aircraft->GetIxx() << ", ";
238 cout << Aircraft->GetIyy() << ", ";
239 cout << Aircraft->GetIzz() << ", ";
240 cout << Aircraft->GetIxz() << ", ";
241 cout << Aircraft->GetMass() << ", ";
242 cout << Aircraft->GetXYZcg();
244 if (SubSystems & FGAircraft::ssPosition) {
246 cout << Position->Geth() << ", ";
247 cout << Rotation->GetEuler() << ", ";
248 cout << Translation->Getalpha() << ", ";
249 cout << Position->GetLatitude() << ", ";
250 cout << Position->GetLongitude() << ", ";
251 cout << Position->GetDistanceAGL() << ", ";
252 cout << Position->GetRunwayRadius();
254 if (SubSystems & FGAircraft::ssCoefficients) {
256 cout << Aircraft->GetCoefficientValues();
258 if (SubSystems & FGAircraft::ssGroundReactions) {
260 cout << Aircraft->GetGroundReactionValues();
265 /******************************************************************************/
267 void FGOutput::DelimitedOutput(string fname)
270 datafile.open(fname.c_str());
272 if (SubSystems & FGAircraft::ssSimulation) {
275 if (SubSystems & FGAircraft::ssAerosurfaces) {
277 datafile << "Throttle, ";
278 datafile << "Aileron Cmd, ";
279 datafile << "Elevator Cmd, ";
280 datafile << "Rudder Cmd, ";
281 datafile << "Aileron Pos, ";
282 datafile << "Elevator Pos, ";
283 datafile << "Rudder Pos";
285 if (SubSystems & FGAircraft::ssRates) {
287 datafile << "P, Q, R";
289 if (SubSystems & FGAircraft::ssVelocities) {
291 datafile << "QBar, ";
292 datafile << "Vtotal, ";
293 datafile << "U, V, W, ";
294 datafile << "Vn, Ve, Vd";
296 if (SubSystems & FGAircraft::ssForces) {
298 datafile << "XsForce, YsForce, ZsForce, ";
299 datafile << "Xforce, Yforce, Zforce";
301 if (SubSystems & FGAircraft::ssMoments) {
303 datafile << "L, M, N";
305 if (SubSystems & FGAircraft::ssAtmosphere) {
309 if (SubSystems & FGAircraft::ssMassProps) {
315 datafile << "Mass, ";
316 datafile << "Xcg, Ycg, Zcg";
318 if (SubSystems & FGAircraft::ssPosition) {
320 datafile << "Altitude, ";
321 datafile << "Phi, Tht, Psi, ";
322 datafile << "Alpha, ";
323 datafile << "Latitude, ";
324 datafile << "Longitude, ";
325 datafile << "Distance AGL, ";
326 datafile << "Runway Radius";
328 if (SubSystems & FGAircraft::ssCoefficients) {
330 datafile << Aircraft->GetCoefficientStrings();
332 if (SubSystems & FGAircraft::ssGroundReactions) {
334 datafile << Aircraft->GetGroundReactionStrings();
340 datafile << State->Getsim_time();
341 if (SubSystems & FGAircraft::ssSimulation) {
343 if (SubSystems & FGAircraft::ssAerosurfaces) {
345 datafile << FCS->GetThrottlePos(0) << ", ";
346 datafile << FCS->GetDaCmd() << ", ";
347 datafile << FCS->GetDeCmd() << ", ";
348 datafile << FCS->GetDrCmd() << ", ";
349 datafile << FCS->GetDaPos() << ", ";
350 datafile << FCS->GetDePos() << ", ";
351 datafile << FCS->GetDrPos();
353 if (SubSystems & FGAircraft::ssRates) {
355 datafile << Rotation->GetPQR();
357 if (SubSystems & FGAircraft::ssVelocities) {
359 datafile << Translation->Getqbar() << ", ";
360 datafile << Translation->GetVt() << ", ";
361 datafile << Translation->GetUVW() << ", ";
362 datafile << Position->GetVel();
364 if (SubSystems & FGAircraft::ssForces) {
366 datafile << Aircraft->GetvFs() << ", ";
367 datafile << Aircraft->GetForces();
369 if (SubSystems & FGAircraft::ssMoments) {
371 datafile << Aircraft->GetMoments();
373 if (SubSystems & FGAircraft::ssAtmosphere) {
375 datafile << Atmosphere->GetDensity();
377 if (SubSystems & FGAircraft::ssMassProps) {
379 datafile << Aircraft->GetIxx() << ", ";
380 datafile << Aircraft->GetIyy() << ", ";
381 datafile << Aircraft->GetIzz() << ", ";
382 datafile << Aircraft->GetIxz() << ", ";
383 datafile << Aircraft->GetMass() << ", ";
384 datafile << Aircraft->GetXYZcg();
386 if (SubSystems & FGAircraft::ssPosition) {
388 datafile << Position->Geth() << ", ";
389 datafile << Rotation->GetEuler() << ", ";
390 datafile << Translation->Getalpha() << ", ";
391 datafile << Position->GetLatitude() << ", ";
392 datafile << Position->GetLongitude() << ", ";
393 datafile << Position->GetDistanceAGL() << ", ";
394 datafile << Position->GetRunwayRadius();
396 if (SubSystems & FGAircraft::ssCoefficients) {
398 datafile << Aircraft->GetCoefficientValues();
400 if (SubSystems & FGAircraft::ssGroundReactions) {
402 datafile << Aircraft->GetGroundReactionValues();
408 /******************************************************************************/
410 void FGOutput::SocketOutput(void)
414 if (socket <= 0) return;
418 socket->Append("<LABELS>");
419 socket->Append("Time");
420 socket->Append("Altitude");
421 socket->Append("Phi");
422 socket->Append("Tht");
423 socket->Append("Psi");
424 socket->Append("Rho");
425 socket->Append("Vtotal");
429 socket->Append("Vn");
430 socket->Append("Ve");
431 socket->Append("Vd");
432 socket->Append("Udot");
433 socket->Append("Vdot");
434 socket->Append("Wdot");
438 socket->Append("PDot");
439 socket->Append("QDot");
440 socket->Append("RDot");
441 socket->Append("Fx");
442 socket->Append("Fy");
443 socket->Append("Fz");
444 socket->Append("Latitude");
445 socket->Append("Longitude");
446 socket->Append("QBar");
447 socket->Append("Alpha");
451 socket->Append("Throttle");
452 socket->Append("Aileron");
453 socket->Append("Elevator");
454 socket->Append("Rudder");
460 socket->Append(State->Getsim_time());
461 socket->Append(Position->Geth());
462 socket->Append(Rotation->Getphi());
463 socket->Append(Rotation->Gettht());
464 socket->Append(Rotation->Getpsi());
465 socket->Append(Atmosphere->GetDensity());
466 socket->Append(Translation->GetVt());
467 socket->Append(Translation->GetU());
468 socket->Append(Translation->GetV());
469 socket->Append(Translation->GetW());
470 socket->Append(Position->GetVn());
471 socket->Append(Position->GetVe());
472 socket->Append(Position->GetVd());
473 socket->Append(Translation->GetUdot());
474 socket->Append(Translation->GetVdot());
475 socket->Append(Translation->GetWdot());
476 socket->Append(Rotation->GetP());
477 socket->Append(Rotation->GetQ());
478 socket->Append(Rotation->GetR());
479 socket->Append(Rotation->GetPdot());
480 socket->Append(Rotation->GetQdot());
481 socket->Append(Rotation->GetRdot());
482 socket->Append(Aircraft->GetFx());
483 socket->Append(Aircraft->GetFy());
484 socket->Append(Aircraft->GetFz());
485 socket->Append(Position->GetLatitude());
486 socket->Append(Position->GetLongitude());
487 socket->Append(Translation->Getqbar());
488 socket->Append(Translation->Getalpha());
489 socket->Append(Aircraft->GetL());
490 socket->Append(Aircraft->GetM());
491 socket->Append(Aircraft->GetN());
492 socket->Append(FCS->GetThrottle(0));
493 socket->Append(FCS->GetDa());
494 socket->Append(FCS->GetDe());
495 socket->Append(FCS->GetDr());
499 /******************************************************************************/
501 void FGOutput::SocketStatusOutput(string out_str)
505 if (socket <= 0) return;
508 asciiData = string("<STATUS>") + out_str;
509 socket->Append(asciiData.c_str());
513 /******************************************************************************/