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 != "NONE"){
125 cerr << "Unknown type of output specified in config file" << endl;
129 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 void FGOutput::DelimitedOutput(string fname)
133 # if defined(sgi) && !defined(__GNUC__)
134 ostream_withassign outstream;
136 _IO_ostream_withassign outstream;
139 if (fname == "COUT" || fname == "cout") {
142 datafile.open(fname.c_str());
143 outstream = datafile;
148 if (SubSystems & FGAircraft::ssSimulation) {
151 if (SubSystems & FGAircraft::ssAerosurfaces) {
153 outstream << "Throttle, ";
154 outstream << "Mixture, ";
155 outstream << "Aileron Cmd, ";
156 outstream << "Elevator Cmd, ";
157 outstream << "Rudder Cmd, ";
158 outstream << "Aileron Pos, ";
159 outstream << "Elevator Pos, ";
160 outstream << "Rudder Pos";
162 if (SubSystems & FGAircraft::ssRates) {
164 outstream << "P, Q, R";
166 if (SubSystems & FGAircraft::ssVelocities) {
168 outstream << "QBar, ";
169 outstream << "Vtotal, ";
170 outstream << "UBody, VBody, WBody, ";
171 outstream << "UAero, VAero, WAero, ";
172 outstream << "Vn, Ve, Vd";
174 if (SubSystems & FGAircraft::ssForces) {
176 outstream << "Drag, Side, Lift, ";
177 outstream << "L/D, ";
178 outstream << "Xforce, Yforce, Zforce";
180 if (SubSystems & FGAircraft::ssMoments) {
182 outstream << "L, M, N";
184 if (SubSystems & FGAircraft::ssAtmosphere) {
188 if (SubSystems & FGAircraft::ssMassProps) {
190 outstream << "Ixx, ";
191 outstream << "Iyy, ";
192 outstream << "Izz, ";
193 outstream << "Ixz, ";
194 outstream << "Mass, ";
195 outstream << "Xcg, Ycg, Zcg";
197 if (SubSystems & FGAircraft::ssPosition) {
199 outstream << "Altitude, ";
200 outstream << "Phi, Tht, Psi, ";
201 outstream << "Alpha, ";
202 outstream << "Latitude, ";
203 outstream << "Longitude, ";
204 outstream << "Distance AGL, ";
205 outstream << "Runway Radius";
207 if (SubSystems & FGAircraft::ssCoefficients) {
209 outstream << Aerodynamics->GetCoefficientStrings();
211 if (SubSystems & FGAircraft::ssGroundReactions) {
213 outstream << GroundReactions->GetGroundReactionStrings();
215 if (SubSystems & FGAircraft::ssPropulsion) {
217 outstream << Propulsion->GetPropulsionStrings();
224 outstream << State->Getsim_time();
225 if (SubSystems & FGAircraft::ssSimulation) {
227 if (SubSystems & FGAircraft::ssAerosurfaces) {
229 outstream << FCS->GetThrottlePos(0) << ", ";
230 outstream << FCS->GetMixturePos(0) << ", ";
231 outstream << FCS->GetDaCmd() << ", ";
232 outstream << FCS->GetDeCmd() << ", ";
233 outstream << FCS->GetDrCmd() << ", ";
234 outstream << FCS->GetDaPos() << ", ";
235 outstream << FCS->GetDePos() << ", ";
236 outstream << FCS->GetDrPos();
238 if (SubSystems & FGAircraft::ssRates) {
240 outstream << Rotation->GetPQR();
242 if (SubSystems & FGAircraft::ssVelocities) {
244 outstream << Translation->Getqbar() << ", ";
245 outstream << Translation->GetVt() << ", ";
246 outstream << Translation->GetUVW() << ", ";
247 outstream << Translation->GetvAero() << ", ";
248 outstream << Position->GetVel();
250 if (SubSystems & FGAircraft::ssForces) {
252 outstream << Aerodynamics->GetvFs() << ", ";
253 outstream << Aerodynamics->GetLoD() << ", ";
254 outstream << Aircraft->GetForces();
256 if (SubSystems & FGAircraft::ssMoments) {
258 outstream << Aircraft->GetMoments();
260 if (SubSystems & FGAircraft::ssAtmosphere) {
262 outstream << Atmosphere->GetDensity();
264 if (SubSystems & FGAircraft::ssMassProps) {
266 outstream << MassBalance->GetIxx() << ", ";
267 outstream << MassBalance->GetIyy() << ", ";
268 outstream << MassBalance->GetIzz() << ", ";
269 outstream << MassBalance->GetIxz() << ", ";
270 outstream << MassBalance->GetMass() << ", ";
271 outstream << MassBalance->GetXYZcg();
273 if (SubSystems & FGAircraft::ssPosition) {
275 outstream << Position->Geth() << ", ";
276 outstream << Rotation->GetEuler() << ", ";
277 outstream << Translation->Getalpha() << ", ";
278 outstream << Position->GetLatitude() << ", ";
279 outstream << Position->GetLongitude() << ", ";
280 outstream << Position->GetDistanceAGL() << ", ";
281 outstream << Position->GetRunwayRadius();
283 if (SubSystems & FGAircraft::ssCoefficients) {
285 outstream << Aerodynamics->GetCoefficientValues();
287 if (SubSystems & FGAircraft::ssGroundReactions) {
289 outstream << GroundReactions->GetGroundReactionValues();
291 if (SubSystems & FGAircraft::ssPropulsion) {
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->GetvAero(eU));
366 socket->Append(Translation->GetvAero(eV));
367 socket->Append(Translation->GetvAero(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 void FGOutput::Debug(void)
415 //TODO: Add your source code here