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 << "Flap Cmd, ";
152 outstream << "Left Aileron Pos, ";
153 outstream << "Right Aileron Pos, ";
154 outstream << "Elevator Pos, ";
155 outstream << "Rudder Pos, ";
156 outstream << "Flap 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->GetDfCmd() << ", ";
232 outstream << FCS->GetDaLPos() << ", ";
233 outstream << FCS->GetDaRPos() << ", ";
234 outstream << FCS->GetDePos() << ", ";
235 outstream << FCS->GetDrPos() << ", ";
236 outstream << FCS->GetDfPos();
238 if (SubSystems & ssRates) {
240 outstream << Rotation->GetPQR() << ", ";
241 outstream << Rotation->GetPQRdot();
243 if (SubSystems & ssVelocities) {
245 outstream << Translation->Getqbar() << ", ";
246 outstream << Translation->GetVt() << ", ";
247 outstream << Translation->GetUVW() << ", ";
248 outstream << Translation->GetAeroUVW() << ", ";
249 outstream << Position->GetVel();
251 if (SubSystems & ssForces) {
253 outstream << Aerodynamics->GetvFs() << ", ";
254 outstream << Aerodynamics->GetLoD() << ", ";
255 outstream << Aircraft->GetForces();
257 if (SubSystems & ssMoments) {
259 outstream << Aircraft->GetMoments();
261 if (SubSystems & ssAtmosphere) {
263 outstream << Atmosphere->GetDensity() << ", ";
264 outstream << Atmosphere->GetWindNED();
266 if (SubSystems & ssMassProps) {
268 outstream << MassBalance->GetIxx() << ", ";
269 outstream << MassBalance->GetIyy() << ", ";
270 outstream << MassBalance->GetIzz() << ", ";
271 outstream << MassBalance->GetIxz() << ", ";
272 outstream << MassBalance->GetMass() << ", ";
273 outstream << MassBalance->GetXYZcg();
275 if (SubSystems & ssPosition) {
277 outstream << Position->Geth() << ", ";
278 outstream << Rotation->GetEuler() << ", ";
279 outstream << Translation->Getalpha() << ", ";
280 outstream << Translation->Getbeta() << ", ";
281 outstream << Position->GetLatitude() << ", ";
282 outstream << Position->GetLongitude() << ", ";
283 outstream << Position->GetDistanceAGL() << ", ";
284 outstream << Position->GetRunwayRadius();
286 if (SubSystems & ssCoefficients) {
288 outstream << Aerodynamics->GetCoefficientValues();
290 if (SubSystems & ssGroundReactions) {
292 outstream << GroundReactions->GetGroundReactionValues();
294 if (SubSystems & ssPropulsion && Propulsion->GetNumEngines() > 0) {
296 outstream << Propulsion->GetPropulsionValues();
303 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305 void FGOutput::SocketOutput(void)
309 if (socket == NULL) return;
310 if (!socket->GetConnectStatus()) return;
314 socket->Append("<LABELS>");
315 socket->Append("Time");
316 socket->Append("Altitude");
317 socket->Append("Phi");
318 socket->Append("Tht");
319 socket->Append("Psi");
320 socket->Append("Rho");
321 socket->Append("Vtotal");
322 socket->Append("UBody");
323 socket->Append("VBody");
324 socket->Append("WBody");
325 socket->Append("UAero");
326 socket->Append("VAero");
327 socket->Append("WAero");
328 socket->Append("Vn");
329 socket->Append("Ve");
330 socket->Append("Vd");
331 socket->Append("Udot");
332 socket->Append("Vdot");
333 socket->Append("Wdot");
337 socket->Append("PDot");
338 socket->Append("QDot");
339 socket->Append("RDot");
340 socket->Append("Fx");
341 socket->Append("Fy");
342 socket->Append("Fz");
343 socket->Append("Latitude");
344 socket->Append("Longitude");
345 socket->Append("QBar");
346 socket->Append("Alpha");
350 socket->Append("Throttle Position");
351 socket->Append("Left Aileron Position");
352 socket->Append("Right Aileron Position");
353 socket->Append("Elevator Position");
354 socket->Append("Rudder Position");
360 socket->Append(State->Getsim_time());
361 socket->Append(Position->Geth());
362 socket->Append(Rotation->Getphi());
363 socket->Append(Rotation->Gettht());
364 socket->Append(Rotation->Getpsi());
365 socket->Append(Atmosphere->GetDensity());
366 socket->Append(Translation->GetVt());
367 socket->Append(Translation->GetUVW(eU));
368 socket->Append(Translation->GetUVW(eV));
369 socket->Append(Translation->GetUVW(eW));
370 socket->Append(Translation->GetAeroUVW(eU));
371 socket->Append(Translation->GetAeroUVW(eV));
372 socket->Append(Translation->GetAeroUVW(eW));
373 socket->Append(Position->GetVn());
374 socket->Append(Position->GetVe());
375 socket->Append(Position->GetVd());
376 socket->Append(Translation->GetUVWdot(eU));
377 socket->Append(Translation->GetUVWdot(eV));
378 socket->Append(Translation->GetUVWdot(eW));
379 socket->Append(Rotation->GetPQR(eP));
380 socket->Append(Rotation->GetPQR(eQ));
381 socket->Append(Rotation->GetPQR(eR));
382 socket->Append(Rotation->GetPQRdot(eP));
383 socket->Append(Rotation->GetPQRdot(eQ));
384 socket->Append(Rotation->GetPQRdot(eR));
385 socket->Append(Aircraft->GetForces(eX));
386 socket->Append(Aircraft->GetForces(eY));
387 socket->Append(Aircraft->GetForces(eZ));
388 socket->Append(Position->GetLatitude());
389 socket->Append(Position->GetLongitude());
390 socket->Append(Translation->Getqbar());
391 socket->Append(Translation->Getalpha());
392 socket->Append(Aircraft->GetMoments(eL));
393 socket->Append(Aircraft->GetMoments(eM));
394 socket->Append(Aircraft->GetMoments(eN));
395 socket->Append(FCS->GetThrottlePos(0));
396 socket->Append(FCS->GetDaLPos());
397 socket->Append(FCS->GetDaRPos());
398 socket->Append(FCS->GetDePos());
399 socket->Append(FCS->GetDrPos());
403 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
405 void FGOutput::SocketStatusOutput(string out_str)
409 if (socket == NULL) return;
412 asciiData = string("<STATUS>") + out_str;
413 socket->Append(asciiData.c_str());
417 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
419 bool FGOutput::Load(FGConfigFile* AC_cfg)
421 string token, parameter;
424 token = AC_cfg->GetValue("NAME");
425 Output->SetFilename(token);
426 token = AC_cfg->GetValue("TYPE");
427 Output->SetType(token);
429 #if defined( FG_WITH_JSBSIM_SOCKET ) || !defined( FGFS )
430 if (token == "SOCKET") {
431 socket = new FGfdmSocket("localhost",1138);
435 AC_cfg->GetNextConfigLine();
437 while ((token = AC_cfg->GetValue()) != string("/OUTPUT")) {
438 *AC_cfg >> parameter;
439 if (parameter == "RATE_IN_HZ") *AC_cfg >> OutRate;
440 if (parameter == "SIMULATION") {
441 *AC_cfg >> parameter;
442 if (parameter == "ON") SubSystems += ssSimulation;
444 if (parameter == "AEROSURFACES") {
445 *AC_cfg >> parameter;
446 if (parameter == "ON") SubSystems += ssAerosurfaces;
448 if (parameter == "RATES") {
449 *AC_cfg >> parameter;
450 if (parameter == "ON") SubSystems += ssRates;
452 if (parameter == "VELOCITIES") {
453 *AC_cfg >> parameter;
454 if (parameter == "ON") SubSystems += ssVelocities;
456 if (parameter == "FORCES") {
457 *AC_cfg >> parameter;
458 if (parameter == "ON") SubSystems += ssForces;
460 if (parameter == "MOMENTS") {
461 *AC_cfg >> parameter;
462 if (parameter == "ON") SubSystems += ssMoments;
464 if (parameter == "ATMOSPHERE") {
465 *AC_cfg >> parameter;
466 if (parameter == "ON") SubSystems += ssAtmosphere;
468 if (parameter == "MASSPROPS") {
469 *AC_cfg >> parameter;
470 if (parameter == "ON") SubSystems += ssMassProps;
472 if (parameter == "POSITION") {
473 *AC_cfg >> parameter;
474 if (parameter == "ON") SubSystems += ssPosition;
476 if (parameter == "COEFFICIENTS") {
477 *AC_cfg >> parameter;
478 if (parameter == "ON") SubSystems += ssCoefficients;
480 if (parameter == "GROUND_REACTIONS") {
481 *AC_cfg >> parameter;
482 if (parameter == "ON") SubSystems += ssGroundReactions;
484 if (parameter == "FCS") {
485 *AC_cfg >> parameter;
486 if (parameter == "ON") SubSystems += ssFCS;
488 if (parameter == "PROPULSION") {
489 *AC_cfg >> parameter;
490 if (parameter == "ON") SubSystems += ssPropulsion;
494 OutRate = OutRate>120?120:(OutRate<0?0:OutRate);
495 rate = (int)(0.5 + 1.0/(State->Getdt()*OutRate));
500 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
501 // The bitmasked value choices are as follows:
502 // unset: In this case (the default) JSBSim would only print
503 // out the normally expected messages, essentially echoing
504 // the config files as they are read. If the environment
505 // variable is not set, debug_lvl is set to 1 internally
506 // 0: This requests JSBSim not to output any messages
508 // 1: This value explicity requests the normal JSBSim
510 // 2: This value asks for a message to be printed out when
511 // a class is instantiated
512 // 4: When this value is set, a message is displayed when a
513 // FGModel object executes its Run() method
514 // 8: When this value is set, various runtime state variables
515 // are printed out periodically
516 // 16: When set various parameters are sanity checked and
517 // a message is printed out when they go out of bounds
519 void FGOutput::Debug(int from)
521 if (debug_lvl <= 0) return;
523 if (debug_lvl & 1) { // Standard console startup message output
524 if (from == 0) { // Constructor
528 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
529 if (from == 0) cout << "Instantiated: FGOutput" << endl;
530 if (from == 1) cout << "Destroyed: FGOutput" << endl;
532 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
534 if (debug_lvl & 8 ) { // Runtime state variables
536 if (debug_lvl & 16) { // Sanity checking
538 if (debug_lvl & 64) {
539 if (from == 0) { // Constructor
540 cout << IdSrc << endl;
541 cout << IdHdr << endl;