JSBSim Flight Dynamics Model  1.2.1 (08 Aug 2024)
An Open Source Flight Dynamics and Control Software Library in C++
FGSensorOrientation.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Header: FGSensorOrientation.h
4  Author: Jon Berndt
5  Date started: September 2009
6 
7  ------------- Copyright (C) 2009 -------------
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 HISTORY
27 --------------------------------------------------------------------------------
28 
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 SENTRY
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
32 
33 #ifndef FGSENSORORIENTATION_H
34 #define FGSENSORORIENTATION_H
35 
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 INCLUDES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39 
40 #include "FGSensor.h"
41 #include "input_output/FGXMLElement.h"
42 #include "math/FGColumnVector3.h"
43 #include "math/FGMatrix33.h"
44 
45 #include <iostream>
46 
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 FORWARD DECLARATIONS
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50 
51 namespace JSBSim {
52 
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 CLASS DOCUMENTATION
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 
65 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 CLASS DECLARATION
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68 
70 {
71 public:
73  {
74  Element* orient_element = element->FindElement("orientation");
75  if (orient_element) vOrient = orient_element->FindElementTripletConvertTo("RAD");
76 
77  axis = 0;
78 
79  Element* axis_element = element->FindElement("axis");
80  if (axis_element) {
81  std::string sAxis = element->FindElementValue("axis");
82  if (sAxis == "X" || sAxis == "x") {
83  axis = 1;
84  } else if (sAxis == "Y" || sAxis == "y") {
85  axis = 2;
86  } else if (sAxis == "Z" || sAxis == "z") {
87  axis = 3;
88  }
89  }
90 
91  if (!axis) {
92  std::cerr << " Incorrect/no axis specified for this sensor; assuming X axis" << std::endl;
93  axis = 1;
94  }
95 
96  CalculateTransformMatrix();
97  }
98 
99 // ~FGSensorOrientation();
100 
101 protected:
102  FGColumnVector3 vOrient;
103  FGMatrix33 mT;
104  int axis;
105  void CalculateTransformMatrix(void)
106  {
107  double cp,sp,cr,sr,cy,sy;
108 
109  cp=cos(vOrient(ePitch)); sp=sin(vOrient(ePitch));
110  cr=cos(vOrient(eRoll)); sr=sin(vOrient(eRoll));
111  cy=cos(vOrient(eYaw)); sy=sin(vOrient(eYaw));
112 
113  mT(1,1) = cp*cy;
114  mT(1,2) = cp*sy;
115  mT(1,3) = -sp;
116 
117  mT(2,1) = sr*sp*cy - cr*sy;
118  mT(2,2) = sr*sp*sy + cr*cy;
119  mT(2,3) = sr*cp;
120 
121  mT(3,1) = cr*sp*cy + sr*sy;
122  mT(3,2) = cr*sp*sy - sr*cy;
123  mT(3,3) = cr*cp;
124 
125  // This transform is different than for FGForce, where we want a native nozzle
126  // force in body frame. Here we calculate the body frame accel and want it in
127  // the transformed accelerometer frame. So, the next line is commented out.
128  // mT = mT.Inverse();
129  }
130 
131 private:
132  void Debug(int from);
133 };
134 }
135 #endif
Element * FindElement(const std::string &el="")
Searches for a specified element.
FGColumnVector3 FindElementTripletConvertTo(const std::string &target_units)
Composes a 3-element column vector for the supplied location or orientation.
std::string FindElementValue(const std::string &el="")
Searches for the named element and returns the string data belonging to it.
This class implements a 3 element column vector.
JSBSim Base class.
Definition: FGJSBBase.h:118
Handles matrix math operations.
Definition: FGMatrix33.h:70
Encapsulates a SensorOrientation capability for a sensor.