| 1 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 | |
| 3 | Header: FGExternalReactions.h |
| 4 | Author: David P. Culp |
| 5 | Date started: 17/11/06 |
| 6 | |
| 7 | ------------- Copyright (C) 2006 David P. Culp ([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 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 | 17/11/06 DPC Created |
| 29 | |
| 30 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 31 | SENTRY |
| 32 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 33 | |
| 34 | #ifndef FGEXTERNALREACTIONS_H |
| 35 | #define FGEXTERNALREACTIONS_H |
| 36 | |
| 37 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 38 | INCLUDES |
| 39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 40 | |
| 41 | #include <vector> |
| 42 | #include "FGModel.h" |
| 43 | #include "math/FGColumnVector3.h" |
| 44 | |
| 45 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 46 | FORWARD DECLARATIONS |
| 47 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 48 | |
| 49 | namespace JSBSim { |
| 50 | |
| 51 | class Element; |
| 52 | class FGExternalForce; |
| 53 | |
| 54 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 55 | CLASS DOCUMENTATION |
| 56 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 57 | |
| 58 | /** Manages the external and/or arbitrary forces and moments. |
| 59 | |
| 60 | The external reactions capability in JSBSim really should be named |
| 61 | "arbitrary forces and moments", because this feature can be used to model a |
| 62 | wide variety of forces and moments that act on a vehicle. Some examples |
| 63 | include: parachutes, catapult, arresting hook, and tow line. |
| 64 | |
| 65 | This class acts similarly to the other "manager classes" (FGPropulsion, |
| 66 | FGFCS, FGGroundReactions, FGAerodynamics) because it manages collections of |
| 67 | constituent elements. The individual forces and moments are implemented with |
| 68 | the FGExternalForce class. |
| 69 | |
| 70 | The format of the <em>optional</em> external reactions section in the config |
| 71 | file is as follows: |
| 72 | |
| 73 | @code |
| 74 | <external_reactions> |
| 75 | |
| 76 | <!-- Interface properties, a.k.a. property declarations --> |
| 77 | <property> ... </property> |
| 78 | |
| 79 | <force name="name" frame="BODY | LOCAL | WIND"> |
| 80 | ... |
| 81 | </force> |
| 82 | <moment name="name" frame="BODY | LOCAL | WIND"> |
| 83 | ... |
| 84 | </moment> |
| 85 | |
| 86 | <!-- Additional force and moment definitions may follow --> |
| 87 | <force name="name" frame="BODY | LOCAL | WIND"> |
| 88 | ... |
| 89 | </force> |
| 90 | <moment name="name" frame="BODY | LOCAL | WIND"> |
| 91 | ... |
| 92 | </moment> |
| 93 | |
| 94 | </external_reactions> |
| 95 | @endcode |
| 96 | |
| 97 | See the FGExternalForce class for more information on the format of the |
| 98 | force and moment specifications. |
| 99 | |
| 100 | When force or moment elements are encountered in the configuration file, a |
| 101 | new instance of the FGExternalForce class is created and a pointer to the |
| 102 | class is pushed onto the Forces vector. |
| 103 | |
| 104 | This class is one of a few of the manager classes that allows properties to |
| 105 | be "declared". In code, these are represented by the |
| 106 | <em>interface_properties</em> vector. Properties that have not yet been |
| 107 | created in an already parsed section of the configuration file and that are |
| 108 | used in the definition of an external force or moment should be declared in |
| 109 | the external_reactions section because they will not be created |
| 110 | automatically, and so would cause an error, since the property cannot be |
| 111 | found to exist. |
| 112 | |
| 113 | See the FGExternalForce documentation for details on how forces and moments |
| 114 | are actually calculated. |
| 115 | */ |
| 116 | |
| 117 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 118 | CLASS DECLARATION |
| 119 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 120 | |
| 121 | class FGExternalReactions : public FGModel |
| 122 | { |
| 123 | public: |
| 124 | /** Constructor. |
| 125 | @param fdmex pointer to the main executive class. |
| 126 | */ |
| 127 | FGExternalReactions(FGFDMExec* fdmex); |
| 128 | |
| 129 | /** Destructor. |
| 130 | Within the destructor the Forces and interface_properties vectors are |
| 131 | cleared out and the items pointed to are deleted. |
| 132 | */ |
| 133 | ~FGExternalReactions(void) override; |
| 134 | |
| 135 | bool InitModel(void) override; |
| 136 | |
| 137 | /** Sum all the constituent forces for this cycle. |
| 138 | Can pass in a value indicating if the executive is directing the simulation to Hold. |
| 139 | @param Holding if true, the executive has been directed to hold the sim from |
| 140 | advancing time. Some models may ignore this flag, such as the Input |
| 141 | model, which may need to be active to listen on a socket for the |
| 142 | "Resume" command to be given. |
| 143 | @return true always. */ |
| 144 | bool Run(bool Holding) override; |
| 145 | |
| 146 | /** Loads the external forces from the XML configuration file. |
| 147 | If the external_reactions section is encountered in the vehicle configuration |
| 148 | file, this Load() method is called. All external forces will be parsed, and |
| 149 | a FGExternalForce object will be instantiated for each force definition. |
| 150 | @param el a pointer to the XML element holding the external reactions definition. |
| 151 | */ |
| 152 | bool Load(Element* el) override; |
| 153 | |
| 154 | /** Retrieves the total forces defined in the external reactions. |
| 155 | @return the total force in pounds. |
| 156 | */ |
| 157 | const FGColumnVector3& GetForces(void) const {return vTotalForces;} |
| 158 | double GetForces(int idx) const {return vTotalForces(idx);} |
| 159 | |
| 160 | /** Retrieves the total moment resulting from the forces defined in the external reactions. |
| 161 | @return the total moment in foot-pounds. |
| 162 | */ |
| 163 | const FGColumnVector3& GetMoments(void) const {return vTotalMoments;} |
| 164 | double GetMoments(int idx) const {return vTotalMoments(idx);} |
| 165 | |
| 166 | private: |
| 167 | |
| 168 | std::vector <FGExternalForce*> Forces; |
| 169 | //unsigned int numForces; |
| 170 | FGColumnVector3 vTotalForces; |
| 171 | FGColumnVector3 vTotalMoments; |
| 172 | |
| 173 | void bind(void); |
| 174 | void Debug(int from) override; |
| 175 | }; |
| 176 | } |
| 177 | //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 178 | #endif |