Skip to content
Snippets Groups Projects
Commit d97c9a2a authored by James Goppert's avatar James Goppert
Browse files

Working on trimming code.

parent d4609cc2
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@
*.notes
.nfs*
src/JSBSim
src/Trim
# Generated Files
setup
......
......@@ -42,8 +42,8 @@ while getopts "c:difrtun:p:vx" opt; do
if ! ( test $email ); then echo email:; read email; fi
year=$(date +%G)
cp ${projectPath}/templates/template.cpp ${class}.cpp
cp ${projectPath}/templates/template.hpp ${class}.hpp
find . -regex ".*${class}.\(cpp\|hpp\)" \
cp ${projectPath}/templates/template.h ${class}.h
find . -regex ".*${class}.\(cpp\|h\)" \
-exec sed -i "
s/@CLASS@/${class}/g;
s/@FIRSTNAME@/${firstName}/g;
......
......@@ -9,7 +9,8 @@ LIBRARY_SOURCES = FGFDMExec.cpp FGJSBBase.cpp
LIBRARY_INCLUDES = FGFDMExec.h FGJSBBase.h
noinst_PROGRAMS = JSBSim
noinst_PROGRAMS = JSBSim Trim
if BUILD_LIBRARIES
......@@ -51,6 +52,22 @@ JSBSim_LDADD = \
simgear/magvar/libcoremag.a \
-lm
Trim_SOURCES = Trim.cpp $(LIBRARY_SOURCES)
Trim_LDADD = \
initialization/libInit.a \
models/libModels.a \
models/flight_control/libFlightControl.a \
models/atmosphere/libAtmosphere.a \
models/propulsion/libPropulsion.a \
input_output/libInputOutput.a \
math/libMath.a \
simgear/props/libProperties.a \
simgear/xml/libExpat.a \
simgear/magvar/libcoremag.a \
-lm
endif
INCLUDES = -I$(top_srcdir)/src
src/Trim 0 → 100755
File added
/*
* Trim.cpp
* Copyright (C) James Goppert 2010 <james.goppert@gmail.com>
*
* Trim.cpp is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Trim.cpp is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FGFDMExec.h"
namespace JSBSim
{
using namespace std;
class ConstrainedFunction
{
public:
virtual void constrain(vector<double> & v) = 0;
virtual double eval(const vector<double> & v) = 0;
};
class FGNelderMead
{
public:
FGNelderMead(ConstrainedFunction * f, const vector<double> & initialGuess,
const vector<double> initialStepSize) :
f(), simplex()
{
nDims = initialGuess.size();
nVerts = nDims + 1;
// construct simplex
for (int vertex=0;vertex<nVerts;vertex++) simplex[vertex] = initialGuess;
for (int dim=0;dim<nDims;dim++)
{
int vertex = dim + 1;
simplex[vertex][dim] += initialStepSize[dim];
}
// find vertex costs
for (int vertex=0;vertex<nVerts;vertex++)
{
f->constrain(simplex[vertex]);
cost[vertex] = f->eval(simplex[vertex]);
}
// sort by cost
// solve
}
private:
int nVerts, nDims;
ConstrainedFunction * f;
vector< vector<double> > simplex;
vector<double> cost;
};
class FGTrimmer : public ConstrainedFunction
{
public:
FGTrimmer(FGFDMExec * fdm) :
myFdm(fdm)
{
}
private:
FGFDMExec * myFdm;
void constrain(vector<double> & v)
{
v[0] = 1;
}
double eval(const vector<double> & v)
{
return 0;
}
};
} // JSBSim
using namespace JSBSim;
int main (int argc, char const* argv[])
{
// load an aircraft
FGFDMExec * fdm = new FGFDMExec;
fdm->LoadModel("../aircraft","../engine","../systems","f16");
// solve for trim condition
FGTrimmer * trimmer = new FGTrimmer(fdm);
int n = 6;
vector<double> initialGuess(n), initialStepSize(n);
for (int i=0;i<n;i++) initialStepSize[i] = 0.1;
for (int i=0;i<n;i++) initialGuess[i] = 0.0;
FGNelderMead * solver = new FGNelderMead(trimmer,initialGuess, initialStepSize);
// cleanup
delete fdm;
delete trimmer;
delete solver;
return 0;
}
// vim:ts=4:sw=4
......@@ -16,7 +16,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "@CLASS@.hpp"
#include "@CLASS@.h"
namespace @NAMESPACE@
{
......
/*
* @CLASS@.hpp
* @CLASS@.h
* Copyright (C) @FIRSTNAME@ @LASTNAME@ @YEAR@ <@EMAIL@>
*
* @CLASS@.hpp is free software: you can redistribute it and/or modify it
* @CLASS@.h is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* @CLASS@.hpp is distributed in the hope that it will be useful, but
* @CLASS@.h is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
......@@ -16,8 +16,8 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef @NAMESPACE@_@CLASS@_HPP
#define @NAMESPACE@_@CLASS@_HPP
#ifndef @NAMESPACE@_@CLASS@_H
#define @NAMESPACE@_@CLASS@_H
namespace @NAMESPACE@
{
......
......@@ -6,6 +6,7 @@ dataDirs="aircraft engine systems"
fileRegex="\(.*\.xml\|.*INSTALL.*\|.*README.*\)"
configFile="configure.in"
echo generating data makefiles for: $dataDirs
topDir=$(pwd)
for dataDir in $dataDirs
do
......@@ -40,6 +41,7 @@ do
done
# update configuration file
echo updating makefile list in: $configFile
cd $topDir
sed -i "/AC_OUTPUT/,/')'/ d" $configFile
echo "AC_OUTPUT( \\" >> $configFile
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment