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, ";
161 outstream << "Pdot, Qdot, Rdot";
163 if (SubSystems & ssVelocities) {
165 outstream << "QBar, ";
166 outstream << "Vtotal, ";
167 outstream << "UBody, VBody, WBody, ";
168 outstream << "UAero, VAero, WAero, ";
169 outstream << "Vn, Ve, Vd";
171 if (SubSystems & ssForces) {
173 outstream << "Drag, Side, Lift, ";
174 outstream << "L/D, ";
175 outstream << "Xforce, Yforce, Zforce";
177 if (SubSystems & ssMoments) {
179 outstream << "L, M, N";
181 if (SubSystems & ssAtmosphere) {
183 outstream << "Rho, ";
184 outstream << "NWind, EWind, DWind";
186 if (SubSystems & ssMassProps) {
188 outstream << "Ixx, ";
189 outstream << "Iyy, ";
190 outstream << "Izz, ";
191 outstream << "Ixz, ";
192 outstream << "Mass, ";
193 outstream << "Xcg, Ycg, Zcg";
195 if (SubSystems & ssPosition) {
197 outstream << "Altitude, ";
198 outstream << "Phi, Tht, Psi, ";
199 outstream << "Alpha, ";
200 outstream << "Beta, ";
201 outstream << "Latitude, ";
202 outstream << "Longitude, ";
203 outstream << "Distance AGL, ";
204 outstream << "Runway Radius";
206 if (SubSystems & ssCoefficients) {
208 outstream << Aerodynamics->GetCoefficientStrings();
210 if (SubSystems & ssGroundReactions) {
212 outstream << GroundReactions->GetGroundReactionStrings();
214 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
216 outstream << Propulsion->GetPropulsionStrings();
223 outstream << State->Getsim_time();
224 if (SubSystems & ssSimulation) {
226 if (SubSystems & ssAerosurfaces) {
228 outstream << FCS->GetDaCmd() << ", ";
229 outstream << FCS->GetDeCmd() << ", ";
230 outstream << FCS->GetDrCmd() << ", ";
231 outstream << FCS->GetDaPos() << ", ";
232 outstream << FCS->GetDePos() << ", ";
233 outstream << FCS->GetDrPos();
235 if (SubSystems & ssRates) {
237 outstream << Rotation->GetPQR() << ", ";
238 outstream << Rotation->GetPQRdot();
240 if (SubSystems & ssVelocities) {
242 outstream << Translation->Getqbar() << ", ";
243 outstream << Translation->GetVt() << ", ";
244 outstream << Translation->GetUVW() << ", ";
245 outstream << Translation->GetvAeroUVW() << ", ";
246 outstream << Position->GetVel();
248 if (SubSystems & ssForces) {
250 outstream << Aerodynamics->GetvFs() << ", ";
251 outstream << Aerodynamics->GetLoD() << ", ";
252 outstream << Aircraft->GetForces();
254 if (SubSystems & ssMoments) {
256 outstream << Aircraft->GetMoments();
258 if (SubSystems & ssAtmosphere) {
260 outstream << Atmosphere->GetDensity() << ", ";
261 outstream << Atmosphere->GetWindNED();
263 if (SubSystems & ssMassProps) {
265 outstream << MassBalance->GetIxx() << ", ";
266 outstream << MassBalance->GetIyy() << ", ";
267 outstream << MassBalance->GetIzz() << ", ";
268 outstream << MassBalance->GetIxz() << ", ";
269 outstream << MassBalance->GetMass() << ", ";
270 outstream << MassBalance->GetXYZcg();
272 if (SubSystems & ssPosition) {
274 outstream << Position->Geth() << ", ";
275 outstream << Rotation->GetEuler() << ", ";
276 outstream << Translation->Getalpha() << ", ";
277 outstream << Translation->Getbeta() << ", ";
278 outstream << Position->GetLatitude() << ", ";
279 outstream << Position->GetLongitude() << ", ";
280 outstream << Position->GetDistanceAGL() << ", ";
281 outstream << Position->GetRunwayRadius();
283 if (SubSystems & ssCoefficients) {
285 outstream << Aerodynamics->GetCoefficientValues();
287 if (SubSystems & ssGroundReactions) {
289 outstream << GroundReactions->GetGroundReactionValues();
291 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
293 outstream << Propulsion->GetPropulsionValues();
300 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
302 void FGOutput::SocketOutput(void)
306 if (socket == NULL) return;
310 socket->Append("<LABELS>");
311 socket->Append("Time");
312 socket->Append("Altitude");
313 socket->Append("Phi");
314 socket->Append("Tht");
315 socket->Append("Psi");
316 socket->Append("Rho");
317 socket->Append("Vtotal");
318 socket->Append("UBody");
319 socket->Append("VBody");
320 socket->Append("WBody");
321 socket->Append("UAero");
322 socket->Append("VAero");
323 socket->Append("WAero");
324 socket->Append("Vn");
325 socket->Append("Ve");
326 socket->Append("Vd");
327 socket->Append("Udot");
328 socket->Append("Vdot");
329 socket->Append("Wdot");
333 socket->Append("PDot");
334 socket->Append("QDot");
335 socket->Append("RDot");
336 socket->Append("Fx");
337 socket->Append("Fy");
338 socket->Append("Fz");
339 socket->Append("Latitude");
340 socket->Append("Longitude");
341 socket->Append("QBar");
342 socket->Append("Alpha");
346 socket->Append("Throttle");
347 socket->Append("Aileron");
348 socket->Append("Elevator");
349 socket->Append("Rudder");
355 socket->Append(State->Getsim_time());
356 socket->Append(Position->Geth());
357 socket->Append(Rotation->Getphi());
358 socket->Append(Rotation->Gettht());
359 socket->Append(Rotation->Getpsi());
360 socket->Append(Atmosphere->GetDensity());
361 socket->Append(Translation->GetVt());
362 socket->Append(Translation->GetUVW(eU));
363 socket->Append(Translation->GetUVW(eV));
364 socket->Append(Translation->GetUVW(eW));
365 socket->Append(Translation->GetvAeroUVW(eU));
366 socket->Append(Translation->GetvAeroUVW(eV));
367 socket->Append(Translation->GetvAeroUVW(eW));
368 socket->Append(Position->GetVn());
369 socket->Append(Position->GetVe());
370 socket->Append(Position->GetVd());
371 socket->Append(Translation->GetUdot());
372 socket->Append(Translation->GetVdot());
373 socket->Append(Translation->GetWdot());
374 socket->Append(Rotation->GetP());
375 socket->Append(Rotation->GetQ());
376 socket->Append(Rotation->GetR());
377 socket->Append(Rotation->GetPdot());
378 socket->Append(Rotation->GetQdot());
379 socket->Append(Rotation->GetRdot());
380 socket->Append(Aircraft->GetFx());
381 socket->Append(Aircraft->GetFy());
382 socket->Append(Aircraft->GetFz());
383 socket->Append(Position->GetLatitude());
384 socket->Append(Position->GetLongitude());
385 socket->Append(Translation->Getqbar());
386 socket->Append(Translation->Getalpha());
387 socket->Append(Aircraft->GetL());
388 socket->Append(Aircraft->GetM());
389 socket->Append(Aircraft->GetN());
390 socket->Append(FCS->GetThrottle(0));
391 socket->Append(FCS->GetDa());
392 socket->Append(FCS->GetDe());
393 socket->Append(FCS->GetDr());
397 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
399 void FGOutput::SocketStatusOutput(string out_str)
403 if (socket == NULL) return;
406 asciiData = string("<STATUS>") + out_str;
407 socket->Append(asciiData.c_str());
411 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
413 bool FGOutput::Load(FGConfigFile* AC_cfg)
415 string token, parameter;
418 token = AC_cfg->GetValue("NAME");
419 Output->SetFilename(token);
420 token = AC_cfg->GetValue("TYPE");
421 Output->SetType(token);
422 AC_cfg->GetNextConfigLine();
424 while ((token = AC_cfg->GetValue()) != string("/OUTPUT")) {
425 *AC_cfg >> parameter;
426 if (parameter == "RATE_IN_HZ") *AC_cfg >> OutRate;
427 if (parameter == "SIMULATION") {
428 *AC_cfg >> parameter;
429 if (parameter == "ON") SubSystems += ssSimulation;
431 if (parameter == "AEROSURFACES") {
432 *AC_cfg >> parameter;
433 if (parameter == "ON") SubSystems += ssAerosurfaces;
435 if (parameter == "RATES") {
436 *AC_cfg >> parameter;
437 if (parameter == "ON") SubSystems += ssRates;
439 if (parameter == "VELOCITIES") {
440 *AC_cfg >> parameter;
441 if (parameter == "ON") SubSystems += ssVelocities;
443 if (parameter == "FORCES") {
444 *AC_cfg >> parameter;
445 if (parameter == "ON") SubSystems += ssForces;
447 if (parameter == "MOMENTS") {
448 *AC_cfg >> parameter;
449 if (parameter == "ON") SubSystems += ssMoments;
451 if (parameter == "ATMOSPHERE") {
452 *AC_cfg >> parameter;
453 if (parameter == "ON") SubSystems += ssAtmosphere;
455 if (parameter == "MASSPROPS") {
456 *AC_cfg >> parameter;
457 if (parameter == "ON") SubSystems += ssMassProps;
459 if (parameter == "POSITION") {
460 *AC_cfg >> parameter;
461 if (parameter == "ON") SubSystems += ssPosition;
463 if (parameter == "COEFFICIENTS") {
464 *AC_cfg >> parameter;
465 if (parameter == "ON") SubSystems += ssCoefficients;
467 if (parameter == "GROUND_REACTIONS") {
468 *AC_cfg >> parameter;
469 if (parameter == "ON") SubSystems += ssGroundReactions;
471 if (parameter == "FCS") {
472 *AC_cfg >> parameter;
473 if (parameter == "ON") SubSystems += ssFCS;
475 if (parameter == "PROPULSION") {
476 *AC_cfg >> parameter;
477 if (parameter == "ON") SubSystems += ssPropulsion;
481 OutRate = OutRate>120?120:(OutRate<0?0:OutRate);
482 rate = (int)(0.5 + 1.0/(State->Getdt()*OutRate));
487 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
488 // The bitmasked value choices are as follows:
489 // unset: In this case (the default) JSBSim would only print
490 // out the normally expected messages, essentially echoing
491 // the config files as they are read. If the environment
492 // variable is not set, debug_lvl is set to 1 internally
493 // 0: This requests JSBSim not to output any messages
495 // 1: This value explicity requests the normal JSBSim
497 // 2: This value asks for a message to be printed out when
498 // a class is instantiated
499 // 4: When this value is set, a message is displayed when a
500 // FGModel object executes its Run() method
501 // 8: When this value is set, various runtime state variables
502 // are printed out periodically
503 // 16: When set various parameters are sanity checked and
504 // a message is printed out when they go out of bounds
506 void FGOutput::Debug(int from)
508 if (debug_lvl <= 0) return;
510 if (debug_lvl & 1) { // Standard console startup message output
511 if (from == 0) { // Constructor
515 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
516 if (from == 0) cout << "Instantiated: FGOutput" << endl;
517 if (from == 1) cout << "Destroyed: FGOutput" << endl;
519 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
521 if (debug_lvl & 8 ) { // Runtime state variables
523 if (debug_lvl & 16) { // Sanity checking