extern_model.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 
34 
35 using namespace std;
37 
38 int main()
39 {
40  // Define variables, functions and constants:
41  // ----------------------------------------------------------
44  DifferentialState alpha;
47  DifferentialState dalpha;
48 
49  AlgebraicState ddx;
50  AlgebraicState ddy;
51  AlgebraicState ddalpha;
52  AlgebraicState Fx;
53  AlgebraicState Fy;
54 
55  Control u;
56 
57  DifferentialEquation f1, f2;
58 
59  OutputFcn h;
60 
61  h << Fx;
62  h << Fy;
63 
64  const double m = 2;
65  const double M = 3.5;
66  const double I = 0.1;
67  const double g = 9.81;
68 
69  // Pendulum DAE model in ACADO syntax (semi-explicit):
70  // ----------------------------------------------------------
71  f1 << dot( x ) == dx;
72  f1 << dot( y ) == dy;
73  f1 << dot( alpha ) == dalpha;
74  f1 << dot( dx ) == ddx ;
75  f1 << dot( dy ) == ddy;
76  f1 << dot( dalpha ) == ddalpha;
77 
78  f1 << 0 == m*ddx - (Fx+u);
79  f1 << 0 == m*ddy + m*g - (Fy+u);
80  f1 << 0 == I*ddalpha - M - (Fx+u)*y + (Fy+u)*x;
81  f1 << 0 == ddx + dy*dalpha + y*ddalpha;
82  f1 << 0 == ddy - dx*dalpha - x*ddalpha;
83 
84 
85  // Pendulum DAE model in ACADO syntax (implicit):
86  // ----------------------------------------------------------
87  f2 << 0 == dot( x ) - dx;
88  f2 << 0 == dot( y ) - dy;
89  f2 << 0 == dot( alpha ) - dalpha;
90  f2 << 0 == dot( dx ) - ddx ;
91  f2 << 0 == dot( dy ) - ddy;
92  f2 << 0 == dot( dalpha ) - ddalpha;
93 
94  f2 << 0 == m*ddx - (Fx+u);
95  f2 << 0 == m*ddy + m*g - (Fy+u);
96  f2 << 0 == I*ddalpha - M - (Fx+u)*y + (Fy+u)*x;
97  f2 << 0 == ddx + dy*dalpha + y*ddalpha;
98  f2 << 0 == ddy - dx*dalpha - x*ddalpha;
99 
100  // ----------------------------------------------------------
101  // ----------------------------------------------------------
102  SIMexport sim1( 1, 0.1 );
103 
105  sim1.set( NUM_INTEGRATOR_STEPS, 4 );
107 
108  sim1.setModel( f1 );
109  sim1.addOutput( h, 5 );
110  sim1.setTimingSteps( 10000 );
111 
112  cout << "-----------------------------------------------------------\n Using a Pendulum DAE model in ACADO syntax (semi-explicit):\n-----------------------------------------------------------\n";
113  sim1.exportAndRun( "pendulum_export", "init_externModel.txt", "controls_externModel.txt" );
114 
115 
116  // ----------------------------------------------------------
117  // ----------------------------------------------------------
118  SIMexport sim2( 1, 0.1 );
119 
121  sim2.set( NUM_INTEGRATOR_STEPS, 4 );
123 
124  sim2.setModel( f2 );
125  sim2.addOutput( h, 5 );
126  sim2.setTimingSteps( 10000 );
127 
128  cout << "-----------------------------------------------------------\n Using a Pendulum DAE model in ACADO syntax (implicit):\n-----------------------------------------------------------\n";
129  sim2.exportAndRun( "pendulum_export", "init_externModel.txt", "controls_externModel.txt" );
130 
131 
132  // ----------------------------------------------------------
133  // ----------------------------------------------------------
134  SIMexport sim3( 1, 0.1 );
135 
137  sim3.set( NUM_INTEGRATOR_STEPS, 4 );
139  sim3.set( GENERATE_MAKE_FILE, NO );
140 
141  sim3.setModel( "model", "rhs", "rhs_jac" );
142  sim3.setDimensions(6, 6, 5, 1, 0, 0);
143 
144  sim3.addOutput( "out", "out_jac", 2, 5 );
145  sim3.setTimingSteps( 10000 );
146 
147  cout << "-----------------------------------------------------------\n Using an externally defined Pendulum DAE model:\n-----------------------------------------------------------\n";
148  sim3.exportAndRun( "externModel_export", "init_externModel.txt", "controls_externModel.txt" );
149 
150 
151  return 0;
152 }
153 
uint addOutput(const OutputFcn &outputEquation_, const DVector &measurements)
Allows to setup and evaluate output functions based on SymbolicExpressions.
Definition: output_fcn.hpp:55
#define USING_NAMESPACE_ACADO
virtual returnValue setTimingSteps(uint _timingSteps)
Definition: sim_export.cpp:917
returnValue setModel(const DifferentialEquation &_f)
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
User-interface to automatically generate simulation algorithms for fast optimal control.
Definition: sim_export.hpp:60
USING_NAMESPACE_ACADO int main()
virtual returnValue exportAndRun(const std::string &dirName, const std::string &initStates, const std::string &controls, const std::string &results=std::string("results.txt"), const std::string &ref=std::string("ref.txt"))
Definition: sim_export.cpp:746
#define NO
Definition: acado_types.hpp:53
returnValue setDimensions(uint _NX1, uint _NX2, uint _NX3, uint _NDX, uint _NDX3, uint _NXA, uint _NXA3, uint _NU, uint _NOD, uint _NP)
Expression dot(const Expression &arg)
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:34