examples/integrator/pendulum.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_integrators.hpp>
36 
37 
38 
39 int main( ){
40 
42 
43 
44  // Define a Right-Hand-Side:
45  // -------------------------
46  DifferentialState phi; // the angle phi
47  DifferentialState dphi; // the first derivative of phi w.r.t time
48  Control F; // a force acting on the pendulum
49  Parameter l; // the length of the pendulum
50 
51  const double m = 1.0 ; // the mass of the pendulum
52  const double g = 9.81 ; // the gravitational constant
53  const double alpha = 2.0 ; // frictional constant
54 
57 
58  z = sin(phi);
59 
60  f << dot(phi ) == dphi;
61  f << dot(dphi) == -(m*g/l)*z - alpha*dphi + F/(m*l);
62 
63 
64  // DEFINE AN INTEGRATOR:
65  // ---------------------
66 
67  IntegratorRK45 integrator( f );
68 
69  integrator.set( INTEGRATOR_PRINTLEVEL, HIGH );
70  integrator.set( INTEGRATOR_TOLERANCE, 1.0e-6 );
71 
72  // DEFINE INITIAL VALUES:
73  // ----------------------
74 
75  double x_start[2] = { 1.0, 0.0 };
76  double u [1] = { 0.0 };
77  double p [1] = { 1.0 };
78 
79  double t_start = 0.0 ;
80  double t_end = 2.0 ;
81 
82 
83  // START THE INTEGRATION:
84  // ----------------------
85 
86  //integrator.freezeAll();
87  integrator.integrate( t_start, t_end, x_start, 0, p, u );
88 
89 
90  // GET THE RESULTS
91  // ---------------
92 
93  VariablesGrid differentialStates;
94  integrator.getX( differentialStates );
95 
96  differentialStates.print( "x" );
97 
98 
99  return 0;
100 }
101 
102 
103 
USING_NAMESPACE_ACADO IntermediateState sin(const Expression &arg)
returnValue print(std::ostream &stream=std::cout, const char *const name=DEFAULT_LABEL, const char *const startString=DEFAULT_START_STRING, const char *const endString=DEFAULT_END_STRING, uint width=DEFAULT_WIDTH, uint precision=DEFAULT_PRECISION, const char *const colSeparator=DEFAULT_COL_SEPARATOR, const char *const rowSeparator=DEFAULT_ROW_SEPARATOR) const
returnValue getX(DVector &xEnd) const
returnValue set(OptionsName name, int value)
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
Expression dot(const Expression &arg)
Implements the Runge-Kutta-45 scheme for integrating ODEs.
const double t_end
const double t_start
returnValue integrate(double t0, double tend, double *x0, double *xa=0, double *p=0, double *u=0, double *w=0)
Definition: integrator.cpp:207
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:58