JSBSim Flight Dynamics Model 1.0 (23 February 2013)
An Open Source Flight Dynamics and Control Software Library in C++

FGSensorOrientation.h

00001 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00002 
00003  Header:       FGSensorOrientation.h
00004  Author:       Jon Berndt
00005  Date started: September 2009
00006 
00007  ------------- Copyright (C) 2009 -------------
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 HISTORY
00027 --------------------------------------------------------------------------------
00028 
00029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00030 SENTRY
00031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00032 
00033 #ifndef FGSENSORORIENTATION_H
00034 #define FGSENSORORIENTATION_H
00035 
00036 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00037 INCLUDES
00038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00039 
00040 #include "FGSensor.h"
00041 #include "input_output/FGXMLElement.h"
00042 #include "math/FGColumnVector3.h"
00043 #include "math/FGMatrix33.h"
00044 
00045 #include <iostream>
00046 
00047 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00048 DEFINITIONS
00049 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00050 
00051 #define ID_SensorOrientation "$Id: FGSensorOrientation.h,v 1.3 2009/10/24 22:59:30 jberndt Exp $"
00052 
00053 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00054 FORWARD DECLARATIONS
00055 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00056 
00057 namespace JSBSim {
00058 
00059 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00060 CLASS DOCUMENTATION
00061 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00062 
00071 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00072 CLASS DECLARATION
00073 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00074 
00075 class FGSensorOrientation  : public FGJSBBase
00076 {
00077 public:
00078   FGSensorOrientation(Element* element)
00079   {
00080     Element* orient_element = element->FindElement("orientation");
00081     if (orient_element) vOrient = orient_element->FindElementTripletConvertTo("RAD");
00082     else { std::cerr << "No orientation given for this sensor. " << std::endl;}
00083 
00084     Element* axis_element = element->FindElement("axis");
00085     if (axis_element) {
00086       string sAxis = element->FindElementValue("axis");
00087       if (sAxis == "X" || sAxis == "x") {
00088         axis = 1;
00089       } else if (sAxis == "Y" || sAxis == "y") {
00090         axis = 2;
00091       } else if (sAxis == "Z" || sAxis == "z") {
00092         axis = 3;
00093       } else {
00094         std::cerr << "  Incorrect/no axis specified for this sensor; assuming X axis" << std::endl;
00095         axis = 1;
00096       }
00097     }
00098 
00099     CalculateTransformMatrix();
00100   }
00101 
00102 //  ~FGSensorOrientation();
00103 
00104 protected:
00105   FGColumnVector3 vOrient;
00106   FGMatrix33 mT;
00107   int axis;
00108   void CalculateTransformMatrix(void)
00109   {
00110     double cp,sp,cr,sr,cy,sy;
00111 
00112     cp=cos(vOrient(ePitch)); sp=sin(vOrient(ePitch));
00113     cr=cos(vOrient(eRoll));  sr=sin(vOrient(eRoll));
00114     cy=cos(vOrient(eYaw));   sy=sin(vOrient(eYaw));
00115 
00116     mT(1,1) =  cp*cy;
00117     mT(1,2) =  cp*sy;
00118     mT(1,3) = -sp;
00119 
00120     mT(2,1) = sr*sp*cy - cr*sy;
00121     mT(2,2) = sr*sp*sy + cr*cy;
00122     mT(2,3) = sr*cp;
00123 
00124     mT(3,1) = cr*sp*cy + sr*sy;
00125     mT(3,2) = cr*sp*sy - sr*cy;
00126     mT(3,3) = cr*cp;
00127 
00128     // This transform is different than for FGForce, where we want a native nozzle
00129     // force in body frame. Here we calculate the body frame accel and want it in
00130     // the transformed accelerometer frame. So, the next line is commented out.
00131     // mT = mT.Inverse();
00132   }
00133 
00134 private:
00135   void Debug(int from);
00136 };
00137 }
00138 #endif