crane.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 
36 using namespace std;
38 
39 int main()
40 {
41  //
42  // DEFINE THE VARIABLES:
43  //
44  DifferentialState xT; // the trolley position
45  DifferentialState vT; // the trolley velocity
46  IntermediateState aT; // the trolley acceleration
47  DifferentialState xL; // the cable length
48  DifferentialState vL; // the cable velocity
49  IntermediateState aL; // the cable acceleration
50  DifferentialState phi; // the excitation angle
51  DifferentialState omega; // the angular velocity
52 
53  DifferentialState uT; // trolley velocity control
54  DifferentialState uL; // cable velocity control
55 
56  Control duT;
57  Control duL;
58 
59  //
60  // DEFINE THE PARAMETERS:
61  //
62  const double tau1 = 0.012790605943772;
63  const double a1 = 0.047418203070092;
64  const double tau2 = 0.024695192379264;
65  const double a2 = 0.034087337273386;
66  const double g = 9.81;
67  const double c = 0.0;
68  const double m = 1318.0;
69 
70  //
71  // DEFINE THE MODEL EQUATIONS:
72  //
74  aT = -1.0 / tau1 * vT + a1 / tau1 * uT;
75  aL = -1.0 / tau2 * vL + a2 / tau2 * uL;
76 
77  f << 0 == dot( xT ) - vT;
78  f << 0 == dot( vT ) - aT;
79  f << 0 == dot( xL ) - vL;
80  f << 0 == dot( vL ) - aL;
81  f << 0 == dot( phi ) - omega;
82  f << 0 == dot( omega ) - 1.0/xL*(-g*sin(phi)-aT*cos(phi)
83  -2*vL*omega-c*omega/(m*xL));
84  f << 0 == dot( uT ) - duT;
85  f << 0 == dot( uL ) - duL;
86 
87  //
88  // DEFINE THE OUTPUT MODEL:
89  //
90  OutputFcn h;
91 
92  h << aT;
93  h << aL;
94 
95  //
96  // SET UP THE SIMULATION EXPORT MODULE:
97  //
98 
99  cout << "-----------------------------------------\n Using an equidistant grid:\n-----------------------------------------\n";
100 
101  SIMexport sim( 1, 0.1 );
102 
103  sim.setModel( f );
104  sim.addOutput( h, 5 );
105 
107  sim.set( NUM_INTEGRATOR_STEPS, 5 );
108  sim.setTimingSteps( 10000 );
109 
110  sim.exportAndRun( "crane_export", "init_crane.txt", "controls_crane.txt" );
111 
112 
113  cout << "-----------------------------------------\n Using a provided grid:\n-----------------------------------------\n";
114 
115  DVector Meas(5);
116  Meas(0) = 0.0;
117  Meas(1) = 0.2;
118  Meas(2) = 0.4;
119  Meas(3) = 0.6;
120  Meas(4) = 0.8;
121 
122  SIMexport sim2( 1, 0.1 );
123 
124  sim2.setModel( f );
125  sim2.addOutput( h, Meas );
126 
128  sim2.set( NUM_INTEGRATOR_STEPS, 5 );
129  sim2.setTimingSteps( 10000 );
130 
131  sim2.exportAndRun( "crane_export", "init_crane.txt", "controls_crane.txt" );
132 
133  return 0;
134 }
135 
USING_NAMESPACE_ACADO int main()
Definition: crane.cpp:39
USING_NAMESPACE_ACADO IntermediateState sin(const Expression &arg)
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)
IntermediateState cos(const Expression &arg)
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
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
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:31