getting_started_advanced.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 
36 #include <acado_toolkit.hpp>
37 #include <acado_gnuplot.hpp>
38 
39 
40 int main( )
41 {
43 
44 
45  // INTRODUCE THE VARIABLES:
46  // -------------------------
51 
52  Disturbance R;
53  Control F;
54 
55  Parameter mB;
56  double mW = 50.0;
57  double kS = 20000.0;
58  double kT = 200000.0;
59 
60 
61  // DEFINE A DYNAMIC SYSTEM:
62  // ------------------------
64 
65  f << dot(xB) == vB;
66  f << dot(xW) == vW;
67  f << dot(vB) == ( -kS*xB + kS*xW + F ) / mB;
68  f << dot(vW) == ( kS*xB - (kT+kS)*xW + kT*R - F ) / mW;
69 
70  OutputFcn g;
71  g << xB;
72  g << 500.0*vB + F;
73 
74  DynamicSystem dynSys( f,g );
75 
76 
77  // SETUP THE PROCESS:
78  // ------------------
79  DVector mean( 1 ), amplitude( 1 );
80  mean.setZero( );
81  amplitude.setAll( 50.0 );
82 
83  GaussianNoise myNoise( mean,amplitude );
84 
85  Actuator myActuator( 1,1 );
86 
87  myActuator.setControlNoise( myNoise,0.1 );
88  myActuator.setControlDeadTimes( 0.1 );
89 
90  myActuator.setParameterDeadTimes( 0.2 );
91 // myActuator.setParameterNoise( myNoise,0.1 );
92 
93 
94  mean.setZero( );
95  amplitude.setAll( 0.005 );
96  UniformNoise myOutputNoise1( mean,amplitude );
97 
98  mean.setAll( 10.0 );
99  amplitude.setAll( 50.0 );
100  GaussianNoise myOutputNoise2( mean,amplitude );
101 
102  Sensor mySensor( 2 );
103  mySensor.setOutputNoise( 0,myOutputNoise1,0.1 );
104  mySensor.setOutputNoise( 1,myOutputNoise2,0.1 );
105  mySensor.setOutputDeadTimes( 0.2 );
106 
107 
108  Process myProcess;
109 
110  myProcess.setDynamicSystem( dynSys,INT_RK45 );
111  myProcess.set( ABSOLUTE_TOLERANCE,1.0e-8 );
112 
113  myProcess.setActuator( myActuator );
114  myProcess.setSensor( mySensor );
115 
116  DVector x0( 4 );
117  x0.setZero( );
118  x0( 0 ) = 0.01;
119 
120  myProcess.initializeStartValues( x0 );
121  myProcess.setProcessDisturbance( "road.txt" );
122 
123  myProcess.set( PLOT_RESOLUTION,HIGH );
124 // myProcess.set( CONTROL_PLOTTING,PLOT_NOMINAL );
125 // myProcess.set( PARAMETER_PLOTTING,PLOT_NOMINAL );
126  myProcess.set( OUTPUT_PLOTTING,PLOT_REAL );
127 
128  GnuplotWindow window;
129  window.addSubplot( xB, "Body Position [m]" );
130  window.addSubplot( xW, "Wheel Position [m]" );
131  window.addSubplot( vB, "Body Velocity [m/s]" );
132  window.addSubplot( vW, "Wheel Velocity [m/s]" );
133 
134  window.addSubplot( F,"Damping Force [N]" );
135  window.addSubplot( mB,"Body Mass [kg]" );
136  window.addSubplot( R, "Road Disturbance" );
137  window.addSubplot( g(0),"Output 1" );
138  window.addSubplot( g(1),"Output 2" );
139 
140  myProcess << window;
141 
142 
143  // SIMULATE AND GET THE RESULTS:
144  // -----------------------------
145  VariablesGrid u( 1,0.0,1.0,6 );
146 
147  u( 0,0 ) = 10.0;
148  u( 1,0 ) = -200.0;
149  u( 2,0 ) = 200.0;
150  u( 3,0 ) = 0.0;
151  u( 4,0 ) = 0.0;
152  u( 5,0 ) = 0.0;
153 
154  DVector p( 1 );
155  p(0) = 350.0;
156 
157  DVector pInit( 1 );
158  pInit(0) = 300.0;
159 
160  myProcess.init( 0.0,x0,u.getFirstVector(),pInit );
161  myProcess.run( u,p );
162 
163 
164  VariablesGrid xSim, ySim;
165 
166 // myProcess.getLast( LOG_SIMULATED_DIFFERENTIAL_STATES,xSim );
167 // xSim.print( "Simulated Differential States" );
168 //
169 // myProcess.getLast( LOG_PROCESS_OUTPUT,ySim );
170 // ySim.print( "Process Output" );
171 
172  return 0;
173 }
174 
175 
176 
returnValue setActuator(const Actuator &_actuator)
Definition: process.cpp:254
Allows to setup and evaluate output functions based on SymbolicExpressions.
Definition: output_fcn.hpp:55
returnValue setParameterDeadTimes(const DVector &_deadTimes)
Definition: actuator.cpp:231
Stores a DifferentialEquation together with an OutputFcn.
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
Generates pseudo-random uniformly distributed noise for simulating the Process.
Allows to simulate the behaviour of sensors within the Process.
Definition: sensor.hpp:54
returnValue addSubplot(PlotWindowSubplot &_subplot)
returnValue initializeStartValues(const DVector &_xStart, const DVector &_xaStart=emptyConstVector)
Definition: process.cpp:330
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
DVector getFirstVector() const
returnValue setOutputNoise(const Noise &_noise, double _noiseSamplingTime)
Definition: sensor.cpp:81
Derived & setZero(Index size)
Expression dot(const Expression &arg)
virtual returnValue run(const VariablesGrid &_u, const VariablesGrid &_p=emptyVariablesGrid)
Definition: process.cpp:632
Generates pseudo-random Gaussian noise for simulating the Process.
returnValue setProcessDisturbance(const Curve &_processDisturbance)
Definition: process.cpp:289
void setAll(const T &_value)
Definition: vector.hpp:160
Simulates the process to be controlled based on a dynamic model.
Definition: process.hpp:71
returnValue setControlNoise(const Noise &_noise, double _noiseSamplingTime)
Definition: actuator.cpp:89
Allows to simulate the behaviour of actuators within the Process.
Definition: actuator.hpp:54
Provides an interface to Gnuplot for plotting algorithmic outputs.
returnValue setDynamicSystem(const DynamicSystem &_dynamicSystem, IntegratorType _integratorType=INT_UNKNOWN)
Definition: process.cpp:204
#define R
returnValue setOutputDeadTimes(const DVector &_deadTimes)
Definition: sensor.cpp:125
returnValue setSensor(const Sensor &_sensor)
Definition: process.cpp:271
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.
virtual returnValue init(double _startTime=0.0, const DVector &_xStart=emptyConstVector, const DVector &_uStart=emptyConstVector, const DVector &_pStart=emptyConstVector)
Definition: process.cpp:353
returnValue setControlDeadTimes(const DVector &_deadTimes)
Definition: actuator.cpp:176


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