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 << "Throttle, ";
152 outstream << "Mixture, ";
153 outstream << "Aileron Cmd, ";
154 outstream << "Elevator Cmd, ";
155 outstream << "Rudder Cmd, ";
156 outstream << "Aileron Pos, ";
157 outstream << "Elevator Pos, ";
158 outstream << "Rudder Pos";
160 if (SubSystems & ssRates) {
162 outstream << "P, Q, R";
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";
178 if (SubSystems & ssMoments) {
180 outstream << "L, M, N";
182 if (SubSystems & ssAtmosphere) {
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 << "Latitude, ";
201 outstream << "Longitude, ";
202 outstream << "Distance AGL, ";
203 outstream << "Runway Radius";
205 if (SubSystems & ssCoefficients) {
207 outstream << Aerodynamics->GetCoefficientStrings();
209 if (SubSystems & ssGroundReactions) {
211 outstream << GroundReactions->GetGroundReactionStrings();
213 if (SubSystems & ssPropulsion) {
215 outstream << Propulsion->GetPropulsionStrings();
222 outstream << State->Getsim_time();
223 if (SubSystems & ssSimulation) {
225 if (SubSystems & ssAerosurfaces) {
227 outstream << FCS->GetThrottlePos(0) << ", ";
228 outstream << FCS->GetMixturePos(0) << ", ";
229 outstream << FCS->GetDaCmd() << ", ";
230 outstream << FCS->GetDeCmd() << ", ";
231 outstream << FCS->GetDrCmd() << ", ";
232 outstream << FCS->GetDaPos() << ", ";
233 outstream << FCS->GetDePos() << ", ";
234 outstream << FCS->GetDrPos();
236 if (SubSystems & ssRates) {
238 outstream << Rotation->GetPQR();
240 if (SubSystems & ssVelocities) {
242 outstream << Translation->Getqbar() << ", ";
243 outstream << Translation->GetVt() << ", ";
244 outstream << Translation->GetUVW() << ", ";
245 outstream << Translation->GetvAero() << ", ";
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();
262 if (SubSystems & ssMassProps) {
264 outstream << MassBalance->GetIxx() << ", ";
265 outstream << MassBalance->GetIyy() << ", ";
266 outstream << MassBalance->GetIzz() << ", ";
267 outstream << MassBalance->GetIxz() << ", ";
268 outstream << MassBalance->GetMass() << ", ";
269 outstream << MassBalance->GetXYZcg();
271 if (SubSystems & ssPosition) {
273 outstream << Position->Geth() << ", ";
274 outstream << Rotation->GetEuler() << ", ";
275 outstream << Translation->Getalpha() << ", ";
276 outstream << Position->GetLatitude() << ", ";
277 outstream << Position->GetLongitude() << ", ";
278 outstream << Position->GetDistanceAGL() << ", ";
279 outstream << Position->GetRunwayRadius();
281 if (SubSystems & ssCoefficients) {
283 outstream << Aerodynamics->GetCoefficientValues();
285 if (SubSystems & ssGroundReactions) {
287 outstream << GroundReactions->GetGroundReactionValues();
289 if (SubSystems & ssPropulsion) {
291 outstream << Propulsion->GetPropulsionValues();
298 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 void FGOutput::SocketOutput(void)
304 if (socket == NULL) 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");
345 socket->Append("Aileron");
346 socket->Append("Elevator");
347 socket->Append("Rudder");
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->GetvAero(eU));
364 socket->Append(Translation->GetvAero(eV));
365 socket->Append(Translation->GetvAero(eW));
366 socket->Append(Position->GetVn());
367 socket->Append(Position->GetVe());
368 socket->Append(Position->GetVd());
369 socket->Append(Translation->GetUdot());
370 socket->Append(Translation->GetVdot());
371 socket->Append(Translation->GetWdot());
372 socket->Append(Rotation->GetP());
373 socket->Append(Rotation->GetQ());
374 socket->Append(Rotation->GetR());
375 socket->Append(Rotation->GetPdot());
376 socket->Append(Rotation->GetQdot());
377 socket->Append(Rotation->GetRdot());
378 socket->Append(Aircraft->GetFx());
379 socket->Append(Aircraft->GetFy());
380 socket->Append(Aircraft->GetFz());
381 socket->Append(Position->GetLatitude());
382 socket->Append(Position->GetLongitude());
383 socket->Append(Translation->Getqbar());
384 socket->Append(Translation->Getalpha());
385 socket->Append(Aircraft->GetL());
386 socket->Append(Aircraft->GetM());
387 socket->Append(Aircraft->GetN());
388 socket->Append(FCS->GetThrottle(0));
389 socket->Append(FCS->GetDa());
390 socket->Append(FCS->GetDe());
391 socket->Append(FCS->GetDr());
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);
420 AC_cfg->GetNextConfigLine();
422 while ((token = AC_cfg->GetValue()) != string("/OUTPUT")) {
423 *AC_cfg >> parameter;
424 if (parameter == "RATE_IN_HZ") *AC_cfg >> OutRate;
425 if (parameter == "SIMULATION") {
426 *AC_cfg >> parameter;
427 if (parameter == "ON") SubSystems += ssSimulation;
429 if (parameter == "AEROSURFACES") {
430 *AC_cfg >> parameter;
431 if (parameter == "ON") SubSystems += ssAerosurfaces;
433 if (parameter == "RATES") {
434 *AC_cfg >> parameter;
435 if (parameter == "ON") SubSystems += ssRates;
437 if (parameter == "VELOCITIES") {
438 *AC_cfg >> parameter;
439 if (parameter == "ON") SubSystems += ssVelocities;
441 if (parameter == "FORCES") {
442 *AC_cfg >> parameter;
443 if (parameter == "ON") SubSystems += ssForces;
445 if (parameter == "MOMENTS") {
446 *AC_cfg >> parameter;
447 if (parameter == "ON") SubSystems += ssMoments;
449 if (parameter == "ATMOSPHERE") {
450 *AC_cfg >> parameter;
451 if (parameter == "ON") SubSystems += ssAtmosphere;
453 if (parameter == "MASSPROPS") {
454 *AC_cfg >> parameter;
455 if (parameter == "ON") SubSystems += ssMassProps;
457 if (parameter == "POSITION") {
458 *AC_cfg >> parameter;
459 if (parameter == "ON") SubSystems += ssPosition;
461 if (parameter == "COEFFICIENTS") {
462 *AC_cfg >> parameter;
463 if (parameter == "ON") SubSystems += ssCoefficients;
465 if (parameter == "GROUND_REACTIONS") {
466 *AC_cfg >> parameter;
467 if (parameter == "ON") SubSystems += ssGroundReactions;
469 if (parameter == "FCS") {
470 *AC_cfg >> parameter;
471 if (parameter == "ON") SubSystems += ssFCS;
473 if (parameter == "PROPULSION") {
474 *AC_cfg >> parameter;
475 if (parameter == "ON") SubSystems += ssPropulsion;
479 OutRate = OutRate>120?120:(OutRate<0?0:OutRate);
480 rate = (int)(0.5 + 1.0/(State->Getdt()*OutRate));
485 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
487 void FGOutput::Debug(void)
489 //TODO: Add your source code here