dev_simple_parameter_estimation.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
27 
35 #include <acado_toolkit.hpp>
36 #include <acado_gnuplot.hpp>
37 
38 
39 int main( ){
40 
42 
43 
44  DifferentialState phi, omega; // the states of the pendulum
45  Parameter l, alpha ; // its length and the friction
46  const double g = 9.81 ; // the gravitational constant
47  DifferentialEquation f ; // the model equations
48  Function h ; // the measurement function
49 
50  VariablesGrid measurements; // read the measurements
51  measurements = readFromFile( "data.txt" ); // from a file.
52 
53 // --------------------------------------
54  OCP ocp(measurements.getTimePoints()); // construct an OCP
55  h << phi ; // the state phi is measured
56  ocp.minimizeLSQ( h, measurements ) ; // fit h to the data
57 
58  f << dot(phi ) == omega ; // a symbolic implementation
59  f << dot(omega) == -(g/l) *sin(phi ) // of the model
60  - alpha*omega ; // equations
61 
62  ocp.subjectTo( f ); // solve OCP s.t. the model,
63  ocp.subjectTo( 0.0 <= alpha <= 4.0 ); // the bounds on alpha
64  ocp.subjectTo( 0.0 <= l <= 2.0 ); // and the bounds on l.
65 // --------------------------------------
66 
67  GnuplotWindow window;
68  window.addSubplot( phi , "The angle phi", "time [s]", "angle [rad]" );
69  window.addSubplot( omega, "The angular velocity dphi" );
70  window.addData( 0, measurements(0) );
71 
72  ParameterEstimationAlgorithm algorithm(ocp); // the parameter estimation
73  algorithm << window;
74  algorithm.solve(); // algorithm solves the problem.
75 
76 
77  return 0;
78 }
79 
80 
81 
USING_NAMESPACE_ACADO IntermediateState sin(const Expression &arg)
Allows to setup and evaluate a general function based on SymbolicExpressions.
Definition: function_.hpp:59
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
returnValue addSubplot(PlotWindowSubplot &_subplot)
returnValue readFromFile(real_t *data, int nrow, int ncol, const char *datafilename)
User-interface to formulate and solve parameter estimation problems.
Data class for defining optimal control problems.
Definition: ocp.hpp:89
virtual returnValue addData(uint idx, const VariablesGrid &_newData)
Expression dot(const Expression &arg)
Provides an interface to Gnuplot for plotting algorithmic outputs.
virtual returnValue solve()
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:32