| 1 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 | |
| 3 | Header: FGForce.h |
| 4 | Author: Tony Peden |
| 5 | Date started: 5/20/00 |
| 6 | |
| 7 | ------------- Copyright (C) 1999 Anthony K. Peden ([email protected]) ----- |
| 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 |
| 11 | Software Foundation; either version 2 of the License, or (at your option) any |
| 12 | later 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 |
| 20 | with this program; if not, write to the Free Software Foundation, Inc., 59 |
| 21 | Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | |
| 23 | Further information about the GNU Lesser General Public License can also be |
| 24 | found on the world wide web at http://www.gnu.org. |
| 25 | |
| 26 | |
| 27 | HISTORY |
| 28 | -------------------------------------------------------------------------------- |
| 29 | 5/20/00 TP Created |
| 30 | |
| 31 | |
| 32 | FUNCTIONAL DESCRIPTION |
| 33 | -------------------------------------------------------------------------------- |
| 34 | |
| 35 | The purpose of this class is to provide storage for computed forces and |
| 36 | encapsulate all the functionality associated with transforming those |
| 37 | forces from their native coord system to the body system. This includes |
| 38 | computing the moments due to the difference between the point of application |
| 39 | and the cg. |
| 40 | |
| 41 | CAVEAT: if the custom transform is used for wind-to-body transforms then the |
| 42 | user *must* always pass this class the negative of beta. This is true |
| 43 | because sideslip angle does not follow the right hand rule i.e. it is |
| 44 | positive for aircraft nose left sideslip. Note that use of the custom |
| 45 | transform for this purpose shouldn't be necessary as it is already |
| 46 | provided by SetTransform(tWindBody) and is not subject to the same |
| 47 | restriction. |
| 48 | |
| 49 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 50 | SENTRY |
| 51 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 52 | |
| 53 | #ifndef FGFORCE_H |
| 54 | #define FGFORCE_H |
| 55 | |
| 56 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 57 | INCLUDES |
| 58 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 59 | |
| 60 | #include "FGJSBBase.h" |
| 61 | #include "math/FGMatrix33.h" |
| 62 | |
| 63 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 64 | FORWARD DECLARATIONS |
| 65 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 66 | |
| 67 | namespace JSBSim { |
| 68 | |
| 69 | class FGFDMExec; |
| 70 | class FGMassBalance; |
| 71 | |
| 72 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 73 | CLASS DOCUMENTATION |
| 74 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 75 | |
| 76 | /** Utility class that aids in the conversion of forces between coordinate |
| 77 | systems and calculation of moments. |
| 78 | <br><h3>Resolution of Applied Forces into Moments and Body Axes Components</h3> |
| 79 | <br><p> |
| 80 | All forces acting on the aircraft that cannot be considered a change in weight |
| 81 | need to be resolved into body axis components so that the aircraft acceleration |
| 82 | vectors, both translational and rotational, can be computed. Furthermore, the |
| 83 | moments produced by each force that does not act at a location corresponding to |
| 84 | the center of gravity also need to be computed. Unfortunately, the math required |
| 85 | to do this can be a bit messy and errors are easily introduced so the class |
| 86 | FGForce was created to provide these services in a consistent and reusable |
| 87 | manner.<br><br></p> |
| 88 | |
| 89 | <h4>Basic usage</h4> |
| 90 | |
| 91 | <p>FGForce requires that its users supply it with the location of the applied |
| 92 | force vector in JSBSim structural coordinates, the sense of each axis in that |
| 93 | coordinate system relative to the body system, the orientation of the vector |
| 94 | also relative to body coordinates and, of course, the force vector itself. With |
| 95 | this information it will compute both the body axis force components and the |
| 96 | resulting moments. Any moments inherently produced by the native system can be |
| 97 | supplied as well and they will be summed with those computed.</p> |
| 98 | |
| 99 | <p>A good example for demonstrating the use of this class are the aerodynamic |
| 100 | forces: lift, drag, and side force and the aerodynamic moments about the pitch, |
| 101 | roll and yaw axes. These "native" forces and moments are computed and stored |
| 102 | in the FGColumnVector objects vFs and vMoments. Their native coordinate system |
| 103 | is often referred to as the wind system and is defined as a right-handed system |
| 104 | having its x-axis aligned with the relative velocity vector and pointing towards |
| 105 | the rear of the aircraft , the y-axis extending out the right wing, and the |
| 106 | z-axis directed upwards. This is different than body axes; they are defined such |
| 107 | that the x-axis is lies on the aircraft's roll axis and positive forward, the |
| 108 | y-axis is positive out the right wing, and the z-axis is positive downwards. In |
| 109 | this instance, JSBSim already provides the needed transform and FGForce can make |
| 110 | use of it by calling SetTransformType() once an object is created:</p> |
| 111 | |
| 112 | <p><tt>FGForce fgf(FDMExec);</tt><br> |
| 113 | <tt>fgf.SetTransformType(tWindBody);</tt><br><br> |
| 114 | |
| 115 | This call need only be made once for each object. The available transforms are |
| 116 | defined in the enumerated type TransformType and are tWindBody, tLocalBody, |
| 117 | tCustom, and tNone. The local-to-body transform, like the wind-to-body, also |
| 118 | makes use of that already available in JSBSim. tNone sets FGForce to do no |
| 119 | angular transform at all, and tCustom allows for modeling force vectors at |
| 120 | arbitrary angles relative to the body system such as that produced by propulsion |
| 121 | systems. Setting up and using a custom transform is covered in more detail |
| 122 | below. |
| 123 | Continuing with the example, the point of application of the aerodynamic forces, |
| 124 | the aerodynamic reference point in JSBSim, also needs to be set:</p> |
| 125 | <p><tt> |
| 126 | fgf.SetLocation(x, y, z)</tt></p> |
| 127 | |
| 128 | <p>where x, y, and z are in JSBSim structural coordinates.</p> |
| 129 | |
| 130 | <p>Initialization is complete and the FGForce object is ready to do its job. As |
| 131 | stated above, the lift, drag, and side force are computed and stored in the |
| 132 | vector vFs and need to be passed to FGForce:</p> |
| 133 | |
| 134 | <p><tt>fgf.SetNativeForces(vFs);</tt> </p> |
| 135 | |
| 136 | <p>The same applies to the aerodynamic pitching, rolling and yawing moments:</p> |
| 137 | |
| 138 | <p><tt>fgf.SetNativeMoments(vMoments);</tt></p> |
| 139 | |
| 140 | <p>Note that storing the native forces and moments outside of this class is not |
| 141 | strictly necessary, overloaded SetNativeForces() and SetNativeMoments() methods |
| 142 | which each accept three doubles (rather than a vector) are provided and can be |
| 143 | repeatedly called without incurring undue overhead. The body axes force vector |
| 144 | can now be retrieved by calling:</p> |
| 145 | |
| 146 | <p><tt>vFb=fgf.GetBodyForces();</tt></p> |
| 147 | |
| 148 | <p>This method is where the bulk of the work gets done so calling it more than |
| 149 | once for the same set of native forces and moments should probably be avoided. |
| 150 | Note that the moment calculations are done here as well so they should be |
| 151 | retrieved after calling the GetBodyForces() method:</p> |
| 152 | |
| 153 | <p><tt>vM=fgf.GetMoments();</tt> </p> |
| 154 | |
| 155 | <p>As an aside, the native moments are not needed to perform the computations |
| 156 | correctly so, if the FGForce object is not being used to store them then an |
| 157 | alternate approach is to avoid the SetNativeMoments call and perform the sum</p> |
| 158 | |
| 159 | <p><tt>vMoments+=fgf.GetMoments();</tt> <br><br> |
| 160 | |
| 161 | after the forces have been retrieved. </p> |
| 162 | |
| 163 | <h4>Use of the Custom Transform Type</h4> |
| 164 | |
| 165 | <p>In cases where the native force vector is not aligned with the body, wind, or |
| 166 | local coordinate systems a custom transform type is provided. A vectorable |
| 167 | engine nozzle will be used to demonstrate its usage. Initialization is much the |
| 168 | same:</p> |
| 169 | |
| 170 | <p><tt>FGForce fgf(FDMExec);</tt> <br> |
| 171 | <tt>fgf.SetTransformType(tCustom);</tt> <br> |
| 172 | <tt>fgf.SetLocation(x,y,z);</tt> </p> |
| 173 | |
| 174 | <p>Except that here the tCustom transform type is specified and the location of |
| 175 | the thrust vector is used rather than the aerodynamic reference point. Thrust is |
| 176 | typically considered to be positive when directed aft while the body x-axis is |
| 177 | positive forward and, if the native system is right handed, the z-axis will be |
| 178 | reversed as well. These differences in sense need to be specified using by the |
| 179 | call: </p> |
| 180 | |
| 181 | <p><tt>fgf.SetSense(-1,1,-1);</tt></p> |
| 182 | |
| 183 | <p>The angles are specified by calling the method: </p> |
| 184 | |
| 185 | <p><tt>fgf.SetAnglesToBody(pitch, roll, yaw);</tt> </p> |
| 186 | |
| 187 | <p>in which the transform matrix is computed. Note that these angles should be |
| 188 | taken relative to the body system and not the local as the names might suggest. |
| 189 | For an aircraft with vectorable thrust, this method will need to be called |
| 190 | every time the nozzle angle changes, a fixed engine/nozzle installation, on the |
| 191 | other hand, will require it to be be called only once.</p> |
| 192 | |
| 193 | <p>Retrieval of the computed forces and moments is done as detailed above.</p> |
| 194 | <br> |
| 195 | <pre> |
| 196 | <p><i>CAVEAT: If the custom system is used to compute |
| 197 | the wind-to-body transform, then the sign of the sideslip |
| 198 | angle must be reversed when calling SetAnglesToBody(). |
| 199 | This is true because sideslip angle does not follow the right |
| 200 | hand rule. Using the custom transform type this way |
| 201 | should not be necessary, as it is already provided as a built |
| 202 | in type (and the sign differences are correctly accounted for).</i> |
| 203 | </p> |
| 204 | </pre> |
| 205 | |
| 206 | <h4>Use as a Base Type</h4> |
| 207 | |
| 208 | <p>For use as a base type, the native force and moment vector data members are |
| 209 | defined as protected. In this case the SetNativeForces() and SetNativeMoments() |
| 210 | methods need not be used and, instead, the assignments to vFn, the force vector, |
| 211 | and vMn, the moments, can be made directly. Otherwise, the usage is similar.<br> |
| 212 | <br><br></p> |
| 213 | |
| 214 | @author Tony Peden |
| 215 | */ |
| 216 | |
| 217 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 218 | CLASS DECLARATION |
| 219 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 220 | |
| 221 | class JSBSIM_API FGForce : public FGJSBBase |
| 222 | { |
| 223 | public: |
| 224 | /// Constructor |
| 225 | explicit FGForce(FGFDMExec *FDMExec); |
| 226 | |
| 227 | /// Destructor |
| 228 | virtual ~FGForce(); |
| 229 | |
| 230 | enum TransformType { tNone, tWindBody, tLocalBody, tInertialBody, tCustom }; |
| 231 | |
| 232 | virtual const FGColumnVector3& GetBodyForces(void); |
| 233 | |
| 234 | inline double GetBodyXForce(void) const { return vFb(eX); } |
| 235 | inline double GetBodyYForce(void) const { return vFb(eY); } |
| 236 | inline double GetBodyZForce(void) const { return vFb(eZ); } |
| 237 | inline const FGColumnVector3& GetMoments(void) const { return vM; } |
| 238 | |
| 239 | // Normal point of application, JSBsim structural coords |
| 240 | // (inches, x +back, y +right, z +up) |
| 241 | inline void SetLocation(double x, double y, double z) { |
| 242 | vXYZn(eX) = x; |
| 243 | vXYZn(eY) = y; |
| 244 | vXYZn(eZ) = z; |
| 245 | SetActingLocation(x, y, z); |
| 246 | } |
| 247 | |
| 248 | /** Acting point of application. |
| 249 | JSBsim structural coords used (inches, x +back, y +right, z +up). |
| 250 | This function sets the point at which the force acts - this may |
| 251 | not be the same as where the object resides. One area where this |
| 252 | is true is P-Factor modeling. |
| 253 | @param x acting location of force |
| 254 | @param y acting location of force |
| 255 | @param z acting location of force */ |
| 256 | inline void SetActingLocation(double x, double y, double z) { |
| 257 | vActingXYZn(eX) = x; |
| 258 | vActingXYZn(eY) = y; |
| 259 | vActingXYZn(eZ) = z; |
| 260 | } |
| 261 | inline void SetLocationX(double x) {vXYZn(eX) = x; vActingXYZn(eX) = x;} |
| 262 | inline void SetLocationY(double y) {vXYZn(eY) = y; vActingXYZn(eY) = y;} |
| 263 | inline void SetLocationZ(double z) {vXYZn(eZ) = z; vActingXYZn(eZ) = z;} |
| 264 | inline double SetActingLocationX(double x) {vActingXYZn(eX) = x; return x;} |
| 265 | inline double SetActingLocationY(double y) {vActingXYZn(eY) = y; return y;} |
| 266 | inline double SetActingLocationZ(double z) {vActingXYZn(eZ) = z; return z;} |
| 267 | inline void SetLocation(const FGColumnVector3& vv) { vXYZn = vv; SetActingLocation(vv);} |
| 268 | inline void SetActingLocation(const FGColumnVector3& vv) { vActingXYZn = vv; } |
| 269 | |
| 270 | inline double GetLocationX( void ) const { return vXYZn(eX);} |
| 271 | inline double GetLocationY( void ) const { return vXYZn(eY);} |
| 272 | inline double GetLocationZ( void ) const { return vXYZn(eZ);} |
| 273 | inline double GetActingLocationX( void ) const { return vActingXYZn(eX);} |
| 274 | inline double GetActingLocationY( void ) const { return vActingXYZn(eY);} |
| 275 | inline double GetActingLocationZ( void ) const { return vActingXYZn(eZ);} |
| 276 | const FGColumnVector3& GetLocation(void) const { return vXYZn; } |
| 277 | const FGColumnVector3& GetActingLocation(void) const { return vActingXYZn; } |
| 278 | |
| 279 | //these angles are relative to body axes, not earth!!!!! |
| 280 | //I'm using these because pitch, roll, and yaw are easy to visualize, |
| 281 | //there's no equivalent to roll in wind axes i.e. alpha, ? , beta |
| 282 | //making up new names or using these is a toss-up: either way people |
| 283 | //are going to get confused. |
| 284 | //They are in radians. |
| 285 | |
| 286 | void SetAnglesToBody(double broll, double bpitch, double byaw); |
| 287 | inline void SetAnglesToBody(const FGColumnVector3& vv) { |
| 288 | SetAnglesToBody(vv(eRoll), vv(ePitch), vv(eYaw)); |
| 289 | } |
| 290 | |
| 291 | void UpdateCustomTransformMatrix(void); |
| 292 | void SetPitch(double pitch) {vOrient(ePitch) = pitch; UpdateCustomTransformMatrix();} |
| 293 | void SetYaw(double yaw) {vOrient(eYaw) = yaw; UpdateCustomTransformMatrix();} |
| 294 | |
| 295 | double GetPitch(void) const {return vOrient(ePitch);} |
| 296 | double GetYaw(void) const {return vOrient(eYaw);} |
| 297 | |
| 298 | inline const FGColumnVector3& GetAnglesToBody(void) const {return vOrient;} |
| 299 | inline double GetAnglesToBody(int axis) const {return vOrient(axis);} |
| 300 | |
| 301 | inline void SetTransformType(TransformType ii) { ttype=ii; } |
| 302 | inline TransformType GetTransformType(void) const { return ttype; } |
| 303 | |
| 304 | const FGMatrix33& Transform(void) const; |
| 305 | |
| 306 | protected: |
| 307 | FGFDMExec *fdmex; |
| 308 | FGMassBalance* MassBalance; |
| 309 | FGColumnVector3 vFn; |
| 310 | FGColumnVector3 vMn; |
| 311 | FGColumnVector3 vOrient; |
| 312 | TransformType ttype; |
| 313 | FGColumnVector3 vXYZn; |
| 314 | FGColumnVector3 vActingXYZn; |
| 315 | FGMatrix33 mT; |
| 316 | |
| 317 | private: |
| 318 | FGColumnVector3 vFb; |
| 319 | FGColumnVector3 vM; |
| 320 | |
| 321 | void Debug(int from); |
| 322 | }; |
| 323 | } |
| 324 | #endif |
| 325 |