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"
57 static const char *IdSrc = "$Id$";
58 static const char *IdHdr = ID_OUTPUT;
60 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64 FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
67 sFirstPass = dFirstPass = true;
70 Filename = "JSBSim.out";
77 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 if (socket) delete socket;
85 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 bool FGOutput::Run(void)
90 if (!FGModel::Run()) {
92 if (Type == otSocket) {
94 } else if (Type == otCSV) {
95 DelimitedOutput(Filename);
96 } else if (Type == otTerminal) {
98 } else if (Type == otNone) {
101 // 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 << "Flap Cmd, ";
155 outstream << "Left Aileron Pos, ";
156 outstream << "Right Aileron Pos, ";
157 outstream << "Elevator Pos, ";
158 outstream << "Rudder Pos, ";
159 outstream << "Flap Pos";
161 if (SubSystems & ssRates) {
163 outstream << "P, Q, R, ";
164 outstream << "Pdot, Qdot, Rdot";
166 if (SubSystems & ssVelocities) {
168 outstream << "QBar, ";
169 outstream << "Vtotal, ";
170 outstream << "UBody, VBody, WBody, ";
171 outstream << "UAero, VAero, WAero, ";
172 outstream << "Vn, Ve, Vd";
174 if (SubSystems & ssForces) {
176 outstream << "Drag, Side, Lift, ";
177 outstream << "L/D, ";
178 outstream << "Xforce, Yforce, Zforce, ";
179 outstream << "xGravity, yGravity, zGravity, ";
180 outstream << "xCoriolis, yCoriolis, zCoriolis, ";
181 outstream << "xCentrifugal, yCentrifugal, zCentrifugal";
183 if (SubSystems & ssMoments) {
185 outstream << "L, M, N";
187 if (SubSystems & ssAtmosphere) {
189 outstream << "Rho, ";
190 outstream << "NWind, EWind, DWind";
192 if (SubSystems & ssMassProps) {
194 outstream << "Ixx, ";
195 outstream << "Iyy, ";
196 outstream << "Izz, ";
197 outstream << "Ixz, ";
198 outstream << "Mass, ";
199 outstream << "Xcg, Ycg, Zcg";
201 if (SubSystems & ssPosition) {
203 outstream << "Altitude, ";
204 outstream << "Phi, Tht, Psi, ";
205 outstream << "Alpha, ";
206 outstream << "Beta, ";
207 outstream << "Latitude, ";
208 outstream << "Longitude, ";
209 outstream << "Distance AGL, ";
210 outstream << "Runway Radius";
212 if (SubSystems & ssCoefficients) {
214 outstream << Aerodynamics->GetCoefficientStrings();
216 if (SubSystems & ssFCS) {
218 outstream << FCS->GetComponentStrings();
220 if (SubSystems & ssGroundReactions) {
222 outstream << GroundReactions->GetGroundReactionStrings();
224 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
226 outstream << Propulsion->GetPropulsionStrings();
233 outstream << State->Getsim_time();
234 if (SubSystems & ssSimulation) {
236 if (SubSystems & ssAerosurfaces) {
238 outstream << FCS->GetDaCmd() << ", ";
239 outstream << FCS->GetDeCmd() << ", ";
240 outstream << FCS->GetDrCmd() << ", ";
241 outstream << FCS->GetDfCmd() << ", ";
242 outstream << FCS->GetDaLPos() << ", ";
243 outstream << FCS->GetDaRPos() << ", ";
244 outstream << FCS->GetDePos() << ", ";
245 outstream << FCS->GetDrPos() << ", ";
246 outstream << FCS->GetDfPos();
248 if (SubSystems & ssRates) {
250 outstream << Rotation->GetPQR() << ", ";
251 outstream << Rotation->GetPQRdot();
253 if (SubSystems & ssVelocities) {
255 outstream << Translation->Getqbar() << ", ";
256 outstream << Translation->GetVt() << ", ";
257 outstream << Translation->GetUVW() << ", ";
258 outstream << Translation->GetAeroUVW() << ", ";
259 outstream << Position->GetVel();
261 if (SubSystems & ssForces) {
263 outstream << Aerodynamics->GetvFs() << ", ";
264 outstream << Aerodynamics->GetLoD() << ", ";
265 outstream << Aircraft->GetForces() << ", ";
266 outstream << Inertial->GetGravity() << ", ";
267 outstream << Inertial->GetCoriolis() << ", ";
268 outstream << Inertial->GetCentrifugal();
270 if (SubSystems & ssMoments) {
272 outstream << Aircraft->GetMoments();
274 if (SubSystems & ssAtmosphere) {
276 outstream << Atmosphere->GetDensity() << ", ";
277 outstream << Atmosphere->GetWindNED();
279 if (SubSystems & ssMassProps) {
281 outstream << MassBalance->GetIxx() << ", ";
282 outstream << MassBalance->GetIyy() << ", ";
283 outstream << MassBalance->GetIzz() << ", ";
284 outstream << MassBalance->GetIxz() << ", ";
285 outstream << MassBalance->GetMass() << ", ";
286 outstream << MassBalance->GetXYZcg();
288 if (SubSystems & ssPosition) {
290 outstream << Position->Geth() << ", ";
291 outstream << Rotation->GetEuler() << ", ";
292 outstream << Translation->Getalpha() << ", ";
293 outstream << Translation->Getbeta() << ", ";
294 outstream << Position->GetLatitude() << ", ";
295 outstream << Position->GetLongitude() << ", ";
296 outstream << Position->GetDistanceAGL() << ", ";
297 outstream << Position->GetRunwayRadius();
299 if (SubSystems & ssCoefficients) {
301 outstream << Aerodynamics->GetCoefficientValues();
303 if (SubSystems & ssFCS) {
305 outstream << FCS->GetComponentValues();
307 if (SubSystems & ssGroundReactions) {
309 outstream << GroundReactions->GetGroundReactionValues();
311 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
313 outstream << Propulsion->GetPropulsionValues();
320 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
322 void FGOutput::SocketOutput(void)
326 if (socket == NULL) return;
327 if (!socket->GetConnectStatus()) return;
331 socket->Append("<LABELS>");
332 socket->Append("Time");
333 socket->Append("Altitude");
334 socket->Append("Phi");
335 socket->Append("Tht");
336 socket->Append("Psi");
337 socket->Append("Rho");
338 socket->Append("Vtotal");
339 socket->Append("UBody");
340 socket->Append("VBody");
341 socket->Append("WBody");
342 socket->Append("UAero");
343 socket->Append("VAero");
344 socket->Append("WAero");
345 socket->Append("Vn");
346 socket->Append("Ve");
347 socket->Append("Vd");
348 socket->Append("Udot");
349 socket->Append("Vdot");
350 socket->Append("Wdot");
354 socket->Append("PDot");
355 socket->Append("QDot");
356 socket->Append("RDot");
357 socket->Append("Fx");
358 socket->Append("Fy");
359 socket->Append("Fz");
360 socket->Append("Latitude");
361 socket->Append("Longitude");
362 socket->Append("QBar");
363 socket->Append("Alpha");
367 socket->Append("Throttle Position");
368 socket->Append("Left Aileron Position");
369 socket->Append("Right Aileron Position");
370 socket->Append("Elevator Position");
371 socket->Append("Rudder Position");
377 socket->Append(State->Getsim_time());
378 socket->Append(Position->Geth());
379 socket->Append(Rotation->Getphi());
380 socket->Append(Rotation->Gettht());
381 socket->Append(Rotation->Getpsi());
382 socket->Append(Atmosphere->GetDensity());
383 socket->Append(Translation->GetVt());
384 socket->Append(Translation->GetUVW(eU));
385 socket->Append(Translation->GetUVW(eV));
386 socket->Append(Translation->GetUVW(eW));
387 socket->Append(Translation->GetAeroUVW(eU));
388 socket->Append(Translation->GetAeroUVW(eV));
389 socket->Append(Translation->GetAeroUVW(eW));
390 socket->Append(Position->GetVn());
391 socket->Append(Position->GetVe());
392 socket->Append(Position->GetVd());
393 socket->Append(Translation->GetUVWdot(eU));
394 socket->Append(Translation->GetUVWdot(eV));
395 socket->Append(Translation->GetUVWdot(eW));
396 socket->Append(Rotation->GetPQR(eP));
397 socket->Append(Rotation->GetPQR(eQ));
398 socket->Append(Rotation->GetPQR(eR));
399 socket->Append(Rotation->GetPQRdot(eP));
400 socket->Append(Rotation->GetPQRdot(eQ));
401 socket->Append(Rotation->GetPQRdot(eR));
402 socket->Append(Aircraft->GetForces(eX));
403 socket->Append(Aircraft->GetForces(eY));
404 socket->Append(Aircraft->GetForces(eZ));
405 socket->Append(Position->GetLatitude());
406 socket->Append(Position->GetLongitude());
407 socket->Append(Translation->Getqbar());
408 socket->Append(Translation->Getalpha());
409 socket->Append(Aircraft->GetMoments(eL));
410 socket->Append(Aircraft->GetMoments(eM));
411 socket->Append(Aircraft->GetMoments(eN));
412 socket->Append(FCS->GetThrottlePos(0));
413 socket->Append(FCS->GetDaLPos());
414 socket->Append(FCS->GetDaRPos());
415 socket->Append(FCS->GetDePos());
416 socket->Append(FCS->GetDrPos());
420 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
422 void FGOutput::SocketStatusOutput(string out_str)
426 if (socket == NULL) return;
429 asciiData = string("<STATUS>") + out_str;
430 socket->Append(asciiData.c_str());
434 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
436 bool FGOutput::Load(FGConfigFile* AC_cfg)
438 string token, parameter;
441 token = AC_cfg->GetValue("NAME");
442 Output->SetFilename(token);
443 token = AC_cfg->GetValue("TYPE");
444 Output->SetType(token);
446 #if defined( FG_WITH_JSBSIM_SOCKET ) || !defined( FGFS )
447 if (token == "SOCKET") {
448 socket = new FGfdmSocket("localhost",1138);
452 AC_cfg->GetNextConfigLine();
454 while ((token = AC_cfg->GetValue()) != string("/OUTPUT")) {
455 *AC_cfg >> parameter;
456 if (parameter == "RATE_IN_HZ") *AC_cfg >> OutRate;
457 if (parameter == "SIMULATION") {
458 *AC_cfg >> parameter;
459 if (parameter == "ON") SubSystems += ssSimulation;
461 if (parameter == "AEROSURFACES") {
462 *AC_cfg >> parameter;
463 if (parameter == "ON") SubSystems += ssAerosurfaces;
465 if (parameter == "RATES") {
466 *AC_cfg >> parameter;
467 if (parameter == "ON") SubSystems += ssRates;
469 if (parameter == "VELOCITIES") {
470 *AC_cfg >> parameter;
471 if (parameter == "ON") SubSystems += ssVelocities;
473 if (parameter == "FORCES") {
474 *AC_cfg >> parameter;
475 if (parameter == "ON") SubSystems += ssForces;
477 if (parameter == "MOMENTS") {
478 *AC_cfg >> parameter;
479 if (parameter == "ON") SubSystems += ssMoments;
481 if (parameter == "ATMOSPHERE") {
482 *AC_cfg >> parameter;
483 if (parameter == "ON") SubSystems += ssAtmosphere;
485 if (parameter == "MASSPROPS") {
486 *AC_cfg >> parameter;
487 if (parameter == "ON") SubSystems += ssMassProps;
489 if (parameter == "POSITION") {
490 *AC_cfg >> parameter;
491 if (parameter == "ON") SubSystems += ssPosition;
493 if (parameter == "COEFFICIENTS") {
494 *AC_cfg >> parameter;
495 if (parameter == "ON") SubSystems += ssCoefficients;
497 if (parameter == "GROUND_REACTIONS") {
498 *AC_cfg >> parameter;
499 if (parameter == "ON") SubSystems += ssGroundReactions;
501 if (parameter == "FCS") {
502 *AC_cfg >> parameter;
503 if (parameter == "ON") SubSystems += ssFCS;
505 if (parameter == "PROPULSION") {
506 *AC_cfg >> parameter;
507 if (parameter == "ON") SubSystems += ssPropulsion;
511 OutRate = OutRate>120?120:(OutRate<0?0:OutRate);
512 rate = (int)(0.5 + 1.0/(State->Getdt()*OutRate));
517 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
518 // The bitmasked value choices are as follows:
519 // unset: In this case (the default) JSBSim would only print
520 // out the normally expected messages, essentially echoing
521 // the config files as they are read. If the environment
522 // variable is not set, debug_lvl is set to 1 internally
523 // 0: This requests JSBSim not to output any messages
525 // 1: This value explicity requests the normal JSBSim
527 // 2: This value asks for a message to be printed out when
528 // a class is instantiated
529 // 4: When this value is set, a message is displayed when a
530 // FGModel object executes its Run() method
531 // 8: When this value is set, various runtime state variables
532 // are printed out periodically
533 // 16: When set various parameters are sanity checked and
534 // a message is printed out when they go out of bounds
536 void FGOutput::Debug(int from)
538 if (debug_lvl <= 0) return;
540 if (debug_lvl & 1) { // Standard console startup message output
541 if (from == 0) { // Constructor
545 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
546 if (from == 0) cout << "Instantiated: FGOutput" << endl;
547 if (from == 1) cout << "Destroyed: FGOutput" << endl;
549 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
551 if (debug_lvl & 8 ) { // Runtime state variables
553 if (debug_lvl & 16) { // Sanity checking
555 if (debug_lvl & 64) {
556 if (from == 0) { // Constructor
557 cout << IdSrc << endl;
558 cout << IdHdr << endl;