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 << "XsForce, YsForce, ZsForce, ";
165 cout << "Xforce, Yforce, Zforce";
167 if (SubSystems & FGAircraft::ssMoments) {
171 if (SubSystems & FGAircraft::ssAtmosphere) {
175 if (SubSystems & FGAircraft::ssMassProps) {
182 cout << "Xcg, Ycg, Zcg";
184 if (SubSystems & FGAircraft::ssPosition) {
186 cout << "Altitude, ";
187 cout << "Phi, Tht, Psi, ";
189 cout << "Latitude, ";
190 cout << "Longitude, ";
191 cout << "Distance AGL, ";
192 cout << "Runway Radius";
194 if (SubSystems & FGAircraft::ssCoefficients) {
196 cout << Aircraft->GetCoefficientStrings();
198 if (SubSystems & FGAircraft::ssGroundReactions) {
200 cout << Aircraft->GetGroundReactionStrings();
202 if (SubSystems & FGAircraft::ssPropulsion) {
204 cout << Propulsion->GetPropulsionStrings();
211 cout << State->Getsim_time();
212 if (SubSystems & FGAircraft::ssSimulation) {
214 if (SubSystems & FGAircraft::ssAerosurfaces) {
216 cout << FCS->GetThrottlePos(0) << ", ";
217 cout << FCS->GetDaCmd() << ", ";
218 cout << FCS->GetDeCmd() << ", ";
219 cout << FCS->GetDrCmd() << ", ";
220 cout << FCS->GetDaPos() << ", ";
221 cout << FCS->GetDePos() << ", ";
222 cout << FCS->GetDrPos();
224 if (SubSystems & FGAircraft::ssRates) {
226 cout << Rotation->GetPQR();
228 if (SubSystems & FGAircraft::ssVelocities) {
230 cout << Translation->Getqbar() << ", ";
231 cout << Translation->GetVt() << ", ";
232 cout << Translation->GetUVW() << ", ";
233 cout << Position->GetVel();
235 if (SubSystems & FGAircraft::ssForces) {
237 cout << Aircraft->GetvFs() << ", ";
238 cout << Aircraft->GetForces();
240 if (SubSystems & FGAircraft::ssMoments) {
242 cout << Aircraft->GetMoments();
244 if (SubSystems & FGAircraft::ssAtmosphere) {
246 cout << Atmosphere->GetDensity();
248 if (SubSystems & FGAircraft::ssMassProps) {
250 cout << Aircraft->GetIxx() << ", ";
251 cout << Aircraft->GetIyy() << ", ";
252 cout << Aircraft->GetIzz() << ", ";
253 cout << Aircraft->GetIxz() << ", ";
254 cout << Aircraft->GetMass() << ", ";
255 cout << Aircraft->GetXYZcg();
257 if (SubSystems & FGAircraft::ssPosition) {
259 cout << Position->Geth() << ", ";
260 cout << Rotation->GetEuler() << ", ";
261 cout << Translation->Getalpha() << ", ";
262 cout << Position->GetLatitude() << ", ";
263 cout << Position->GetLongitude() << ", ";
264 cout << Position->GetDistanceAGL() << ", ";
265 cout << Position->GetRunwayRadius();
267 if (SubSystems & FGAircraft::ssCoefficients) {
269 cout << Aircraft->GetCoefficientValues();
271 if (SubSystems & FGAircraft::ssGroundReactions) {
273 cout << Aircraft->GetGroundReactionValues();
275 if (SubSystems & FGAircraft::ssPropulsion) {
277 cout << Propulsion->GetPropulsionValues();
283 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285 void FGOutput::DelimitedOutput(string fname)
288 datafile.open(fname.c_str());
290 if (SubSystems & FGAircraft::ssSimulation) {
293 if (SubSystems & FGAircraft::ssAerosurfaces) {
295 datafile << "Throttle, ";
296 datafile << "Aileron Cmd, ";
297 datafile << "Elevator Cmd, ";
298 datafile << "Rudder Cmd, ";
299 datafile << "Aileron Pos, ";
300 datafile << "Elevator Pos, ";
301 datafile << "Rudder Pos";
303 if (SubSystems & FGAircraft::ssRates) {
305 datafile << "P, Q, R";
307 if (SubSystems & FGAircraft::ssVelocities) {
309 datafile << "QBar, ";
310 datafile << "Vtotal, ";
311 datafile << "U, V, W, ";
312 datafile << "Vn, Ve, Vd";
314 if (SubSystems & FGAircraft::ssForces) {
316 datafile << "XsForce, YsForce, ZsForce, ";
317 datafile << "Xforce, Yforce, Zforce";
319 if (SubSystems & FGAircraft::ssMoments) {
321 datafile << "L, M, N";
323 if (SubSystems & FGAircraft::ssAtmosphere) {
327 if (SubSystems & FGAircraft::ssMassProps) {
333 datafile << "Mass, ";
334 datafile << "Xcg, Ycg, Zcg";
336 if (SubSystems & FGAircraft::ssPosition) {
338 datafile << "Altitude, ";
339 datafile << "Phi, Tht, Psi, ";
340 datafile << "Alpha, ";
341 datafile << "Latitude, ";
342 datafile << "Longitude, ";
343 datafile << "Distance AGL, ";
344 datafile << "Runway Radius";
346 if (SubSystems & FGAircraft::ssCoefficients) {
348 datafile << Aircraft->GetCoefficientStrings();
350 if (SubSystems & FGAircraft::ssGroundReactions) {
352 datafile << Aircraft->GetGroundReactionStrings();
354 if (SubSystems & FGAircraft::ssFCS) {
356 datafile << FCS->GetComponentStrings();
358 if (SubSystems & FGAircraft::ssPropulsion) {
360 datafile << Propulsion->GetPropulsionStrings();
366 datafile << State->Getsim_time();
367 if (SubSystems & FGAircraft::ssSimulation) {
369 if (SubSystems & FGAircraft::ssAerosurfaces) {
371 datafile << FCS->GetThrottlePos(0) << ", ";
372 datafile << FCS->GetDaCmd() << ", ";
373 datafile << FCS->GetDeCmd() << ", ";
374 datafile << FCS->GetDrCmd() << ", ";
375 datafile << FCS->GetDaPos() << ", ";
376 datafile << FCS->GetDePos() << ", ";
377 datafile << FCS->GetDrPos();
379 if (SubSystems & FGAircraft::ssRates) {
381 datafile << Rotation->GetPQR();
383 if (SubSystems & FGAircraft::ssVelocities) {
385 datafile << Translation->Getqbar() << ", ";
386 datafile << Translation->GetVt() << ", ";
387 datafile << Translation->GetUVW() << ", ";
388 datafile << Position->GetVel();
390 if (SubSystems & FGAircraft::ssForces) {
392 datafile << Aircraft->GetvFs() << ", ";
393 datafile << Aircraft->GetForces();
395 if (SubSystems & FGAircraft::ssMoments) {
397 datafile << Aircraft->GetMoments();
399 if (SubSystems & FGAircraft::ssAtmosphere) {
401 datafile << Atmosphere->GetDensity();
403 if (SubSystems & FGAircraft::ssMassProps) {
405 datafile << Aircraft->GetIxx() << ", ";
406 datafile << Aircraft->GetIyy() << ", ";
407 datafile << Aircraft->GetIzz() << ", ";
408 datafile << Aircraft->GetIxz() << ", ";
409 datafile << Aircraft->GetMass() << ", ";
410 datafile << Aircraft->GetXYZcg();
412 if (SubSystems & FGAircraft::ssPosition) {
414 datafile << Position->Geth() << ", ";
415 datafile << Rotation->GetEuler() << ", ";
416 datafile << Translation->Getalpha() << ", ";
417 datafile << Position->GetLatitude() << ", ";
418 datafile << Position->GetLongitude() << ", ";
419 datafile << Position->GetDistanceAGL() << ", ";
420 datafile << Position->GetRunwayRadius();
422 if (SubSystems & FGAircraft::ssCoefficients) {
424 datafile << Aircraft->GetCoefficientValues();
426 if (SubSystems & FGAircraft::ssGroundReactions) {
428 datafile << Aircraft->GetGroundReactionValues();
430 if (SubSystems & FGAircraft::ssFCS) {
432 datafile << FCS->GetComponentValues();
434 if (SubSystems & FGAircraft::ssPropulsion) {
436 datafile << Propulsion->GetPropulsionValues();
442 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
444 void FGOutput::SocketOutput(void)
448 if (socket == NULL) return;
452 socket->Append("<LABELS>");
453 socket->Append("Time");
454 socket->Append("Altitude");
455 socket->Append("Phi");
456 socket->Append("Tht");
457 socket->Append("Psi");
458 socket->Append("Rho");
459 socket->Append("Vtotal");
463 socket->Append("Vn");
464 socket->Append("Ve");
465 socket->Append("Vd");
466 socket->Append("Udot");
467 socket->Append("Vdot");
468 socket->Append("Wdot");
472 socket->Append("PDot");
473 socket->Append("QDot");
474 socket->Append("RDot");
475 socket->Append("Fx");
476 socket->Append("Fy");
477 socket->Append("Fz");
478 socket->Append("Latitude");
479 socket->Append("Longitude");
480 socket->Append("QBar");
481 socket->Append("Alpha");
485 socket->Append("Throttle");
486 socket->Append("Aileron");
487 socket->Append("Elevator");
488 socket->Append("Rudder");
494 socket->Append(State->Getsim_time());
495 socket->Append(Position->Geth());
496 socket->Append(Rotation->Getphi());
497 socket->Append(Rotation->Gettht());
498 socket->Append(Rotation->Getpsi());
499 socket->Append(Atmosphere->GetDensity());
500 socket->Append(Translation->GetVt());
501 socket->Append(Translation->GetU());
502 socket->Append(Translation->GetV());
503 socket->Append(Translation->GetW());
504 socket->Append(Position->GetVn());
505 socket->Append(Position->GetVe());
506 socket->Append(Position->GetVd());
507 socket->Append(Translation->GetUdot());
508 socket->Append(Translation->GetVdot());
509 socket->Append(Translation->GetWdot());
510 socket->Append(Rotation->GetP());
511 socket->Append(Rotation->GetQ());
512 socket->Append(Rotation->GetR());
513 socket->Append(Rotation->GetPdot());
514 socket->Append(Rotation->GetQdot());
515 socket->Append(Rotation->GetRdot());
516 socket->Append(Aircraft->GetFx());
517 socket->Append(Aircraft->GetFy());
518 socket->Append(Aircraft->GetFz());
519 socket->Append(Position->GetLatitude());
520 socket->Append(Position->GetLongitude());
521 socket->Append(Translation->Getqbar());
522 socket->Append(Translation->Getalpha());
523 socket->Append(Aircraft->GetL());
524 socket->Append(Aircraft->GetM());
525 socket->Append(Aircraft->GetN());
526 socket->Append(FCS->GetThrottle(0));
527 socket->Append(FCS->GetDa());
528 socket->Append(FCS->GetDe());
529 socket->Append(FCS->GetDr());
533 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
535 void FGOutput::SocketStatusOutput(string out_str)
539 if (socket == NULL) return;
542 asciiData = string("<STATUS>") + out_str;
543 socket->Append(asciiData.c_str());
547 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
549 void FGOutput::Debug(void)
551 //TODO: Add your source code here