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 static const char *IdSrc = "$Id$";
53 static const char *IdHdr = ID_OUTPUT;
55 extern short debug_lvl;
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61 FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
64 sFirstPass = dFirstPass = true;
67 Filename = "JSBSim.out";
71 #ifdef FG_WITH_JSBSIM_SOCKET
72 socket = new FGfdmSocket("localhost",1138);
74 if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
77 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 if (socket) delete socket;
82 if (debug_lvl & 2) cout << "Destroyed: FGOutput" << endl;
85 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 bool FGOutput::Run(void)
90 if (!FGModel::Run()) {
92 if (Type == otSocket) {
94 } else if (Type == otCSV) {
95 if (Filename != "COUT" && Filename != "cout" && Filename.size() > 0) {
96 DelimitedOutput(Filename);
100 } else if (Type == otTerminal) {
102 } else if (Type == otNone) {
105 // Not a valid type of output
114 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 void FGOutput::SetType(string type)
120 } else if (type == "TABULAR") {
122 } else if (type == "SOCKET") {
124 } else if (type == "TERMINAL") {
126 } else if (type != "NONE"){
128 cerr << "Unknown type of output specified in config file" << endl;
132 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 void FGOutput::DelimitedOutput(void)
138 if (SubSystems & FGAircraft::ssSimulation) {
141 if (SubSystems & FGAircraft::ssAerosurfaces) {
143 cout << "Throttle, ";
144 cout << "Aileron Cmd, ";
145 cout << "Elevator Cmd, ";
146 cout << "Rudder Cmd, ";
147 cout << "Aileron Pos, ";
148 cout << "Elevator Pos, ";
149 cout << "Rudder Pos";
151 if (SubSystems & FGAircraft::ssRates) {
155 if (SubSystems & FGAircraft::ssVelocities) {
160 cout << "Vn, Ve, Vd";
162 if (SubSystems & FGAircraft::ssForces) {
164 cout << "Drag, Side, Lift, ";
166 cout << "Xforce, Yforce, Zforce";
168 if (SubSystems & FGAircraft::ssMoments) {
172 if (SubSystems & FGAircraft::ssAtmosphere) {
176 if (SubSystems & FGAircraft::ssMassProps) {
183 cout << "Xcg, Ycg, Zcg";
185 if (SubSystems & FGAircraft::ssPosition) {
187 cout << "Altitude, ";
188 cout << "Phi, Tht, Psi, ";
190 cout << "Latitude, ";
191 cout << "Longitude, ";
192 cout << "Distance AGL, ";
193 cout << "Runway Radius";
195 if (SubSystems & FGAircraft::ssCoefficients) {
197 cout << Aircraft->GetCoefficientStrings();
199 if (SubSystems & FGAircraft::ssGroundReactions) {
201 cout << Aircraft->GetGroundReactionStrings();
203 if (SubSystems & FGAircraft::ssPropulsion) {
205 cout << Propulsion->GetPropulsionStrings();
212 cout << State->Getsim_time();
213 if (SubSystems & FGAircraft::ssSimulation) {
215 if (SubSystems & FGAircraft::ssAerosurfaces) {
217 cout << FCS->GetThrottlePos(0) << ", ";
218 cout << FCS->GetDaCmd() << ", ";
219 cout << FCS->GetDeCmd() << ", ";
220 cout << FCS->GetDrCmd() << ", ";
221 cout << FCS->GetDaPos() << ", ";
222 cout << FCS->GetDePos() << ", ";
223 cout << FCS->GetDrPos();
225 if (SubSystems & FGAircraft::ssRates) {
227 cout << Rotation->GetPQR();
229 if (SubSystems & FGAircraft::ssVelocities) {
231 cout << Translation->Getqbar() << ", ";
232 cout << Translation->GetVt() << ", ";
233 cout << Translation->GetUVW() << ", ";
234 cout << Position->GetVel();
236 if (SubSystems & FGAircraft::ssForces) {
238 cout << Aircraft->GetvFs() << ", ";
239 cout << Aircraft->GetLoD() << ", ";
240 cout << Aircraft->GetForces();
242 if (SubSystems & FGAircraft::ssMoments) {
244 cout << Aircraft->GetMoments();
246 if (SubSystems & FGAircraft::ssAtmosphere) {
248 cout << Atmosphere->GetDensity();
250 if (SubSystems & FGAircraft::ssMassProps) {
252 cout << Aircraft->GetIxx() << ", ";
253 cout << Aircraft->GetIyy() << ", ";
254 cout << Aircraft->GetIzz() << ", ";
255 cout << Aircraft->GetIxz() << ", ";
256 cout << Aircraft->GetMass() << ", ";
257 cout << Aircraft->GetXYZcg();
259 if (SubSystems & FGAircraft::ssPosition) {
261 cout << Position->Geth() << ", ";
262 cout << Rotation->GetEuler() << ", ";
263 cout << Translation->Getalpha() << ", ";
264 cout << Position->GetLatitude() << ", ";
265 cout << Position->GetLongitude() << ", ";
266 cout << Position->GetDistanceAGL() << ", ";
267 cout << Position->GetRunwayRadius();
269 if (SubSystems & FGAircraft::ssCoefficients) {
271 cout << Aircraft->GetCoefficientValues();
273 if (SubSystems & FGAircraft::ssGroundReactions) {
275 cout << Aircraft->GetGroundReactionValues();
277 if (SubSystems & FGAircraft::ssPropulsion) {
279 cout << Propulsion->GetPropulsionValues();
285 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287 void FGOutput::DelimitedOutput(string fname)
290 datafile.open(fname.c_str());
292 if (SubSystems & FGAircraft::ssSimulation) {
295 if (SubSystems & FGAircraft::ssAerosurfaces) {
297 datafile << "Throttle, ";
298 datafile << "Aileron Cmd, ";
299 datafile << "Elevator Cmd, ";
300 datafile << "Rudder Cmd, ";
301 datafile << "Aileron Pos, ";
302 datafile << "Elevator Pos, ";
303 datafile << "Rudder Pos";
305 if (SubSystems & FGAircraft::ssRates) {
307 datafile << "P, Q, R";
309 if (SubSystems & FGAircraft::ssVelocities) {
311 datafile << "QBar, ";
312 datafile << "Vtotal, ";
313 datafile << "U, V, W, ";
314 datafile << "Vn, Ve, Vd";
316 if (SubSystems & FGAircraft::ssForces) {
318 datafile << "Drag, Side, Lift, ";
320 datafile << "Xforce, Yforce, Zforce";
322 if (SubSystems & FGAircraft::ssMoments) {
324 datafile << "L, M, N";
326 if (SubSystems & FGAircraft::ssAtmosphere) {
330 if (SubSystems & FGAircraft::ssMassProps) {
336 datafile << "Mass, ";
337 datafile << "Xcg, Ycg, Zcg";
339 if (SubSystems & FGAircraft::ssPosition) {
341 datafile << "Altitude, ";
342 datafile << "Phi, Tht, Psi, ";
343 datafile << "Alpha, ";
344 datafile << "Latitude, ";
345 datafile << "Longitude, ";
346 datafile << "Distance AGL, ";
347 datafile << "Runway Radius";
349 if (SubSystems & FGAircraft::ssCoefficients) {
351 datafile << Aircraft->GetCoefficientStrings();
353 if (SubSystems & FGAircraft::ssGroundReactions) {
355 datafile << Aircraft->GetGroundReactionStrings();
357 if (SubSystems & FGAircraft::ssFCS) {
359 datafile << FCS->GetComponentStrings();
361 if (SubSystems & FGAircraft::ssPropulsion) {
363 datafile << Propulsion->GetPropulsionStrings();
369 datafile << State->Getsim_time();
370 if (SubSystems & FGAircraft::ssSimulation) {
372 if (SubSystems & FGAircraft::ssAerosurfaces) {
374 datafile << FCS->GetThrottlePos(0) << ", ";
375 datafile << FCS->GetDaCmd() << ", ";
376 datafile << FCS->GetDeCmd() << ", ";
377 datafile << FCS->GetDrCmd() << ", ";
378 datafile << FCS->GetDaPos() << ", ";
379 datafile << FCS->GetDePos() << ", ";
380 datafile << FCS->GetDrPos();
382 if (SubSystems & FGAircraft::ssRates) {
384 datafile << Rotation->GetPQR();
386 if (SubSystems & FGAircraft::ssVelocities) {
388 datafile << Translation->Getqbar() << ", ";
389 datafile << Translation->GetVt() << ", ";
390 datafile << Translation->GetUVW() << ", ";
391 datafile << Position->GetVel();
393 if (SubSystems & FGAircraft::ssForces) {
395 datafile << Aircraft->GetvFs() << ", ";
396 datafile << Aircraft->GetLoD() << ", ";
397 datafile << Aircraft->GetForces();
399 if (SubSystems & FGAircraft::ssMoments) {
401 datafile << Aircraft->GetMoments();
403 if (SubSystems & FGAircraft::ssAtmosphere) {
405 datafile << Atmosphere->GetDensity();
407 if (SubSystems & FGAircraft::ssMassProps) {
409 datafile << Aircraft->GetIxx() << ", ";
410 datafile << Aircraft->GetIyy() << ", ";
411 datafile << Aircraft->GetIzz() << ", ";
412 datafile << Aircraft->GetIxz() << ", ";
413 datafile << Aircraft->GetMass() << ", ";
414 datafile << Aircraft->GetXYZcg();
416 if (SubSystems & FGAircraft::ssPosition) {
418 datafile << Position->Geth() << ", ";
419 datafile << Rotation->GetEuler() << ", ";
420 datafile << Translation->Getalpha() << ", ";
421 datafile << Position->GetLatitude() << ", ";
422 datafile << Position->GetLongitude() << ", ";
423 datafile << Position->GetDistanceAGL() << ", ";
424 datafile << Position->GetRunwayRadius();
426 if (SubSystems & FGAircraft::ssCoefficients) {
428 datafile << Aircraft->GetCoefficientValues();
430 if (SubSystems & FGAircraft::ssGroundReactions) {
432 datafile << Aircraft->GetGroundReactionValues();
434 if (SubSystems & FGAircraft::ssFCS) {
436 datafile << FCS->GetComponentValues();
438 if (SubSystems & FGAircraft::ssPropulsion) {
440 datafile << Propulsion->GetPropulsionValues();
446 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
448 void FGOutput::SocketOutput(void)
452 if (socket == NULL) return;
456 socket->Append("<LABELS>");
457 socket->Append("Time");
458 socket->Append("Altitude");
459 socket->Append("Phi");
460 socket->Append("Tht");
461 socket->Append("Psi");
462 socket->Append("Rho");
463 socket->Append("Vtotal");
467 socket->Append("Vn");
468 socket->Append("Ve");
469 socket->Append("Vd");
470 socket->Append("Udot");
471 socket->Append("Vdot");
472 socket->Append("Wdot");
476 socket->Append("PDot");
477 socket->Append("QDot");
478 socket->Append("RDot");
479 socket->Append("Fx");
480 socket->Append("Fy");
481 socket->Append("Fz");
482 socket->Append("Latitude");
483 socket->Append("Longitude");
484 socket->Append("QBar");
485 socket->Append("Alpha");
489 socket->Append("Throttle");
490 socket->Append("Aileron");
491 socket->Append("Elevator");
492 socket->Append("Rudder");
498 socket->Append(State->Getsim_time());
499 socket->Append(Position->Geth());
500 socket->Append(Rotation->Getphi());
501 socket->Append(Rotation->Gettht());
502 socket->Append(Rotation->Getpsi());
503 socket->Append(Atmosphere->GetDensity());
504 socket->Append(Translation->GetVt());
505 socket->Append(Translation->GetU());
506 socket->Append(Translation->GetV());
507 socket->Append(Translation->GetW());
508 socket->Append(Position->GetVn());
509 socket->Append(Position->GetVe());
510 socket->Append(Position->GetVd());
511 socket->Append(Translation->GetUdot());
512 socket->Append(Translation->GetVdot());
513 socket->Append(Translation->GetWdot());
514 socket->Append(Rotation->GetP());
515 socket->Append(Rotation->GetQ());
516 socket->Append(Rotation->GetR());
517 socket->Append(Rotation->GetPdot());
518 socket->Append(Rotation->GetQdot());
519 socket->Append(Rotation->GetRdot());
520 socket->Append(Aircraft->GetFx());
521 socket->Append(Aircraft->GetFy());
522 socket->Append(Aircraft->GetFz());
523 socket->Append(Position->GetLatitude());
524 socket->Append(Position->GetLongitude());
525 socket->Append(Translation->Getqbar());
526 socket->Append(Translation->Getalpha());
527 socket->Append(Aircraft->GetL());
528 socket->Append(Aircraft->GetM());
529 socket->Append(Aircraft->GetN());
530 socket->Append(FCS->GetThrottle(0));
531 socket->Append(FCS->GetDa());
532 socket->Append(FCS->GetDe());
533 socket->Append(FCS->GetDr());
537 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
539 void FGOutput::SocketStatusOutput(string out_str)
543 if (socket == NULL) return;
546 asciiData = string("<STATUS>") + out_str;
547 socket->Append(asciiData.c_str());
551 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
553 void FGOutput::Debug(void)
555 //TODO: Add your source code here