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
109 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 void FGOutput::SetType(string type)
115 } else if (type == "TABULAR") {
117 } else if (type == "SOCKET") {
119 } else if (type == "TERMINAL") {
121 } else if (type != string("NONE")) {
123 cerr << "Unknown type of output specified in config file" << endl;
127 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 void FGOutput::DelimitedOutput(string fname)
133 if (fname == "COUT" || fname == "cout") {
134 buffer = cout.rdbuf();
136 datafile.open(fname.c_str());
137 buffer = datafile.rdbuf();
140 ostream outstream(buffer);
144 if (SubSystems & ssSimulation) {
147 if (SubSystems & ssAerosurfaces) {
149 outstream << "Aileron Cmd, ";
150 outstream << "Elevator Cmd, ";
151 outstream << "Rudder Cmd, ";
152 outstream << "Flap Cmd, ";
153 outstream << "Left Aileron Pos, ";
154 outstream << "Right Aileron Pos, ";
155 outstream << "Elevator Pos, ";
156 outstream << "Rudder Pos, ";
157 outstream << "Flap Pos";
159 if (SubSystems & ssRates) {
161 outstream << "P, Q, R, ";
162 outstream << "Pdot, Qdot, Rdot";
164 if (SubSystems & ssVelocities) {
166 outstream << "QBar, ";
167 outstream << "Vtotal, ";
168 outstream << "UBody, VBody, WBody, ";
169 outstream << "UAero, VAero, WAero, ";
170 outstream << "Vn, Ve, Vd";
172 if (SubSystems & ssForces) {
174 outstream << "Drag, Side, Lift, ";
175 outstream << "L/D, ";
176 outstream << "Xforce, Yforce, Zforce, ";
177 outstream << "xGravity, yGravity, zGravity, ";
178 outstream << "xCoriolis, yCoriolis, zCoriolis, ";
179 outstream << "xCentrifugal, yCentrifugal, zCentrifugal";
181 if (SubSystems & ssMoments) {
183 outstream << "L, M, N";
185 if (SubSystems & ssAtmosphere) {
187 outstream << "Rho, ";
188 outstream << "NWind, EWind, DWind";
190 if (SubSystems & ssMassProps) {
192 outstream << "Ixx, ";
193 outstream << "Iyy, ";
194 outstream << "Izz, ";
195 outstream << "Ixz, ";
196 outstream << "Mass, ";
197 outstream << "Xcg, Ycg, Zcg";
199 if (SubSystems & ssPosition) {
201 outstream << "Altitude, ";
202 outstream << "Phi, Tht, Psi, ";
203 outstream << "Alpha, ";
204 outstream << "Beta, ";
205 outstream << "Latitude, ";
206 outstream << "Longitude, ";
207 outstream << "Distance AGL, ";
208 outstream << "Runway Radius";
210 if (SubSystems & ssCoefficients) {
212 outstream << Aerodynamics->GetCoefficientStrings();
214 if (SubSystems & ssGroundReactions) {
216 outstream << GroundReactions->GetGroundReactionStrings();
218 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
220 outstream << Propulsion->GetPropulsionStrings();
227 outstream << State->Getsim_time();
228 if (SubSystems & ssSimulation) {
230 if (SubSystems & ssAerosurfaces) {
232 outstream << FCS->GetDaCmd() << ", ";
233 outstream << FCS->GetDeCmd() << ", ";
234 outstream << FCS->GetDrCmd() << ", ";
235 outstream << FCS->GetDfCmd() << ", ";
236 outstream << FCS->GetDaLPos() << ", ";
237 outstream << FCS->GetDaRPos() << ", ";
238 outstream << FCS->GetDePos() << ", ";
239 outstream << FCS->GetDrPos() << ", ";
240 outstream << FCS->GetDfPos();
242 if (SubSystems & ssRates) {
244 outstream << Rotation->GetPQR() << ", ";
245 outstream << Rotation->GetPQRdot();
247 if (SubSystems & ssVelocities) {
249 outstream << Translation->Getqbar() << ", ";
250 outstream << Translation->GetVt() << ", ";
251 outstream << Translation->GetUVW() << ", ";
252 outstream << Translation->GetAeroUVW() << ", ";
253 outstream << Position->GetVel();
255 if (SubSystems & ssForces) {
257 outstream << Aerodynamics->GetvFs() << ", ";
258 outstream << Aerodynamics->GetLoD() << ", ";
259 outstream << Aircraft->GetForces() << ", ";
260 outstream << Inertial->GetGravity() << ", ";
261 outstream << Inertial->GetCoriolis() << ", ";
262 outstream << Inertial->GetCentrifugal();
264 if (SubSystems & ssMoments) {
266 outstream << Aircraft->GetMoments();
268 if (SubSystems & ssAtmosphere) {
270 outstream << Atmosphere->GetDensity() << ", ";
271 outstream << Atmosphere->GetWindNED();
273 if (SubSystems & ssMassProps) {
275 outstream << MassBalance->GetIxx() << ", ";
276 outstream << MassBalance->GetIyy() << ", ";
277 outstream << MassBalance->GetIzz() << ", ";
278 outstream << MassBalance->GetIxz() << ", ";
279 outstream << MassBalance->GetMass() << ", ";
280 outstream << MassBalance->GetXYZcg();
282 if (SubSystems & ssPosition) {
284 outstream << Position->Geth() << ", ";
285 outstream << Rotation->GetEuler() << ", ";
286 outstream << Translation->Getalpha() << ", ";
287 outstream << Translation->Getbeta() << ", ";
288 outstream << Position->GetLatitude() << ", ";
289 outstream << Position->GetLongitude() << ", ";
290 outstream << Position->GetDistanceAGL() << ", ";
291 outstream << Position->GetRunwayRadius();
293 if (SubSystems & ssCoefficients) {
295 outstream << Aerodynamics->GetCoefficientValues();
297 if (SubSystems & ssGroundReactions) {
299 outstream << GroundReactions->GetGroundReactionValues();
301 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
303 outstream << Propulsion->GetPropulsionValues();
310 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
312 void FGOutput::SocketOutput(void)
316 if (socket == NULL) return;
317 if (!socket->GetConnectStatus()) return;
321 socket->Append("<LABELS>");
322 socket->Append("Time");
323 socket->Append("Altitude");
324 socket->Append("Phi");
325 socket->Append("Tht");
326 socket->Append("Psi");
327 socket->Append("Rho");
328 socket->Append("Vtotal");
329 socket->Append("UBody");
330 socket->Append("VBody");
331 socket->Append("WBody");
332 socket->Append("UAero");
333 socket->Append("VAero");
334 socket->Append("WAero");
335 socket->Append("Vn");
336 socket->Append("Ve");
337 socket->Append("Vd");
338 socket->Append("Udot");
339 socket->Append("Vdot");
340 socket->Append("Wdot");
344 socket->Append("PDot");
345 socket->Append("QDot");
346 socket->Append("RDot");
347 socket->Append("Fx");
348 socket->Append("Fy");
349 socket->Append("Fz");
350 socket->Append("Latitude");
351 socket->Append("Longitude");
352 socket->Append("QBar");
353 socket->Append("Alpha");
357 socket->Append("Throttle Position");
358 socket->Append("Left Aileron Position");
359 socket->Append("Right Aileron Position");
360 socket->Append("Elevator Position");
361 socket->Append("Rudder Position");
367 socket->Append(State->Getsim_time());
368 socket->Append(Position->Geth());
369 socket->Append(Rotation->Getphi());
370 socket->Append(Rotation->Gettht());
371 socket->Append(Rotation->Getpsi());
372 socket->Append(Atmosphere->GetDensity());
373 socket->Append(Translation->GetVt());
374 socket->Append(Translation->GetUVW(eU));
375 socket->Append(Translation->GetUVW(eV));
376 socket->Append(Translation->GetUVW(eW));
377 socket->Append(Translation->GetAeroUVW(eU));
378 socket->Append(Translation->GetAeroUVW(eV));
379 socket->Append(Translation->GetAeroUVW(eW));
380 socket->Append(Position->GetVn());
381 socket->Append(Position->GetVe());
382 socket->Append(Position->GetVd());
383 socket->Append(Translation->GetUVWdot(eU));
384 socket->Append(Translation->GetUVWdot(eV));
385 socket->Append(Translation->GetUVWdot(eW));
386 socket->Append(Rotation->GetPQR(eP));
387 socket->Append(Rotation->GetPQR(eQ));
388 socket->Append(Rotation->GetPQR(eR));
389 socket->Append(Rotation->GetPQRdot(eP));
390 socket->Append(Rotation->GetPQRdot(eQ));
391 socket->Append(Rotation->GetPQRdot(eR));
392 socket->Append(Aircraft->GetForces(eX));
393 socket->Append(Aircraft->GetForces(eY));
394 socket->Append(Aircraft->GetForces(eZ));
395 socket->Append(Position->GetLatitude());
396 socket->Append(Position->GetLongitude());
397 socket->Append(Translation->Getqbar());
398 socket->Append(Translation->Getalpha());
399 socket->Append(Aircraft->GetMoments(eL));
400 socket->Append(Aircraft->GetMoments(eM));
401 socket->Append(Aircraft->GetMoments(eN));
402 socket->Append(FCS->GetThrottlePos(0));
403 socket->Append(FCS->GetDaLPos());
404 socket->Append(FCS->GetDaRPos());
405 socket->Append(FCS->GetDePos());
406 socket->Append(FCS->GetDrPos());
410 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
412 void FGOutput::SocketStatusOutput(string out_str)
416 if (socket == NULL) return;
419 asciiData = string("<STATUS>") + out_str;
420 socket->Append(asciiData.c_str());
424 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
426 bool FGOutput::Load(FGConfigFile* AC_cfg)
428 string token, parameter;
431 token = AC_cfg->GetValue("NAME");
432 Output->SetFilename(token);
433 token = AC_cfg->GetValue("TYPE");
434 Output->SetType(token);
436 #if defined( FG_WITH_JSBSIM_SOCKET ) || !defined( FGFS )
437 if (token == "SOCKET") {
438 socket = new FGfdmSocket("localhost",1138);
442 AC_cfg->GetNextConfigLine();
444 while ((token = AC_cfg->GetValue()) != string("/OUTPUT")) {
445 *AC_cfg >> parameter;
446 if (parameter == "RATE_IN_HZ") *AC_cfg >> OutRate;
447 if (parameter == "SIMULATION") {
448 *AC_cfg >> parameter;
449 if (parameter == "ON") SubSystems += ssSimulation;
451 if (parameter == "AEROSURFACES") {
452 *AC_cfg >> parameter;
453 if (parameter == "ON") SubSystems += ssAerosurfaces;
455 if (parameter == "RATES") {
456 *AC_cfg >> parameter;
457 if (parameter == "ON") SubSystems += ssRates;
459 if (parameter == "VELOCITIES") {
460 *AC_cfg >> parameter;
461 if (parameter == "ON") SubSystems += ssVelocities;
463 if (parameter == "FORCES") {
464 *AC_cfg >> parameter;
465 if (parameter == "ON") SubSystems += ssForces;
467 if (parameter == "MOMENTS") {
468 *AC_cfg >> parameter;
469 if (parameter == "ON") SubSystems += ssMoments;
471 if (parameter == "ATMOSPHERE") {
472 *AC_cfg >> parameter;
473 if (parameter == "ON") SubSystems += ssAtmosphere;
475 if (parameter == "MASSPROPS") {
476 *AC_cfg >> parameter;
477 if (parameter == "ON") SubSystems += ssMassProps;
479 if (parameter == "POSITION") {
480 *AC_cfg >> parameter;
481 if (parameter == "ON") SubSystems += ssPosition;
483 if (parameter == "COEFFICIENTS") {
484 *AC_cfg >> parameter;
485 if (parameter == "ON") SubSystems += ssCoefficients;
487 if (parameter == "GROUND_REACTIONS") {
488 *AC_cfg >> parameter;
489 if (parameter == "ON") SubSystems += ssGroundReactions;
491 if (parameter == "FCS") {
492 *AC_cfg >> parameter;
493 if (parameter == "ON") SubSystems += ssFCS;
495 if (parameter == "PROPULSION") {
496 *AC_cfg >> parameter;
497 if (parameter == "ON") SubSystems += ssPropulsion;
501 OutRate = OutRate>120?120:(OutRate<0?0:OutRate);
502 rate = (int)(0.5 + 1.0/(State->Getdt()*OutRate));
507 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
508 // The bitmasked value choices are as follows:
509 // unset: In this case (the default) JSBSim would only print
510 // out the normally expected messages, essentially echoing
511 // the config files as they are read. If the environment
512 // variable is not set, debug_lvl is set to 1 internally
513 // 0: This requests JSBSim not to output any messages
515 // 1: This value explicity requests the normal JSBSim
517 // 2: This value asks for a message to be printed out when
518 // a class is instantiated
519 // 4: When this value is set, a message is displayed when a
520 // FGModel object executes its Run() method
521 // 8: When this value is set, various runtime state variables
522 // are printed out periodically
523 // 16: When set various parameters are sanity checked and
524 // a message is printed out when they go out of bounds
526 void FGOutput::Debug(int from)
528 if (debug_lvl <= 0) return;
530 if (debug_lvl & 1) { // Standard console startup message output
531 if (from == 0) { // Constructor
535 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
536 if (from == 0) cout << "Instantiated: FGOutput" << endl;
537 if (from == 1) cout << "Destroyed: FGOutput" << endl;
539 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
541 if (debug_lvl & 8 ) { // Runtime state variables
543 if (debug_lvl & 16) { // Sanity checking
545 if (debug_lvl & 64) {
546 if (from == 0) { // Constructor
547 cout << IdSrc << endl;
548 cout << IdHdr << endl;