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";
72 #ifdef FG_WITH_JSBSIM_SOCKET
73 socket = new FGfdmSocket("localhost",1138);
78 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 if (socket) delete socket;
86 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 bool FGOutput::Run(void)
91 if (!FGModel::Run()) {
93 if (Type == otSocket) {
95 } else if (Type == otCSV) {
96 DelimitedOutput(Filename);
97 } else if (Type == otTerminal) {
99 } else if (Type == otNone) {
102 // Not a valid type of output
111 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 void FGOutput::SetType(string type)
117 } else if (type == "TABULAR") {
119 } else if (type == "SOCKET") {
121 } else if (type == "TERMINAL") {
123 } else if (type != string("NONE")){
125 cerr << "Unknown type of output specified in config file" << endl;
129 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 void FGOutput::DelimitedOutput(string fname)
135 if (fname == "COUT" || fname == "cout") {
136 buffer = cout.rdbuf();
138 datafile.open(fname.c_str());
139 buffer = datafile.rdbuf();
142 ostream outstream(buffer);
146 if (SubSystems & ssSimulation) {
149 if (SubSystems & ssAerosurfaces) {
151 outstream << "Aileron Cmd, ";
152 outstream << "Elevator Cmd, ";
153 outstream << "Rudder Cmd, ";
154 outstream << "Aileron Pos, ";
155 outstream << "Elevator Pos, ";
156 outstream << "Rudder Pos";
158 if (SubSystems & ssRates) {
160 outstream << "P, Q, R";
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) {
184 if (SubSystems & ssMassProps) {
186 outstream << "Ixx, ";
187 outstream << "Iyy, ";
188 outstream << "Izz, ";
189 outstream << "Ixz, ";
190 outstream << "Mass, ";
191 outstream << "Xcg, Ycg, Zcg";
193 if (SubSystems & ssPosition) {
195 outstream << "Altitude, ";
196 outstream << "Phi, Tht, Psi, ";
197 outstream << "Alpha, ";
198 outstream << "Beta, ";
199 outstream << "Latitude, ";
200 outstream << "Longitude, ";
201 outstream << "Distance AGL, ";
202 outstream << "Runway Radius";
204 if (SubSystems & ssCoefficients) {
206 outstream << Aerodynamics->GetCoefficientStrings();
208 if (SubSystems & ssGroundReactions) {
210 outstream << GroundReactions->GetGroundReactionStrings();
212 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
214 outstream << Propulsion->GetPropulsionStrings();
221 outstream << State->Getsim_time();
222 if (SubSystems & ssSimulation) {
224 if (SubSystems & ssAerosurfaces) {
226 outstream << FCS->GetDaCmd() << ", ";
227 outstream << FCS->GetDeCmd() << ", ";
228 outstream << FCS->GetDrCmd() << ", ";
229 outstream << FCS->GetDaPos() << ", ";
230 outstream << FCS->GetDePos() << ", ";
231 outstream << FCS->GetDrPos();
233 if (SubSystems & ssRates) {
235 outstream << Rotation->GetPQR();
237 if (SubSystems & ssVelocities) {
239 outstream << Translation->Getqbar() << ", ";
240 outstream << Translation->GetVt() << ", ";
241 outstream << Translation->GetUVW() << ", ";
242 outstream << Translation->GetvAeroUVW() << ", ";
243 outstream << Position->GetVel();
245 if (SubSystems & ssForces) {
247 outstream << Aerodynamics->GetvFs() << ", ";
248 outstream << Aerodynamics->GetLoD() << ", ";
249 outstream << Aircraft->GetForces();
251 if (SubSystems & ssMoments) {
253 outstream << Aircraft->GetMoments();
255 if (SubSystems & ssAtmosphere) {
257 outstream << Atmosphere->GetDensity();
259 if (SubSystems & ssMassProps) {
261 outstream << MassBalance->GetIxx() << ", ";
262 outstream << MassBalance->GetIyy() << ", ";
263 outstream << MassBalance->GetIzz() << ", ";
264 outstream << MassBalance->GetIxz() << ", ";
265 outstream << MassBalance->GetMass() << ", ";
266 outstream << MassBalance->GetXYZcg();
268 if (SubSystems & ssPosition) {
270 outstream << Position->Geth() << ", ";
271 outstream << Rotation->GetEuler() << ", ";
272 outstream << Translation->Getalpha() << ", ";
273 outstream << Translation->Getbeta() << ", ";
274 outstream << Position->GetLatitude() << ", ";
275 outstream << Position->GetLongitude() << ", ";
276 outstream << Position->GetDistanceAGL() << ", ";
277 outstream << Position->GetRunwayRadius();
279 if (SubSystems & ssCoefficients) {
281 outstream << Aerodynamics->GetCoefficientValues();
283 if (SubSystems & ssGroundReactions) {
285 outstream << GroundReactions->GetGroundReactionValues();
287 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
289 outstream << Propulsion->GetPropulsionValues();
296 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298 void FGOutput::SocketOutput(void)
302 if (socket == NULL) return;
306 socket->Append("<LABELS>");
307 socket->Append("Time");
308 socket->Append("Altitude");
309 socket->Append("Phi");
310 socket->Append("Tht");
311 socket->Append("Psi");
312 socket->Append("Rho");
313 socket->Append("Vtotal");
314 socket->Append("UBody");
315 socket->Append("VBody");
316 socket->Append("WBody");
317 socket->Append("UAero");
318 socket->Append("VAero");
319 socket->Append("WAero");
320 socket->Append("Vn");
321 socket->Append("Ve");
322 socket->Append("Vd");
323 socket->Append("Udot");
324 socket->Append("Vdot");
325 socket->Append("Wdot");
329 socket->Append("PDot");
330 socket->Append("QDot");
331 socket->Append("RDot");
332 socket->Append("Fx");
333 socket->Append("Fy");
334 socket->Append("Fz");
335 socket->Append("Latitude");
336 socket->Append("Longitude");
337 socket->Append("QBar");
338 socket->Append("Alpha");
342 socket->Append("Throttle");
343 socket->Append("Aileron");
344 socket->Append("Elevator");
345 socket->Append("Rudder");
351 socket->Append(State->Getsim_time());
352 socket->Append(Position->Geth());
353 socket->Append(Rotation->Getphi());
354 socket->Append(Rotation->Gettht());
355 socket->Append(Rotation->Getpsi());
356 socket->Append(Atmosphere->GetDensity());
357 socket->Append(Translation->GetVt());
358 socket->Append(Translation->GetUVW(eU));
359 socket->Append(Translation->GetUVW(eV));
360 socket->Append(Translation->GetUVW(eW));
361 socket->Append(Translation->GetvAeroUVW(eU));
362 socket->Append(Translation->GetvAeroUVW(eV));
363 socket->Append(Translation->GetvAeroUVW(eW));
364 socket->Append(Position->GetVn());
365 socket->Append(Position->GetVe());
366 socket->Append(Position->GetVd());
367 socket->Append(Translation->GetUdot());
368 socket->Append(Translation->GetVdot());
369 socket->Append(Translation->GetWdot());
370 socket->Append(Rotation->GetP());
371 socket->Append(Rotation->GetQ());
372 socket->Append(Rotation->GetR());
373 socket->Append(Rotation->GetPdot());
374 socket->Append(Rotation->GetQdot());
375 socket->Append(Rotation->GetRdot());
376 socket->Append(Aircraft->GetFx());
377 socket->Append(Aircraft->GetFy());
378 socket->Append(Aircraft->GetFz());
379 socket->Append(Position->GetLatitude());
380 socket->Append(Position->GetLongitude());
381 socket->Append(Translation->Getqbar());
382 socket->Append(Translation->Getalpha());
383 socket->Append(Aircraft->GetL());
384 socket->Append(Aircraft->GetM());
385 socket->Append(Aircraft->GetN());
386 socket->Append(FCS->GetThrottle(0));
387 socket->Append(FCS->GetDa());
388 socket->Append(FCS->GetDe());
389 socket->Append(FCS->GetDr());
393 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
395 void FGOutput::SocketStatusOutput(string out_str)
399 if (socket == NULL) return;
402 asciiData = string("<STATUS>") + out_str;
403 socket->Append(asciiData.c_str());
407 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409 bool FGOutput::Load(FGConfigFile* AC_cfg)
411 string token, parameter;
414 token = AC_cfg->GetValue("NAME");
415 Output->SetFilename(token);
416 token = AC_cfg->GetValue("TYPE");
417 Output->SetType(token);
418 AC_cfg->GetNextConfigLine();
420 while ((token = AC_cfg->GetValue()) != string("/OUTPUT")) {
421 *AC_cfg >> parameter;
422 if (parameter == "RATE_IN_HZ") *AC_cfg >> OutRate;
423 if (parameter == "SIMULATION") {
424 *AC_cfg >> parameter;
425 if (parameter == "ON") SubSystems += ssSimulation;
427 if (parameter == "AEROSURFACES") {
428 *AC_cfg >> parameter;
429 if (parameter == "ON") SubSystems += ssAerosurfaces;
431 if (parameter == "RATES") {
432 *AC_cfg >> parameter;
433 if (parameter == "ON") SubSystems += ssRates;
435 if (parameter == "VELOCITIES") {
436 *AC_cfg >> parameter;
437 if (parameter == "ON") SubSystems += ssVelocities;
439 if (parameter == "FORCES") {
440 *AC_cfg >> parameter;
441 if (parameter == "ON") SubSystems += ssForces;
443 if (parameter == "MOMENTS") {
444 *AC_cfg >> parameter;
445 if (parameter == "ON") SubSystems += ssMoments;
447 if (parameter == "ATMOSPHERE") {
448 *AC_cfg >> parameter;
449 if (parameter == "ON") SubSystems += ssAtmosphere;
451 if (parameter == "MASSPROPS") {
452 *AC_cfg >> parameter;
453 if (parameter == "ON") SubSystems += ssMassProps;
455 if (parameter == "POSITION") {
456 *AC_cfg >> parameter;
457 if (parameter == "ON") SubSystems += ssPosition;
459 if (parameter == "COEFFICIENTS") {
460 *AC_cfg >> parameter;
461 if (parameter == "ON") SubSystems += ssCoefficients;
463 if (parameter == "GROUND_REACTIONS") {
464 *AC_cfg >> parameter;
465 if (parameter == "ON") SubSystems += ssGroundReactions;
467 if (parameter == "FCS") {
468 *AC_cfg >> parameter;
469 if (parameter == "ON") SubSystems += ssFCS;
471 if (parameter == "PROPULSION") {
472 *AC_cfg >> parameter;
473 if (parameter == "ON") SubSystems += ssPropulsion;
477 OutRate = OutRate>120?120:(OutRate<0?0:OutRate);
478 rate = (int)(0.5 + 1.0/(State->Getdt()*OutRate));
483 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
484 // The bitmasked value choices are as follows:
485 // unset: In this case (the default) JSBSim would only print
486 // out the normally expected messages, essentially echoing
487 // the config files as they are read. If the environment
488 // variable is not set, debug_lvl is set to 1 internally
489 // 0: This requests JSBSim not to output any messages
491 // 1: This value explicity requests the normal JSBSim
493 // 2: This value asks for a message to be printed out when
494 // a class is instantiated
495 // 4: When this value is set, a message is displayed when a
496 // FGModel object executes its Run() method
497 // 8: When this value is set, various runtime state variables
498 // are printed out periodically
499 // 16: When set various parameters are sanity checked and
500 // a message is printed out when they go out of bounds
502 void FGOutput::Debug(int from)
504 if (debug_lvl <= 0) return;
506 if (debug_lvl & 1) { // Standard console startup message output
507 if (from == 0) { // Constructor
511 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
512 if (from == 0) cout << "Instantiated: FGOutput" << endl;
513 if (from == 1) cout << "Destroyed: FGOutput" << endl;
515 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
517 if (debug_lvl & 8 ) { // Runtime state variables
519 if (debug_lvl & 16) { // Sanity checking