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 "FGAerodynamics.h"
47 #include "FGGroundReactions.h"
48 #include "FGAircraft.h"
49 #include "FGMassBalance.h"
50 #include "FGTranslation.h"
51 #include "FGRotation.h"
52 #include "FGPosition.h"
53 #include "FGAuxiliary.h"
55 static const char *IdSrc = "$Id$";
56 static const char *IdHdr = ID_OUTPUT;
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62 FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
65 sFirstPass = dFirstPass = true;
68 Filename = "JSBSim.out";
75 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 if (socket) delete socket;
83 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 bool FGOutput::Run(void)
88 if (!FGModel::Run()) {
90 if (Type == otSocket) {
92 } else if (Type == otCSV) {
93 DelimitedOutput(Filename);
94 } else if (Type == otTerminal) {
96 } else if (Type == otNone) {
99 // Not a valid type of output
108 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110 void FGOutput::SetType(string type)
114 } else if (type == "TABULAR") {
116 } else if (type == "SOCKET") {
118 } else if (type == "TERMINAL") {
120 } else if (type != string("NONE")){
122 cerr << "Unknown type of output specified in config file" << endl;
126 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 void FGOutput::DelimitedOutput(string fname)
132 if (fname == "COUT" || fname == "cout") {
133 buffer = cout.rdbuf();
135 datafile.open(fname.c_str());
136 buffer = datafile.rdbuf();
139 ostream outstream(buffer);
143 if (SubSystems & ssSimulation) {
146 if (SubSystems & ssAerosurfaces) {
148 outstream << "Aileron Cmd, ";
149 outstream << "Elevator Cmd, ";
150 outstream << "Rudder Cmd, ";
151 outstream << "Flap Cmd, ";
152 outstream << "Aileron Pos, ";
153 outstream << "Elevator Pos, ";
154 outstream << "Rudder Pos, ";
155 outstream << "Flap Pos";
157 if (SubSystems & ssRates) {
159 outstream << "P, Q, R, ";
160 outstream << "Pdot, Qdot, Rdot";
162 if (SubSystems & ssVelocities) {
164 outstream << "QBar, ";
165 outstream << "Vtotal, ";
166 outstream << "UBody, VBody, WBody, ";
167 outstream << "UAero, VAero, WAero, ";
168 outstream << "Vn, Ve, Vd";
170 if (SubSystems & ssForces) {
172 outstream << "Drag, Side, Lift, ";
173 outstream << "L/D, ";
174 outstream << "Xforce, Yforce, Zforce";
176 if (SubSystems & ssMoments) {
178 outstream << "L, M, N";
180 if (SubSystems & ssAtmosphere) {
182 outstream << "Rho, ";
183 outstream << "NWind, EWind, DWind";
185 if (SubSystems & ssMassProps) {
187 outstream << "Ixx, ";
188 outstream << "Iyy, ";
189 outstream << "Izz, ";
190 outstream << "Ixz, ";
191 outstream << "Mass, ";
192 outstream << "Xcg, Ycg, Zcg";
194 if (SubSystems & ssPosition) {
196 outstream << "Altitude, ";
197 outstream << "Phi, Tht, Psi, ";
198 outstream << "Alpha, ";
199 outstream << "Beta, ";
200 outstream << "Latitude, ";
201 outstream << "Longitude, ";
202 outstream << "Distance AGL, ";
203 outstream << "Runway Radius";
205 if (SubSystems & ssCoefficients) {
207 outstream << Aerodynamics->GetCoefficientStrings();
209 if (SubSystems & ssGroundReactions) {
211 outstream << GroundReactions->GetGroundReactionStrings();
213 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
215 outstream << Propulsion->GetPropulsionStrings();
222 outstream << State->Getsim_time();
223 if (SubSystems & ssSimulation) {
225 if (SubSystems & ssAerosurfaces) {
227 outstream << FCS->GetDaCmd() << ", ";
228 outstream << FCS->GetDeCmd() << ", ";
229 outstream << FCS->GetDrCmd() << ", ";
230 outstream << FCS->GetDfCmd() << ", ";
231 outstream << FCS->GetDaPos() << ", ";
232 outstream << FCS->GetDePos() << ", ";
233 outstream << FCS->GetDrPos() << ", ";
234 outstream << FCS->GetDfPos();
236 if (SubSystems & ssRates) {
238 outstream << Rotation->GetPQR() << ", ";
239 outstream << Rotation->GetPQRdot();
241 if (SubSystems & ssVelocities) {
243 outstream << Translation->Getqbar() << ", ";
244 outstream << Translation->GetVt() << ", ";
245 outstream << Translation->GetUVW() << ", ";
246 outstream << Translation->GetvAeroUVW() << ", ";
247 outstream << Position->GetVel();
249 if (SubSystems & ssForces) {
251 outstream << Aerodynamics->GetvFs() << ", ";
252 outstream << Aerodynamics->GetLoD() << ", ";
253 outstream << Aircraft->GetForces();
255 if (SubSystems & ssMoments) {
257 outstream << Aircraft->GetMoments();
259 if (SubSystems & ssAtmosphere) {
261 outstream << Atmosphere->GetDensity() << ", ";
262 outstream << Atmosphere->GetWindNED();
264 if (SubSystems & ssMassProps) {
266 outstream << MassBalance->GetIxx() << ", ";
267 outstream << MassBalance->GetIyy() << ", ";
268 outstream << MassBalance->GetIzz() << ", ";
269 outstream << MassBalance->GetIxz() << ", ";
270 outstream << MassBalance->GetMass() << ", ";
271 outstream << MassBalance->GetXYZcg();
273 if (SubSystems & ssPosition) {
275 outstream << Position->Geth() << ", ";
276 outstream << Rotation->GetEuler() << ", ";
277 outstream << Translation->Getalpha() << ", ";
278 outstream << Translation->Getbeta() << ", ";
279 outstream << Position->GetLatitude() << ", ";
280 outstream << Position->GetLongitude() << ", ";
281 outstream << Position->GetDistanceAGL() << ", ";
282 outstream << Position->GetRunwayRadius();
284 if (SubSystems & ssCoefficients) {
286 outstream << Aerodynamics->GetCoefficientValues();
288 if (SubSystems & ssGroundReactions) {
290 outstream << GroundReactions->GetGroundReactionValues();
292 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
294 outstream << Propulsion->GetPropulsionValues();
301 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303 void FGOutput::SocketOutput(void)
307 if (socket == NULL) return;
308 if (!socket->GetConnectStatus()) return;
312 socket->Append("<LABELS>");
313 socket->Append("Time");
314 socket->Append("Altitude");
315 socket->Append("Phi");
316 socket->Append("Tht");
317 socket->Append("Psi");
318 socket->Append("Rho");
319 socket->Append("Vtotal");
320 socket->Append("UBody");
321 socket->Append("VBody");
322 socket->Append("WBody");
323 socket->Append("UAero");
324 socket->Append("VAero");
325 socket->Append("WAero");
326 socket->Append("Vn");
327 socket->Append("Ve");
328 socket->Append("Vd");
329 socket->Append("Udot");
330 socket->Append("Vdot");
331 socket->Append("Wdot");
335 socket->Append("PDot");
336 socket->Append("QDot");
337 socket->Append("RDot");
338 socket->Append("Fx");
339 socket->Append("Fy");
340 socket->Append("Fz");
341 socket->Append("Latitude");
342 socket->Append("Longitude");
343 socket->Append("QBar");
344 socket->Append("Alpha");
348 socket->Append("Throttle Position");
349 socket->Append("Aileron Position");
350 socket->Append("Elevator Position");
351 socket->Append("Rudder Position");
357 socket->Append(State->Getsim_time());
358 socket->Append(Position->Geth());
359 socket->Append(Rotation->Getphi());
360 socket->Append(Rotation->Gettht());
361 socket->Append(Rotation->Getpsi());
362 socket->Append(Atmosphere->GetDensity());
363 socket->Append(Translation->GetVt());
364 socket->Append(Translation->GetUVW(eU));
365 socket->Append(Translation->GetUVW(eV));
366 socket->Append(Translation->GetUVW(eW));
367 socket->Append(Translation->GetvAeroUVW(eU));
368 socket->Append(Translation->GetvAeroUVW(eV));
369 socket->Append(Translation->GetvAeroUVW(eW));
370 socket->Append(Position->GetVn());
371 socket->Append(Position->GetVe());
372 socket->Append(Position->GetVd());
373 socket->Append(Translation->GetUVWdot(eU));
374 socket->Append(Translation->GetUVWdot(eV));
375 socket->Append(Translation->GetUVWdot(eW));
376 socket->Append(Rotation->GetPQR(eP));
377 socket->Append(Rotation->GetPQR(eQ));
378 socket->Append(Rotation->GetPQR(eR));
379 socket->Append(Rotation->GetPQRdot(eP));
380 socket->Append(Rotation->GetPQRdot(eQ));
381 socket->Append(Rotation->GetPQRdot(eR));
382 socket->Append(Aircraft->GetForces(eX));
383 socket->Append(Aircraft->GetForces(eY));
384 socket->Append(Aircraft->GetForces(eZ));
385 socket->Append(Position->GetLatitude());
386 socket->Append(Position->GetLongitude());
387 socket->Append(Translation->Getqbar());
388 socket->Append(Translation->Getalpha());
389 socket->Append(Aircraft->GetMoments(eL));
390 socket->Append(Aircraft->GetMoments(eM));
391 socket->Append(Aircraft->GetMoments(eN));
392 socket->Append(FCS->GetThrottlePos(0));
393 socket->Append(FCS->GetDaPos());
394 socket->Append(FCS->GetDePos());
395 socket->Append(FCS->GetDrPos());
399 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
401 void FGOutput::SocketStatusOutput(string out_str)
405 if (socket == NULL) return;
408 asciiData = string("<STATUS>") + out_str;
409 socket->Append(asciiData.c_str());
413 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
415 bool FGOutput::Load(FGConfigFile* AC_cfg)
417 string token, parameter;
420 token = AC_cfg->GetValue("NAME");
421 Output->SetFilename(token);
422 token = AC_cfg->GetValue("TYPE");
423 Output->SetType(token);
425 #if defined( FG_WITH_JSBSIM_SOCKET ) || !defined( FGFS )
426 if (token == "SOCKET") {
427 socket = new FGfdmSocket("localhost",1138);
431 AC_cfg->GetNextConfigLine();
433 while ((token = AC_cfg->GetValue()) != string("/OUTPUT")) {
434 *AC_cfg >> parameter;
435 if (parameter == "RATE_IN_HZ") *AC_cfg >> OutRate;
436 if (parameter == "SIMULATION") {
437 *AC_cfg >> parameter;
438 if (parameter == "ON") SubSystems += ssSimulation;
440 if (parameter == "AEROSURFACES") {
441 *AC_cfg >> parameter;
442 if (parameter == "ON") SubSystems += ssAerosurfaces;
444 if (parameter == "RATES") {
445 *AC_cfg >> parameter;
446 if (parameter == "ON") SubSystems += ssRates;
448 if (parameter == "VELOCITIES") {
449 *AC_cfg >> parameter;
450 if (parameter == "ON") SubSystems += ssVelocities;
452 if (parameter == "FORCES") {
453 *AC_cfg >> parameter;
454 if (parameter == "ON") SubSystems += ssForces;
456 if (parameter == "MOMENTS") {
457 *AC_cfg >> parameter;
458 if (parameter == "ON") SubSystems += ssMoments;
460 if (parameter == "ATMOSPHERE") {
461 *AC_cfg >> parameter;
462 if (parameter == "ON") SubSystems += ssAtmosphere;
464 if (parameter == "MASSPROPS") {
465 *AC_cfg >> parameter;
466 if (parameter == "ON") SubSystems += ssMassProps;
468 if (parameter == "POSITION") {
469 *AC_cfg >> parameter;
470 if (parameter == "ON") SubSystems += ssPosition;
472 if (parameter == "COEFFICIENTS") {
473 *AC_cfg >> parameter;
474 if (parameter == "ON") SubSystems += ssCoefficients;
476 if (parameter == "GROUND_REACTIONS") {
477 *AC_cfg >> parameter;
478 if (parameter == "ON") SubSystems += ssGroundReactions;
480 if (parameter == "FCS") {
481 *AC_cfg >> parameter;
482 if (parameter == "ON") SubSystems += ssFCS;
484 if (parameter == "PROPULSION") {
485 *AC_cfg >> parameter;
486 if (parameter == "ON") SubSystems += ssPropulsion;
490 OutRate = OutRate>120?120:(OutRate<0?0:OutRate);
491 rate = (int)(0.5 + 1.0/(State->Getdt()*OutRate));
496 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
497 // The bitmasked value choices are as follows:
498 // unset: In this case (the default) JSBSim would only print
499 // out the normally expected messages, essentially echoing
500 // the config files as they are read. If the environment
501 // variable is not set, debug_lvl is set to 1 internally
502 // 0: This requests JSBSim not to output any messages
504 // 1: This value explicity requests the normal JSBSim
506 // 2: This value asks for a message to be printed out when
507 // a class is instantiated
508 // 4: When this value is set, a message is displayed when a
509 // FGModel object executes its Run() method
510 // 8: When this value is set, various runtime state variables
511 // are printed out periodically
512 // 16: When set various parameters are sanity checked and
513 // a message is printed out when they go out of bounds
515 void FGOutput::Debug(int from)
517 if (debug_lvl <= 0) return;
519 if (debug_lvl & 1) { // Standard console startup message output
520 if (from == 0) { // Constructor
524 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
525 if (from == 0) cout << "Instantiated: FGOutput" << endl;
526 if (from == 1) cout << "Destroyed: FGOutput" << endl;
528 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
530 if (debug_lvl & 8 ) { // Runtime state variables
532 if (debug_lvl & 16) { // Sanity checking
534 if (debug_lvl & 64) {
535 if (from == 0) { // Constructor
536 cout << IdSrc << endl;
537 cout << IdHdr << endl;