JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGAccelerometer.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Module: FGAccelerometer.cpp
4  Author: Jon Berndt
5  Date started: 9 July 2005
6 
7  ------------- Copyright (C) 2005 -------------
8 
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17  details.
18 
19  You should have received a copy of the GNU Lesser General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23  Further information about the GNU Lesser General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25 
26 FUNCTIONAL DESCRIPTION
27 --------------------------------------------------------------------------------
28 
29 HISTORY
30 --------------------------------------------------------------------------------
31 
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 COMMENTS, REFERENCES, and NOTES
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 INCLUDES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39 
40 #include <iostream>
41 #include <cstdlib>
42 
43 #include "FGAccelerometer.h"
44 #include "models/FGPropagate.h"
45 #include "models/FGAccelerations.h"
46 #include "models/FGMassBalance.h"
47 #include "input_output/FGXMLElement.h"
48 #include "models/FGFCS.h"
49 
50 using namespace std;
51 
52 namespace JSBSim {
53 
54 IDENT(IdSrc,"$Id: FGAccelerometer.cpp,v 1.17 2015/08/09 17:29:48 bcoconni Exp $");
55 IDENT(IdHdr,ID_ACCELEROMETER);
56 
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 CLASS IMPLEMENTATION
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60 
61 FGAccelerometer::FGAccelerometer(FGFCS* fcs, Element* element)
62  : FGSensor(fcs, element),
63  FGSensorOrientation(element)
64 {
65  Propagate = fcs->GetExec()->GetPropagate();
66  Accelerations = fcs->GetExec()->GetAccelerations();
67  MassBalance = fcs->GetExec()->GetMassBalance();
68 
69  Element* location_element = element->FindElement("location");
70  if (location_element) vLocation = location_element->FindElementTripletConvertTo("IN");
71  else {cerr << "No location given for accelerometer. " << endl; exit(-1);}
72 
73  vRadius = MassBalance->StructuralToBody(vLocation);
74 
75  Debug(0);
76 }
77 
78 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 
80 FGAccelerometer::~FGAccelerometer()
81 {
82  Debug(1);
83 }
84 
85 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 
87 bool FGAccelerometer::Run(void )
88 {
89  // There is no input assumed. This is a dedicated acceleration sensor.
90 
91  vRadius = MassBalance->StructuralToBody(vLocation);
92 
93  //aircraft forces
94  vAccel = (Accelerations->GetBodyAccel()
95  + Accelerations->GetPQRidot() * vRadius
96  + Propagate->GetPQRi() * (Propagate->GetPQRi() * vRadius));
97 
98  // transform to the specified orientation
99  vAccel = mT * vAccel;
100 
101  Input = vAccel(axis);
102 
103  ProcessSensorSignal();
104 
105  if (IsOutput) SetOutput();
106 
107  return true;
108 }
109 
110 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 // The bitmasked value choices are as follows:
112 // unset: In this case (the default) JSBSim would only print
113 // out the normally expected messages, essentially echoing
114 // the config files as they are read. If the environment
115 // variable is not set, debug_lvl is set to 1 internally
116 // 0: This requests JSBSim not to output any messages
117 // whatsoever.
118 // 1: This value explicity requests the normal JSBSim
119 // startup messages
120 // 2: This value asks for a message to be printed out when
121 // a class is instantiated
122 // 4: When this value is set, a message is displayed when a
123 // FGModel object executes its Run() method
124 // 8: When this value is set, various runtime state variables
125 // are printed out periodically
126 // 16: When set various parameters are sanity checked and
127 // a message is printed out when they go out of bounds
128 
129 void FGAccelerometer::Debug(int from)
130 {
131  string ax[4] = {"none", "X", "Y", "Z"};
132 
133  if (debug_lvl <= 0) return;
134 
135  if (debug_lvl & 1) { // Standard console startup message output
136  if (from == 0) { // Constructor
137  cout << " Axis: " << ax[axis] << endl;
138  }
139  }
140  if (debug_lvl & 2 ) { // Instantiation/Destruction notification
141  if (from == 0) cout << "Instantiated: FGAccelerometer" << endl;
142  if (from == 1) cout << "Destroyed: FGAccelerometer" << endl;
143  }
144  if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
145  }
146  if (debug_lvl & 8 ) { // Runtime state variables
147  }
148  if (debug_lvl & 16) { // Sanity checking
149  }
150  if (debug_lvl & 64) {
151  if (from == 0) { // Constructor
152  cout << IdSrc << endl;
153  cout << IdHdr << endl;
154  }
155  }
156 }
157 }
STL namespace.