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 & ssFCS) {
216 outstream << FCS->GetComponentStrings();
218 if (SubSystems & ssGroundReactions) {
220 outstream << GroundReactions->GetGroundReactionStrings();
222 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
224 outstream << Propulsion->GetPropulsionStrings();
231 outstream << State->Getsim_time();
232 if (SubSystems & ssSimulation) {
234 if (SubSystems & ssAerosurfaces) {
236 outstream << FCS->GetDaCmd() << ", ";
237 outstream << FCS->GetDeCmd() << ", ";
238 outstream << FCS->GetDrCmd() << ", ";
239 outstream << FCS->GetDfCmd() << ", ";
240 outstream << FCS->GetDaLPos() << ", ";
241 outstream << FCS->GetDaRPos() << ", ";
242 outstream << FCS->GetDePos() << ", ";
243 outstream << FCS->GetDrPos() << ", ";
244 outstream << FCS->GetDfPos();
246 if (SubSystems & ssRates) {
248 outstream << Rotation->GetPQR() << ", ";
249 outstream << Rotation->GetPQRdot();
251 if (SubSystems & ssVelocities) {
253 outstream << Translation->Getqbar() << ", ";
254 outstream << Translation->GetVt() << ", ";
255 outstream << Translation->GetUVW() << ", ";
256 outstream << Translation->GetAeroUVW() << ", ";
257 outstream << Position->GetVel();
259 if (SubSystems & ssForces) {
261 outstream << Aerodynamics->GetvFs() << ", ";
262 outstream << Aerodynamics->GetLoD() << ", ";
263 outstream << Aircraft->GetForces() << ", ";
264 outstream << Inertial->GetGravity() << ", ";
265 outstream << Inertial->GetCoriolis() << ", ";
266 outstream << Inertial->GetCentrifugal();
268 if (SubSystems & ssMoments) {
270 outstream << Aircraft->GetMoments();
272 if (SubSystems & ssAtmosphere) {
274 outstream << Atmosphere->GetDensity() << ", ";
275 outstream << Atmosphere->GetWindNED();
277 if (SubSystems & ssMassProps) {
279 outstream << MassBalance->GetIxx() << ", ";
280 outstream << MassBalance->GetIyy() << ", ";
281 outstream << MassBalance->GetIzz() << ", ";
282 outstream << MassBalance->GetIxz() << ", ";
283 outstream << MassBalance->GetMass() << ", ";
284 outstream << MassBalance->GetXYZcg();
286 if (SubSystems & ssPosition) {
288 outstream << Position->Geth() << ", ";
289 outstream << Rotation->GetEuler() << ", ";
290 outstream << Translation->Getalpha() << ", ";
291 outstream << Translation->Getbeta() << ", ";
292 outstream << Position->GetLatitude() << ", ";
293 outstream << Position->GetLongitude() << ", ";
294 outstream << Position->GetDistanceAGL() << ", ";
295 outstream << Position->GetRunwayRadius();
297 if (SubSystems & ssCoefficients) {
299 outstream << Aerodynamics->GetCoefficientValues();
301 if (SubSystems & ssFCS) {
303 outstream << FCS->GetComponentValues();
305 if (SubSystems & ssGroundReactions) {
307 outstream << GroundReactions->GetGroundReactionValues();
309 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
311 outstream << Propulsion->GetPropulsionValues();
318 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
320 void FGOutput::SocketOutput(void)
324 if (socket == NULL) return;
325 if (!socket->GetConnectStatus()) return;
329 socket->Append("<LABELS>");
330 socket->Append("Time");
331 socket->Append("Altitude");
332 socket->Append("Phi");
333 socket->Append("Tht");
334 socket->Append("Psi");
335 socket->Append("Rho");
336 socket->Append("Vtotal");
337 socket->Append("UBody");
338 socket->Append("VBody");
339 socket->Append("WBody");
340 socket->Append("UAero");
341 socket->Append("VAero");
342 socket->Append("WAero");
343 socket->Append("Vn");
344 socket->Append("Ve");
345 socket->Append("Vd");
346 socket->Append("Udot");
347 socket->Append("Vdot");
348 socket->Append("Wdot");
352 socket->Append("PDot");
353 socket->Append("QDot");
354 socket->Append("RDot");
355 socket->Append("Fx");
356 socket->Append("Fy");
357 socket->Append("Fz");
358 socket->Append("Latitude");
359 socket->Append("Longitude");
360 socket->Append("QBar");
361 socket->Append("Alpha");
365 socket->Append("Throttle Position");
366 socket->Append("Left Aileron Position");
367 socket->Append("Right Aileron Position");
368 socket->Append("Elevator Position");
369 socket->Append("Rudder Position");
375 socket->Append(State->Getsim_time());
376 socket->Append(Position->Geth());
377 socket->Append(Rotation->Getphi());
378 socket->Append(Rotation->Gettht());
379 socket->Append(Rotation->Getpsi());
380 socket->Append(Atmosphere->GetDensity());
381 socket->Append(Translation->GetVt());
382 socket->Append(Translation->GetUVW(eU));
383 socket->Append(Translation->GetUVW(eV));
384 socket->Append(Translation->GetUVW(eW));
385 socket->Append(Translation->GetAeroUVW(eU));
386 socket->Append(Translation->GetAeroUVW(eV));
387 socket->Append(Translation->GetAeroUVW(eW));
388 socket->Append(Position->GetVn());
389 socket->Append(Position->GetVe());
390 socket->Append(Position->GetVd());
391 socket->Append(Translation->GetUVWdot(eU));
392 socket->Append(Translation->GetUVWdot(eV));
393 socket->Append(Translation->GetUVWdot(eW));
394 socket->Append(Rotation->GetPQR(eP));
395 socket->Append(Rotation->GetPQR(eQ));
396 socket->Append(Rotation->GetPQR(eR));
397 socket->Append(Rotation->GetPQRdot(eP));
398 socket->Append(Rotation->GetPQRdot(eQ));
399 socket->Append(Rotation->GetPQRdot(eR));
400 socket->Append(Aircraft->GetForces(eX));
401 socket->Append(Aircraft->GetForces(eY));
402 socket->Append(Aircraft->GetForces(eZ));
403 socket->Append(Position->GetLatitude());
404 socket->Append(Position->GetLongitude());
405 socket->Append(Translation->Getqbar());
406 socket->Append(Translation->Getalpha());
407 socket->Append(Aircraft->GetMoments(eL));
408 socket->Append(Aircraft->GetMoments(eM));
409 socket->Append(Aircraft->GetMoments(eN));
410 socket->Append(FCS->GetThrottlePos(0));
411 socket->Append(FCS->GetDaLPos());
412 socket->Append(FCS->GetDaRPos());
413 socket->Append(FCS->GetDePos());
414 socket->Append(FCS->GetDrPos());
418 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
420 void FGOutput::SocketStatusOutput(string out_str)
424 if (socket == NULL) return;
427 asciiData = string("<STATUS>") + out_str;
428 socket->Append(asciiData.c_str());
432 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
434 bool FGOutput::Load(FGConfigFile* AC_cfg)
436 string token, parameter;
439 token = AC_cfg->GetValue("NAME");
440 Output->SetFilename(token);
441 token = AC_cfg->GetValue("TYPE");
442 Output->SetType(token);
444 #if defined( FG_WITH_JSBSIM_SOCKET ) || !defined( FGFS )
445 if (token == "SOCKET") {
446 socket = new FGfdmSocket("localhost",1138);
450 AC_cfg->GetNextConfigLine();
452 while ((token = AC_cfg->GetValue()) != string("/OUTPUT")) {
453 *AC_cfg >> parameter;
454 if (parameter == "RATE_IN_HZ") *AC_cfg >> OutRate;
455 if (parameter == "SIMULATION") {
456 *AC_cfg >> parameter;
457 if (parameter == "ON") SubSystems += ssSimulation;
459 if (parameter == "AEROSURFACES") {
460 *AC_cfg >> parameter;
461 if (parameter == "ON") SubSystems += ssAerosurfaces;
463 if (parameter == "RATES") {
464 *AC_cfg >> parameter;
465 if (parameter == "ON") SubSystems += ssRates;
467 if (parameter == "VELOCITIES") {
468 *AC_cfg >> parameter;
469 if (parameter == "ON") SubSystems += ssVelocities;
471 if (parameter == "FORCES") {
472 *AC_cfg >> parameter;
473 if (parameter == "ON") SubSystems += ssForces;
475 if (parameter == "MOMENTS") {
476 *AC_cfg >> parameter;
477 if (parameter == "ON") SubSystems += ssMoments;
479 if (parameter == "ATMOSPHERE") {
480 *AC_cfg >> parameter;
481 if (parameter == "ON") SubSystems += ssAtmosphere;
483 if (parameter == "MASSPROPS") {
484 *AC_cfg >> parameter;
485 if (parameter == "ON") SubSystems += ssMassProps;
487 if (parameter == "POSITION") {
488 *AC_cfg >> parameter;
489 if (parameter == "ON") SubSystems += ssPosition;
491 if (parameter == "COEFFICIENTS") {
492 *AC_cfg >> parameter;
493 if (parameter == "ON") SubSystems += ssCoefficients;
495 if (parameter == "GROUND_REACTIONS") {
496 *AC_cfg >> parameter;
497 if (parameter == "ON") SubSystems += ssGroundReactions;
499 if (parameter == "FCS") {
500 *AC_cfg >> parameter;
501 if (parameter == "ON") SubSystems += ssFCS;
503 if (parameter == "PROPULSION") {
504 *AC_cfg >> parameter;
505 if (parameter == "ON") SubSystems += ssPropulsion;
509 OutRate = OutRate>120?120:(OutRate<0?0:OutRate);
510 rate = (int)(0.5 + 1.0/(State->Getdt()*OutRate));
515 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
516 // The bitmasked value choices are as follows:
517 // unset: In this case (the default) JSBSim would only print
518 // out the normally expected messages, essentially echoing
519 // the config files as they are read. If the environment
520 // variable is not set, debug_lvl is set to 1 internally
521 // 0: This requests JSBSim not to output any messages
523 // 1: This value explicity requests the normal JSBSim
525 // 2: This value asks for a message to be printed out when
526 // a class is instantiated
527 // 4: When this value is set, a message is displayed when a
528 // FGModel object executes its Run() method
529 // 8: When this value is set, various runtime state variables
530 // are printed out periodically
531 // 16: When set various parameters are sanity checked and
532 // a message is printed out when they go out of bounds
534 void FGOutput::Debug(int from)
536 if (debug_lvl <= 0) return;
538 if (debug_lvl & 1) { // Standard console startup message output
539 if (from == 0) { // Constructor
543 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
544 if (from == 0) cout << "Instantiated: FGOutput" << endl;
545 if (from == 1) cout << "Destroyed: FGOutput" << endl;
547 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
549 if (debug_lvl & 8 ) { // Runtime state variables
551 if (debug_lvl & 16) { // Sanity checking
553 if (debug_lvl & 64) {
554 if (from == 0) { // Constructor
555 cout << IdSrc << endl;
556 cout << IdHdr << endl;