examples/integration_algorithm/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 
36 #include <acado_gnuplot.hpp>
37 
38 using namespace std;
39 
41 
42 int main( )
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; // friction 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  // DEFINE INITIAL VALUES:
64  // ----------------------
65 
66  DVector xStart( 2 );
67  xStart(0) = 1.0;
68  xStart(1) = 0.0;
69 
70  DVector xa;
71 
72  DVector u( 1 );
73  u(0) = 0.0;
74 
75  DVector p( 1 );
76  p(0) = 1.0;
77 
78  double tStart = 0.0;
79  double tEnd = 2.0;
80 
81  Grid timeHorizon( tStart,tEnd );
82 
83  // DEFINE AN INTEGRATOR:
84  // ---------------------
85 
86  IntegrationAlgorithm intAlg;
87 
88  intAlg.addStage( f, timeHorizon, INT_RK45 );
89 
90  //intAlg.set( INTEGRATOR_TYPE, INT_RK45 );
91  intAlg.set( INTEGRATOR_PRINTLEVEL, HIGH );
92  intAlg.set( INTEGRATOR_TOLERANCE, 1.0e-6 );
93 
94  // START THE INTEGRATION:
95  // ----------------------
96 
97  intAlg.integrate( timeHorizon, xStart,xa,p,u );
98 
99  // GET THE RESULTS
100  // ---------------
101 
102  VariablesGrid differentialStates;
103  intAlg.getX( differentialStates );
104 
105  cout << "x = " << endl << differentialStates << endl;
106 
107  return 0;
108 }
109 
110 
111 
USING_NAMESPACE_ACADO IntermediateState sin(const Expression &arg)
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
Allows to conveniently handle (one-dimensional) grids consisting of time points.
Definition: grid.hpp:58
returnValue getX(DVector &xEnd) const
returnValue integrate(VariablesGrid *x, VariablesGrid *xa, VariablesGrid *p, VariablesGrid *u, VariablesGrid *w)
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
User-interface to integrate a DynamicSystem, possibly over multiple stages.
Expression dot(const Expression &arg)
virtual returnValue addStage(const DynamicSystem &dynamicSystem_, const Grid &stageIntervals, const IntegratorType &integratorType_=INT_UNKNOWN)
USING_NAMESPACE_ACADO int main()
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