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);
75 if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
78 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 if (socket) delete socket;
83 if (debug_lvl & 2) cout << "Destroyed: FGOutput" << endl;
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";
162 if (SubSystems & ssVelocities) {
164 outstream << "QBar, ";
165 outstream << "Vtotal, ";
166 outstream << "UBody, VBody, WBody, ";
167 outstream << "UAero, VAero, WAero, ";
168 outstream << "Vn, Ve, Vd";
170 if (SubSystems & ssForces) {
172 outstream << "Drag, Side, Lift, ";
173 outstream << "L/D, ";
174 outstream << "Xforce, Yforce, Zforce";
176 if (SubSystems & ssMoments) {
178 outstream << "L, M, N";
180 if (SubSystems & ssAtmosphere) {
184 if (SubSystems & ssMassProps) {
186 outstream << "Ixx, ";
187 outstream << "Iyy, ";
188 outstream << "Izz, ";
189 outstream << "Ixz, ";
190 outstream << "Mass, ";
191 outstream << "Xcg, Ycg, Zcg";
193 if (SubSystems & ssPosition) {
195 outstream << "Altitude, ";
196 outstream << "Phi, Tht, Psi, ";
197 outstream << "Alpha, ";
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) {
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();
236 if (SubSystems & ssVelocities) {
238 outstream << Translation->Getqbar() << ", ";
239 outstream << Translation->GetVt() << ", ";
240 outstream << Translation->GetUVW() << ", ";
241 outstream << Translation->GetvAeroUVW() << ", ";
242 outstream << Position->GetVel();
244 if (SubSystems & ssForces) {
246 outstream << Aerodynamics->GetvFs() << ", ";
247 outstream << Aerodynamics->GetLoD() << ", ";
248 outstream << Aircraft->GetForces();
250 if (SubSystems & ssMoments) {
252 outstream << Aircraft->GetMoments();
254 if (SubSystems & ssAtmosphere) {
256 outstream << Atmosphere->GetDensity();
258 if (SubSystems & ssMassProps) {
260 outstream << MassBalance->GetIxx() << ", ";
261 outstream << MassBalance->GetIyy() << ", ";
262 outstream << MassBalance->GetIzz() << ", ";
263 outstream << MassBalance->GetIxz() << ", ";
264 outstream << MassBalance->GetMass() << ", ";
265 outstream << MassBalance->GetXYZcg();
267 if (SubSystems & ssPosition) {
269 outstream << Position->Geth() << ", ";
270 outstream << Rotation->GetEuler() << ", ";
271 outstream << Translation->Getalpha() << ", ";
272 outstream << Position->GetLatitude() << ", ";
273 outstream << Position->GetLongitude() << ", ";
274 outstream << Position->GetDistanceAGL() << ", ";
275 outstream << Position->GetRunwayRadius();
277 if (SubSystems & ssCoefficients) {
279 outstream << Aerodynamics->GetCoefficientValues();
281 if (SubSystems & ssGroundReactions) {
283 outstream << GroundReactions->GetGroundReactionValues();
285 if (SubSystems & ssPropulsion) {
287 outstream << Propulsion->GetPropulsionValues();
294 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296 void FGOutput::SocketOutput(void)
300 if (socket == NULL) return;
304 socket->Append("<LABELS>");
305 socket->Append("Time");
306 socket->Append("Altitude");
307 socket->Append("Phi");
308 socket->Append("Tht");
309 socket->Append("Psi");
310 socket->Append("Rho");
311 socket->Append("Vtotal");
312 socket->Append("UBody");
313 socket->Append("VBody");
314 socket->Append("WBody");
315 socket->Append("UAero");
316 socket->Append("VAero");
317 socket->Append("WAero");
318 socket->Append("Vn");
319 socket->Append("Ve");
320 socket->Append("Vd");
321 socket->Append("Udot");
322 socket->Append("Vdot");
323 socket->Append("Wdot");
327 socket->Append("PDot");
328 socket->Append("QDot");
329 socket->Append("RDot");
330 socket->Append("Fx");
331 socket->Append("Fy");
332 socket->Append("Fz");
333 socket->Append("Latitude");
334 socket->Append("Longitude");
335 socket->Append("QBar");
336 socket->Append("Alpha");
340 socket->Append("Throttle");
341 socket->Append("Aileron");
342 socket->Append("Elevator");
343 socket->Append("Rudder");
349 socket->Append(State->Getsim_time());
350 socket->Append(Position->Geth());
351 socket->Append(Rotation->Getphi());
352 socket->Append(Rotation->Gettht());
353 socket->Append(Rotation->Getpsi());
354 socket->Append(Atmosphere->GetDensity());
355 socket->Append(Translation->GetVt());
356 socket->Append(Translation->GetUVW(eU));
357 socket->Append(Translation->GetUVW(eV));
358 socket->Append(Translation->GetUVW(eW));
359 socket->Append(Translation->GetvAeroUVW(eU));
360 socket->Append(Translation->GetvAeroUVW(eV));
361 socket->Append(Translation->GetvAeroUVW(eW));
362 socket->Append(Position->GetVn());
363 socket->Append(Position->GetVe());
364 socket->Append(Position->GetVd());
365 socket->Append(Translation->GetUdot());
366 socket->Append(Translation->GetVdot());
367 socket->Append(Translation->GetWdot());
368 socket->Append(Rotation->GetP());
369 socket->Append(Rotation->GetQ());
370 socket->Append(Rotation->GetR());
371 socket->Append(Rotation->GetPdot());
372 socket->Append(Rotation->GetQdot());
373 socket->Append(Rotation->GetRdot());
374 socket->Append(Aircraft->GetFx());
375 socket->Append(Aircraft->GetFy());
376 socket->Append(Aircraft->GetFz());
377 socket->Append(Position->GetLatitude());
378 socket->Append(Position->GetLongitude());
379 socket->Append(Translation->Getqbar());
380 socket->Append(Translation->Getalpha());
381 socket->Append(Aircraft->GetL());
382 socket->Append(Aircraft->GetM());
383 socket->Append(Aircraft->GetN());
384 socket->Append(FCS->GetThrottle(0));
385 socket->Append(FCS->GetDa());
386 socket->Append(FCS->GetDe());
387 socket->Append(FCS->GetDr());
391 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
393 void FGOutput::SocketStatusOutput(string out_str)
397 if (socket == NULL) return;
400 asciiData = string("<STATUS>") + out_str;
401 socket->Append(asciiData.c_str());
405 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
407 bool FGOutput::Load(FGConfigFile* AC_cfg)
409 string token, parameter;
412 token = AC_cfg->GetValue("NAME");
413 Output->SetFilename(token);
414 token = AC_cfg->GetValue("TYPE");
415 Output->SetType(token);
416 AC_cfg->GetNextConfigLine();
418 while ((token = AC_cfg->GetValue()) != string("/OUTPUT")) {
419 *AC_cfg >> parameter;
420 if (parameter == "RATE_IN_HZ") *AC_cfg >> OutRate;
421 if (parameter == "SIMULATION") {
422 *AC_cfg >> parameter;
423 if (parameter == "ON") SubSystems += ssSimulation;
425 if (parameter == "AEROSURFACES") {
426 *AC_cfg >> parameter;
427 if (parameter == "ON") SubSystems += ssAerosurfaces;
429 if (parameter == "RATES") {
430 *AC_cfg >> parameter;
431 if (parameter == "ON") SubSystems += ssRates;
433 if (parameter == "VELOCITIES") {
434 *AC_cfg >> parameter;
435 if (parameter == "ON") SubSystems += ssVelocities;
437 if (parameter == "FORCES") {
438 *AC_cfg >> parameter;
439 if (parameter == "ON") SubSystems += ssForces;
441 if (parameter == "MOMENTS") {
442 *AC_cfg >> parameter;
443 if (parameter == "ON") SubSystems += ssMoments;
445 if (parameter == "ATMOSPHERE") {
446 *AC_cfg >> parameter;
447 if (parameter == "ON") SubSystems += ssAtmosphere;
449 if (parameter == "MASSPROPS") {
450 *AC_cfg >> parameter;
451 if (parameter == "ON") SubSystems += ssMassProps;
453 if (parameter == "POSITION") {
454 *AC_cfg >> parameter;
455 if (parameter == "ON") SubSystems += ssPosition;
457 if (parameter == "COEFFICIENTS") {
458 *AC_cfg >> parameter;
459 if (parameter == "ON") SubSystems += ssCoefficients;
461 if (parameter == "GROUND_REACTIONS") {
462 *AC_cfg >> parameter;
463 if (parameter == "ON") SubSystems += ssGroundReactions;
465 if (parameter == "FCS") {
466 *AC_cfg >> parameter;
467 if (parameter == "ON") SubSystems += ssFCS;
469 if (parameter == "PROPULSION") {
470 *AC_cfg >> parameter;
471 if (parameter == "ON") SubSystems += ssPropulsion;
475 OutRate = OutRate>120?120:(OutRate<0?0:OutRate);
476 rate = (int)(0.5 + 1.0/(State->Getdt()*OutRate));
481 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
483 void FGOutput::Debug(void)
485 //TODO: Add your source code here