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 << "Aileron Pos, ";
152 outstream << "Elevator Pos, ";
153 outstream << "Rudder Pos";
155 if (SubSystems & ssRates) {
157 outstream << "P, Q, R, ";
158 outstream << "Pdot, Qdot, Rdot";
160 if (SubSystems & ssVelocities) {
162 outstream << "QBar, ";
163 outstream << "Vtotal, ";
164 outstream << "UBody, VBody, WBody, ";
165 outstream << "UAero, VAero, WAero, ";
166 outstream << "Vn, Ve, Vd";
168 if (SubSystems & ssForces) {
170 outstream << "Drag, Side, Lift, ";
171 outstream << "L/D, ";
172 outstream << "Xforce, Yforce, Zforce";
174 if (SubSystems & ssMoments) {
176 outstream << "L, M, N";
178 if (SubSystems & ssAtmosphere) {
180 outstream << "Rho, ";
181 outstream << "NWind, EWind, DWind";
183 if (SubSystems & ssMassProps) {
185 outstream << "Ixx, ";
186 outstream << "Iyy, ";
187 outstream << "Izz, ";
188 outstream << "Ixz, ";
189 outstream << "Mass, ";
190 outstream << "Xcg, Ycg, Zcg";
192 if (SubSystems & ssPosition) {
194 outstream << "Altitude, ";
195 outstream << "Phi, Tht, Psi, ";
196 outstream << "Alpha, ";
197 outstream << "Beta, ";
198 outstream << "Latitude, ";
199 outstream << "Longitude, ";
200 outstream << "Distance AGL, ";
201 outstream << "Runway Radius";
203 if (SubSystems & ssCoefficients) {
205 outstream << Aerodynamics->GetCoefficientStrings();
207 if (SubSystems & ssGroundReactions) {
209 outstream << GroundReactions->GetGroundReactionStrings();
211 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
213 outstream << Propulsion->GetPropulsionStrings();
220 outstream << State->Getsim_time();
221 if (SubSystems & ssSimulation) {
223 if (SubSystems & ssAerosurfaces) {
225 outstream << FCS->GetDaCmd() << ", ";
226 outstream << FCS->GetDeCmd() << ", ";
227 outstream << FCS->GetDrCmd() << ", ";
228 outstream << FCS->GetDaPos() << ", ";
229 outstream << FCS->GetDePos() << ", ";
230 outstream << FCS->GetDrPos();
232 if (SubSystems & ssRates) {
234 outstream << Rotation->GetPQR() << ", ";
235 outstream << Rotation->GetPQRdot();
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() << ", ";
258 outstream << Atmosphere->GetWindNED();
260 if (SubSystems & ssMassProps) {
262 outstream << MassBalance->GetIxx() << ", ";
263 outstream << MassBalance->GetIyy() << ", ";
264 outstream << MassBalance->GetIzz() << ", ";
265 outstream << MassBalance->GetIxz() << ", ";
266 outstream << MassBalance->GetMass() << ", ";
267 outstream << MassBalance->GetXYZcg();
269 if (SubSystems & ssPosition) {
271 outstream << Position->Geth() << ", ";
272 outstream << Rotation->GetEuler() << ", ";
273 outstream << Translation->Getalpha() << ", ";
274 outstream << Translation->Getbeta() << ", ";
275 outstream << Position->GetLatitude() << ", ";
276 outstream << Position->GetLongitude() << ", ";
277 outstream << Position->GetDistanceAGL() << ", ";
278 outstream << Position->GetRunwayRadius();
280 if (SubSystems & ssCoefficients) {
282 outstream << Aerodynamics->GetCoefficientValues();
284 if (SubSystems & ssGroundReactions) {
286 outstream << GroundReactions->GetGroundReactionValues();
288 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
290 outstream << Propulsion->GetPropulsionValues();
297 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
299 void FGOutput::SocketOutput(void)
303 if (socket == NULL) return;
304 if (!socket->GetConnectStatus()) return;
308 socket->Append("<LABELS>");
309 socket->Append("Time");
310 socket->Append("Altitude");
311 socket->Append("Phi");
312 socket->Append("Tht");
313 socket->Append("Psi");
314 socket->Append("Rho");
315 socket->Append("Vtotal");
316 socket->Append("UBody");
317 socket->Append("VBody");
318 socket->Append("WBody");
319 socket->Append("UAero");
320 socket->Append("VAero");
321 socket->Append("WAero");
322 socket->Append("Vn");
323 socket->Append("Ve");
324 socket->Append("Vd");
325 socket->Append("Udot");
326 socket->Append("Vdot");
327 socket->Append("Wdot");
331 socket->Append("PDot");
332 socket->Append("QDot");
333 socket->Append("RDot");
334 socket->Append("Fx");
335 socket->Append("Fy");
336 socket->Append("Fz");
337 socket->Append("Latitude");
338 socket->Append("Longitude");
339 socket->Append("QBar");
340 socket->Append("Alpha");
344 socket->Append("Throttle Position");
345 socket->Append("Aileron Position");
346 socket->Append("Elevator Position");
347 socket->Append("Rudder Position");
353 socket->Append(State->Getsim_time());
354 socket->Append(Position->Geth());
355 socket->Append(Rotation->Getphi());
356 socket->Append(Rotation->Gettht());
357 socket->Append(Rotation->Getpsi());
358 socket->Append(Atmosphere->GetDensity());
359 socket->Append(Translation->GetVt());
360 socket->Append(Translation->GetUVW(eU));
361 socket->Append(Translation->GetUVW(eV));
362 socket->Append(Translation->GetUVW(eW));
363 socket->Append(Translation->GetvAeroUVW(eU));
364 socket->Append(Translation->GetvAeroUVW(eV));
365 socket->Append(Translation->GetvAeroUVW(eW));
366 socket->Append(Position->GetVn());
367 socket->Append(Position->GetVe());
368 socket->Append(Position->GetVd());
369 socket->Append(Translation->GetUVWdot(eU));
370 socket->Append(Translation->GetUVWdot(eV));
371 socket->Append(Translation->GetUVWdot(eW));
372 socket->Append(Rotation->GetPQR(eP));
373 socket->Append(Rotation->GetPQR(eQ));
374 socket->Append(Rotation->GetPQR(eR));
375 socket->Append(Rotation->GetPQRdot(eP));
376 socket->Append(Rotation->GetPQRdot(eQ));
377 socket->Append(Rotation->GetPQRdot(eR));
378 socket->Append(Aircraft->GetForces(eX));
379 socket->Append(Aircraft->GetForces(eY));
380 socket->Append(Aircraft->GetForces(eZ));
381 socket->Append(Position->GetLatitude());
382 socket->Append(Position->GetLongitude());
383 socket->Append(Translation->Getqbar());
384 socket->Append(Translation->Getalpha());
385 socket->Append(Aircraft->GetMoments(eL));
386 socket->Append(Aircraft->GetMoments(eM));
387 socket->Append(Aircraft->GetMoments(eN));
388 socket->Append(FCS->GetThrottlePos(0));
389 socket->Append(FCS->GetDaPos());
390 socket->Append(FCS->GetDePos());
391 socket->Append(FCS->GetDrPos());
395 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
397 void FGOutput::SocketStatusOutput(string out_str)
401 if (socket == NULL) return;
404 asciiData = string("<STATUS>") + out_str;
405 socket->Append(asciiData.c_str());
409 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411 bool FGOutput::Load(FGConfigFile* AC_cfg)
413 string token, parameter;
416 token = AC_cfg->GetValue("NAME");
417 Output->SetFilename(token);
418 token = AC_cfg->GetValue("TYPE");
419 Output->SetType(token);
421 #if defined( FG_WITH_JSBSIM_SOCKET ) || !defined( FGFS )
422 if (token == "SOCKET") {
423 socket = new FGfdmSocket("localhost",1138);
427 AC_cfg->GetNextConfigLine();
429 while ((token = AC_cfg->GetValue()) != string("/OUTPUT")) {
430 *AC_cfg >> parameter;
431 if (parameter == "RATE_IN_HZ") *AC_cfg >> OutRate;
432 if (parameter == "SIMULATION") {
433 *AC_cfg >> parameter;
434 if (parameter == "ON") SubSystems += ssSimulation;
436 if (parameter == "AEROSURFACES") {
437 *AC_cfg >> parameter;
438 if (parameter == "ON") SubSystems += ssAerosurfaces;
440 if (parameter == "RATES") {
441 *AC_cfg >> parameter;
442 if (parameter == "ON") SubSystems += ssRates;
444 if (parameter == "VELOCITIES") {
445 *AC_cfg >> parameter;
446 if (parameter == "ON") SubSystems += ssVelocities;
448 if (parameter == "FORCES") {
449 *AC_cfg >> parameter;
450 if (parameter == "ON") SubSystems += ssForces;
452 if (parameter == "MOMENTS") {
453 *AC_cfg >> parameter;
454 if (parameter == "ON") SubSystems += ssMoments;
456 if (parameter == "ATMOSPHERE") {
457 *AC_cfg >> parameter;
458 if (parameter == "ON") SubSystems += ssAtmosphere;
460 if (parameter == "MASSPROPS") {
461 *AC_cfg >> parameter;
462 if (parameter == "ON") SubSystems += ssMassProps;
464 if (parameter == "POSITION") {
465 *AC_cfg >> parameter;
466 if (parameter == "ON") SubSystems += ssPosition;
468 if (parameter == "COEFFICIENTS") {
469 *AC_cfg >> parameter;
470 if (parameter == "ON") SubSystems += ssCoefficients;
472 if (parameter == "GROUND_REACTIONS") {
473 *AC_cfg >> parameter;
474 if (parameter == "ON") SubSystems += ssGroundReactions;
476 if (parameter == "FCS") {
477 *AC_cfg >> parameter;
478 if (parameter == "ON") SubSystems += ssFCS;
480 if (parameter == "PROPULSION") {
481 *AC_cfg >> parameter;
482 if (parameter == "ON") SubSystems += ssPropulsion;
486 OutRate = OutRate>120?120:(OutRate<0?0:OutRate);
487 rate = (int)(0.5 + 1.0/(State->Getdt()*OutRate));
492 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
493 // The bitmasked value choices are as follows:
494 // unset: In this case (the default) JSBSim would only print
495 // out the normally expected messages, essentially echoing
496 // the config files as they are read. If the environment
497 // variable is not set, debug_lvl is set to 1 internally
498 // 0: This requests JSBSim not to output any messages
500 // 1: This value explicity requests the normal JSBSim
502 // 2: This value asks for a message to be printed out when
503 // a class is instantiated
504 // 4: When this value is set, a message is displayed when a
505 // FGModel object executes its Run() method
506 // 8: When this value is set, various runtime state variables
507 // are printed out periodically
508 // 16: When set various parameters are sanity checked and
509 // a message is printed out when they go out of bounds
511 void FGOutput::Debug(int from)
513 if (debug_lvl <= 0) return;
515 if (debug_lvl & 1) { // Standard console startup message output
516 if (from == 0) { // Constructor
520 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
521 if (from == 0) cout << "Instantiated: FGOutput" << endl;
522 if (from == 1) cout << "Destroyed: FGOutput" << endl;
524 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
526 if (debug_lvl & 8 ) { // Runtime state variables
528 if (debug_lvl & 16) { // Sanity checking
530 if (debug_lvl & 64) {
531 if (from == 0) { // Constructor
532 cout << IdSrc << endl;
533 cout << IdHdr << endl;