JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGSurface.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Module: FGSurface.cpp
4  Author: Erik Hofman
5  Date started: 01/15/14
6  Purpose: Base class for all surface properties
7  Called by: GroundReactions
8 
9  ------------- Copyright (C) 2014 Jon S. Berndt (jon@jsbsim.org) -------------
10 
11  This program is free software; you can redistribute it and/or modify it under
12  the terms of the GNU Lesser General Public License as published by the Free Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  version.
15 
16  This program is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
19  details.
20 
21  You should have received a copy of the GNU Lesser General Public License along with
22  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23  Place - Suite 330, Boston, MA 02111-1307, USA.
24 
25  Further information about the GNU Lesser General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27 
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This base class for the GroundReactions class defines methoed and holds data
31 for all surface types.
32 
33 HISTORY
34 --------------------------------------------------------------------------------
35 01/15/14 EMH Created
36 
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 
41 #include "input_output/FGPropertyManager.h"
42 #include "models/FGSurface.h"
43 
44 using namespace std;
45 
46 namespace JSBSim {
47 
48 IDENT(IdSrc,"$Id: FGSurface.cpp,v 1.5 2014/01/28 09:42:21 ehofman Exp $");
49 IDENT(IdHdr,ID_SURFACE);
50 
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 GLOBAL DECLARATIONS
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54 
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 CLASS IMPLEMENTATION
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58 
59 FGSurface::FGSurface(FGFDMExec* fdmex, int number) :
60  contactNumber(number)
61 {
62  eSurfaceType = ctBOGEY;
63  _PropertyManager = fdmex->GetPropertyManager();
64  resetValues();
65 }
66 
67 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 
70 {
71 }
72 
73 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 
76 {
77  staticFFactor = 1.0;
78  rollingFFactor = 1.0;
79  maximumForce = DBL_MAX;
80  bumpiness = 0.0;
81  isSolid = true;
82 }
83 
84 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 
86 void FGSurface::bind(void)
87 {
88  if (!_PropertyManager) return;
89 
90  string base_property_name;
91  string property_name;
92 
93  switch(eSurfaceType) {
94  case ctBOGEY:
95  base_property_name = _CreateIndexedPropertyName("gear/unit", contactNumber);
96  break;
97  case ctSTRUCTURE:
98  base_property_name = _CreateIndexedPropertyName("contact/unit", contactNumber);
99  break;
100  case ctGROUND:
101  base_property_name = "ground";
102  break;
103  default:
104  return;
105  }
106 
107  property_name = base_property_name + "/solid";
108  _PropertyManager->Tie( property_name.c_str(), &isSolid);
109  property_name = base_property_name + "/bumpiness";
110  _PropertyManager->Tie( property_name.c_str(), &bumpiness);
111  property_name = base_property_name + "/maximum-force-lbs";
112  _PropertyManager->Tie( property_name.c_str(), &maximumForce);
113  property_name = base_property_name + "/rolling_friction-factor";
114  _PropertyManager->Tie( property_name.c_str(), &rollingFFactor);
115  property_name = base_property_name + "/static-friction-factor";
116  _PropertyManager->Tie( property_name.c_str(), &staticFFactor);
117 }
118 
119 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 
122 {
123  if (bumpiness < 0.001) return 0.0f;
124 
125  double x = pos[0]*0.1;
126  double y = pos[1]*0.1;
127  x -= floor(x);
128  y -= floor(y);
129  x *= 2*M_PI;
130  y *= 2*M_PI;
131  //now x and y are in the range of 0..2pi
132  //we need a function, that is periodically on 2pi and gives some
133  //height. This is not very fast, but for a beginning.
134  //maybe this should be done by interpolating between some precalculated
135  //values
136  static const float maxGroundBumpAmplitude=0.4;
137  float h = sin(x)+sin(7*x)+sin(8*x)+sin(13*x);
138  h += sin(2*y)+sin(5*y)+sin(9*y*x)+sin(17*y);
139 
140  return h*(1/8.)*bumpiness*maxGroundBumpAmplitude;
141 }
142 
143 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144 
145 string FGSurface::_CreateIndexedPropertyName(const string& Property, int index)
146 {
147  std::ostringstream buf;
148  buf << Property << '[' << index << ']';
149  return buf.str();
150 }
151 
152 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153 
154 string FGSurface::GetSurfaceStrings(string delimeter) const
155 {
156  std::ostringstream buf;
157 
158  buf << "staticFFactor" << delimeter
159  << "rollingFFactor" << delimeter
160  << "maximumForce" << delimeter
161  << "bumpiness" << delimeter
162  << "isSolid";
163 
164  return buf.str();
165 }
166 
167 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168 
169 string FGSurface::GetSurfaceValues(string delimeter) const
170 {
171  std::ostringstream buf;
172 
173  buf << staticFFactor << delimeter
174  << rollingFFactor << delimeter
175  << maximumForce << delimeter
176  << bumpiness << delimeter
177  << (isSolid ? "1" : "0");
178 
179  return buf.str();
180 }
181 
182 } // namespace JSBSim
183 
184 
STL namespace.
FGPropertyManager * GetPropertyManager(void)
Returns a pointer to the property manager object.
Definition: FGFDMExec.cpp:1099
void Tie(const std::string &name, bool *pointer, bool useDefault=true)
Tie a property to an external bool variable.
float GetBumpHeight()
Returns the height of the bump at the provided offset.
Definition: FGSurface.cpp:121
~FGSurface()
Destructor.
Definition: FGSurface.cpp:69
void resetValues(void)
Reset all surface values to a default.
Definition: FGSurface.cpp:75
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:189