FlightGear next
FGSurface.cpp
Go to the documentation of this file.
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
28FUNCTIONAL DESCRIPTION
29--------------------------------------------------------------------------------
30This base class for the GroundReactions class defines methoed and holds data
31for all surface types.
32
33HISTORY
34--------------------------------------------------------------------------------
3501/15/14 EMH Created
36
37%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38INCLUDES
39%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
42#include "models/FGSurface.h"
43
44using namespace std;
45
46namespace JSBSim {
47
48/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49CLASS IMPLEMENTATION
50%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51
52FGSurface::FGSurface(FGFDMExec* fdmex, int number) :
53 contactNumber(number)
54{
55 _PropertyManager = fdmex->GetPropertyManager();
57}
58
59//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60
64
65//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66
68{
69 staticFFactor = 1.0;
70 rollingFFactor = 1.0;
71 maximumForce = DBL_MAX;
72 bumpiness = 0.0;
73 isSolid = true;
74 pos[0] = 0.0;
75 pos[1] = 0.0;
76 pos[2] = 0.0;
77}
78
79//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80
82{
83 if (!_PropertyManager) return;
84
85 string base_property_name;
86 string property_name;
87
88 switch(eSurfaceType) {
89 case ctBOGEY:
90 base_property_name = _CreateIndexedPropertyName("gear/unit", contactNumber);
91 break;
92 case ctSTRUCTURE:
93 base_property_name = _CreateIndexedPropertyName("contact/unit", contactNumber);
94 break;
95 case ctGROUND:
96 base_property_name = "ground";
97 break;
98 default:
99 return;
100 }
101
102 property_name = base_property_name + "/solid";
103 _PropertyManager->Tie( property_name.c_str(), &isSolid);
104 property_name = base_property_name + "/bumpiness";
105 _PropertyManager->Tie( property_name.c_str(), &bumpiness);
106 property_name = base_property_name + "/maximum-force-lbs";
107 _PropertyManager->Tie( property_name.c_str(), &maximumForce);
108 property_name = base_property_name + "/rolling_friction-factor";
109 _PropertyManager->Tie( property_name.c_str(), &rollingFFactor);
110 property_name = base_property_name + "/static-friction-factor";
111 _PropertyManager->Tie( property_name.c_str(), &staticFFactor);
112}
113
114//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115
117{
118 // bump hight might have been manually set
119 if (bumpHeight < DBL_MAX) {
120 float rv = bumpHeight;
121 bumpHeight = DBL_MAX;
122 return rv;
123 }
124 if (bumpiness < 0.001) return 0.0f;
125
126 double x = pos[0]*0.1;
127 double y = pos[1]*0.1;
128 x -= floor(x);
129 y -= floor(y);
130 x *= 2*M_PI;
131 y *= 2*M_PI;
132 //now x and y are in the range of 0..2pi
133 //we need a function, that is periodically on 2pi and gives some
134 //height. This is not very fast, but for a beginning.
135 //maybe this should be done by interpolating between some precalculated
136 //values
137 static const float maxGroundBumpAmplitude=0.4;
138 float h = sin(x)+sin(7*x)+sin(8*x)+sin(13*x);
139 h += sin(2*y)+sin(5*y)+sin(9*y*x)+sin(17*y);
140
141 return h*(1/8.)*bumpiness*maxGroundBumpAmplitude;
142}
143
144//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145
146string FGSurface::_CreateIndexedPropertyName(const string& Property, int index)
147{
148 std::ostringstream buf;
149 buf << Property << '[' << index << ']';
150 return buf.str();
151}
152
153//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154
155string FGSurface::GetSurfaceStrings(string delimeter) const
156{
157 std::ostringstream buf;
158
159 buf << "staticFFactor" << delimeter
160 << "rollingFFactor" << delimeter
161 << "maximumForce" << delimeter
162 << "bumpiness" << delimeter
163 << "isSolid";
164
165 return buf.str();
166}
167
168//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169
170string FGSurface::GetSurfaceValues(string delimeter) const
171{
172 std::ostringstream buf;
173
174 buf << staticFFactor << delimeter
175 << rollingFFactor << delimeter
176 << maximumForce << delimeter
177 << bumpiness << delimeter
178 << (isSolid ? "1" : "0");
179
180 return buf.str();
181}
182
183} // namespace JSBSim
#define M_PI
Definition FGJSBBase.h:50
FGPropertyManager * GetPropertyManager(void)
Returns a pointer to the property manager object.
double rollingFFactor
Definition FGSurface.h:126
FGSurface(FGFDMExec *fdmex, int number=-1)
Constructor.
Definition FGSurface.cpp:52
std::string GetSurfaceValues(std::string delimeter) const
~FGSurface()
Destructor.
Definition FGSurface.cpp:61
std::string GetSurfaceStrings(std::string delimeter) const
float GetBumpHeight()
Returns the height of the bump at the provided offset.
ContactType eSurfaceType
Definition FGSurface.h:124
void resetValues(void)
Reset all surface values to a default.
Definition FGSurface.cpp:67
void bind(void)
Definition FGSurface.cpp:81