1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Header: FGSensorOrientation.h
5 Date started: September 2009
7 ------------- Copyright (C) 2009 -------------
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
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
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.
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.
27 --------------------------------------------------------------------------------
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33 #ifndef FGSENSORORIENTATION_H
34 #define FGSENSORORIENTATION_H
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41 #include "input_output/FGXMLElement.h"
42 #include "math/FGColumnVector3.h"
43 #include "math/FGMatrix33.h"
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51 #define ID_SensorOrientation "$Id: FGSensorOrientation.h,v 1.3 2009/10/24 22:59:30 jberndt Exp $"
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63 /** Encapsulates a SensorOrientation capability for a sensor.
68 @version $Revision: 1.3 $
71 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
75 class FGSensorOrientation : public FGJSBBase
78 FGSensorOrientation(Element* element)
80 Element* orient_element = element->FindElement("orientation");
81 if (orient_element) vOrient = orient_element->FindElementTripletConvertTo("RAD");
82 else { std::cerr << "No orientation given for this sensor. " << std::endl;}
84 Element* axis_element = element->FindElement("axis");
86 string sAxis = element->FindElementValue("axis");
87 if (sAxis == "X" || sAxis == "x") {
89 } else if (sAxis == "Y" || sAxis == "y") {
91 } else if (sAxis == "Z" || sAxis == "z") {
94 std::cerr << " Incorrect/no axis specified for this sensor; assuming X axis" << std::endl;
99 CalculateTransformMatrix();
102 // ~FGSensorOrientation();
105 FGColumnVector3 vOrient;
108 void CalculateTransformMatrix(void)
110 double cp,sp,cr,sr,cy,sy;
112 cp=cos(vOrient(ePitch)); sp=sin(vOrient(ePitch));
113 cr=cos(vOrient(eRoll)); sr=sin(vOrient(eRoll));
114 cy=cos(vOrient(eYaw)); sy=sin(vOrient(eYaw));
120 mT(2,1) = sr*sp*cy - cr*sy;
121 mT(2,2) = sr*sp*sy + cr*cy;
124 mT(3,1) = cr*sp*cy + sr*sy;
125 mT(3,2) = cr*sp*sy - sr*cy;
128 // This transform is different than for FGForce, where we want a native nozzle
129 // force in body frame. Here we calculate the body frame accel and want it in
130 // the transformed accelerometer frame. So, the next line is commented out.
131 // mT = mT.Inverse();
135 void Debug(int from);