![]() |
JSBSim Flight Dynamics Model 1.0 (23 February 2013)
An Open Source Flight Dynamics and Control Software Library in C++
|
00001 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00002 00003 Module: FGAccelerometer.cpp 00004 Author: Jon Berndt 00005 Date started: 9 July 2005 00006 00007 ------------- Copyright (C) 2005 ------------- 00008 00009 This program is free software; you can redistribute it and/or modify it under 00010 the terms of the GNU Lesser General Public License as published by the Free Software 00011 Foundation; either version 2 of the License, or (at your option) any later 00012 version. 00013 00014 This program is distributed in the hope that it will be useful, but WITHOUT 00015 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00016 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00017 details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00023 Further information about the GNU Lesser General Public License can also be found on 00024 the world wide web at http://www.gnu.org. 00025 00026 FUNCTIONAL DESCRIPTION 00027 -------------------------------------------------------------------------------- 00028 00029 HISTORY 00030 -------------------------------------------------------------------------------- 00031 00032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00033 COMMENTS, REFERENCES, and NOTES 00034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00035 00036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00037 INCLUDES 00038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00039 00040 #include "FGAccelerometer.h" 00041 #include <iostream> 00042 #include <cstdlib> 00043 00044 #include "models/FGPropagate.h" 00045 #include "models/FGAccelerations.h" 00046 #include "models/FGMassBalance.h" 00047 #include "models/FGInertial.h" 00048 00049 using namespace std; 00050 00051 namespace JSBSim { 00052 00053 static const char *IdSrc = "$Id: FGAccelerometer.cpp,v 1.11 2012/11/17 18:03:19 jberndt Exp $"; 00054 static const char *IdHdr = ID_ACCELEROMETER; 00055 00056 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00057 CLASS IMPLEMENTATION 00058 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00059 00060 FGAccelerometer::FGAccelerometer(FGFCS* fcs, Element* element) 00061 : FGSensor(fcs, element), 00062 FGSensorOrientation(element) 00063 { 00064 Propagate = fcs->GetExec()->GetPropagate(); 00065 Accelerations = fcs->GetExec()->GetAccelerations(); 00066 MassBalance = fcs->GetExec()->GetMassBalance(); 00067 Inertial = fcs->GetExec()->GetInertial(); 00068 00069 Element* location_element = element->FindElement("location"); 00070 if (location_element) vLocation = location_element->FindElementTripletConvertTo("IN"); 00071 else {cerr << "No location given for accelerometer. " << endl; exit(-1);} 00072 00073 vRadius = MassBalance->StructuralToBody(vLocation); 00074 00075 Debug(0); 00076 } 00077 00078 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00079 00080 FGAccelerometer::~FGAccelerometer() 00081 { 00082 Debug(1); 00083 } 00084 00085 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00086 00087 bool FGAccelerometer::Run(void ) 00088 { 00089 // There is no input assumed. This is a dedicated acceleration sensor. 00090 00091 vRadius = MassBalance->StructuralToBody(vLocation); 00092 00093 //aircraft forces 00094 vAccel = (Accelerations->GetBodyAccel() 00095 + Propagate->GetTi2b() * Accelerations->GetGravAccel() 00096 + Accelerations->GetPQRdot() * vRadius 00097 + Propagate->GetPQR() * (Propagate->GetPQR() * vRadius)); 00098 00099 // transform to the specified orientation 00100 vAccel = mT * vAccel; 00101 00102 Input = vAccel(axis); 00103 00104 ProcessSensorSignal(); 00105 00106 if (IsOutput) SetOutput(); 00107 00108 return true; 00109 } 00110 00111 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00112 // The bitmasked value choices are as follows: 00113 // unset: In this case (the default) JSBSim would only print 00114 // out the normally expected messages, essentially echoing 00115 // the config files as they are read. If the environment 00116 // variable is not set, debug_lvl is set to 1 internally 00117 // 0: This requests JSBSim not to output any messages 00118 // whatsoever. 00119 // 1: This value explicity requests the normal JSBSim 00120 // startup messages 00121 // 2: This value asks for a message to be printed out when 00122 // a class is instantiated 00123 // 4: When this value is set, a message is displayed when a 00124 // FGModel object executes its Run() method 00125 // 8: When this value is set, various runtime state variables 00126 // are printed out periodically 00127 // 16: When set various parameters are sanity checked and 00128 // a message is printed out when they go out of bounds 00129 00130 void FGAccelerometer::Debug(int from) 00131 { 00132 string ax[4] = {"none", "X", "Y", "Z"}; 00133 00134 if (debug_lvl <= 0) return; 00135 00136 if (debug_lvl & 1) { // Standard console startup message output 00137 if (from == 0) { // Constructor 00138 cout << " Axis: " << ax[axis] << endl; 00139 } 00140 } 00141 if (debug_lvl & 2 ) { // Instantiation/Destruction notification 00142 if (from == 0) cout << "Instantiated: FGAccelerometer" << endl; 00143 if (from == 1) cout << "Destroyed: FGAccelerometer" << endl; 00144 } 00145 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects 00146 } 00147 if (debug_lvl & 8 ) { // Runtime state variables 00148 } 00149 if (debug_lvl & 16) { // Sanity checking 00150 } 00151 if (debug_lvl & 64) { 00152 if (from == 0) { // Constructor 00153 cout << IdSrc << endl; 00154 cout << IdHdr << endl; 00155 } 00156 } 00157 } 00158 }