active_damping.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 
39 int main( ){
40 
42 
43 
44  // INTRODUCE THE VARIABLES:
45  // -------------------------
46  DifferentialState xBody;
47  DifferentialState xWheel;
48  DifferentialState vBody;
49  DifferentialState vWheel;
50 
51  Disturbance roadExcitation;
52 
53  Control dampingForce;
54 
55  double mBody = 350.0;
56  double mWheel = 50.0;
57  double kSpring = 20000.0;
58  double kTire = 200000.0;
59 
60 
61  // DEFINE A DIFFERENTIAL EQUATION:
62  // -------------------------------
64 
65  f << dot(xBody) == vBody;
66  f << dot(xWheel) == vWheel;
67  f << dot(vBody) == ( -kSpring*xBody + kSpring*xWheel + dampingForce ) / mBody;
68  f << dot(vWheel) == ( -kTire*xBody - (kTire+kSpring)*xWheel + kTire*roadExcitation - dampingForce ) / mWheel;
69 
70 
71  // DEFINE LEAST SQUARE FUNCTION:
72  // -----------------------------
73  Function h;
74 
75  h << xBody;
76  h << xWheel;
77  h << vBody;
78  h << vWheel;
79 
80  DMatrix S(4,4);
81  DVector r(4);
82 
83  S.setIdentity();
84  S(0,0) = 10.0;
85  S(1,1) = 10.0;
86 
87  r.setAll( 0.0 );
88 
89 
90  // DEFINE AN OPTIMAL CONTROL PROBLEM:
91  // ----------------------------------
92  const double t_start = 0.0;
93  const double t_end = 1.0;
94 
95  OCP ocp( t_start, t_end, 20 );
96 
97  ocp.minimizeLSQ( S, h, r );
98  //ocp.minimizeLagrangeTerm( 0.5*(10.0*xBody*xBody + 10.0*xWheel*xWheel + vBody*vBody + vWheel*vWheel ) );
99 
100  ocp.subjectTo( f );
101 
102  ocp.subjectTo( AT_START, xBody == 0.01 );
103  ocp.subjectTo( AT_START, xWheel == 0.0 );
104  ocp.subjectTo( AT_START, vBody == 0.0 );
105  ocp.subjectTo( AT_START, vWheel == 0.0 );
106 
107  ocp.subjectTo( -500.0 <= dampingForce <= 500.0 );
108  ocp.subjectTo( roadExcitation == 0.0 );
109 
110 
111  // Additionally, flush a plotting object
112  GnuplotWindow window1;//( PLOT_AT_EACH_ITERATION );
113  window1.addSubplot( xBody, "Body Position [m]" );
114  window1.addSubplot( xWheel,"Wheel Position [m]" );
115  window1.addSubplot( vBody, "Body Velocity [m/s]" );
116  window1.addSubplot( vWheel,"Wheel Velocity [m/s]" );
117 
118  window1.addSubplot( dampingForce,"Damping Force [N]" );
119  window1.addSubplot( roadExcitation,"Road Excitation [m]" );
120 
121 
122  // DEFINE AN OPTIMIZATION ALGORITHM AND SOLVE THE OCP:
123  // ---------------------------------------------------
124  OptimizationAlgorithm algorithm(ocp);
125 
126  algorithm << window1;
127 
128  // algorithm.set( HESSIAN_APPROXIMATION, EXACT_HESSIAN );
129  // algorithm.set( HESSIAN_APPROXIMATION, GAUSS_NEWTON );
131 
132  //algorithm.set( INTEGRATOR_TOLERANCE, 1e-8 );
133  algorithm.set( KKT_TOLERANCE, 1e-6 );
134  //algorithm.set( GLOBALIZATION_STRATEGY, GS_FULLSTEP );
135  //algorithm.set( MAX_NUM_ITERATIONS, 1 );
136 
137  algorithm.solve();
138 
139 
140  return 0;
141 }
142 
143 
144 
Allows to setup and evaluate a general function based on SymbolicExpressions.
Definition: function_.hpp:59
User-interface to formulate and solve optimal control problems and static NLPs.
int main()
#define USING_NAMESPACE_ACADO
returnValue subjectTo(const DifferentialEquation &differentialEquation_)
Definition: ocp.cpp:153
returnValue addSubplot(PlotWindowSubplot &_subplot)
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
returnValue minimizeLSQ(const DMatrix &S, const Function &h, const DVector &r)
Definition: ocp.cpp:244
Data class for defining optimal control problems.
Definition: ocp.hpp:89
Expression dot(const Expression &arg)
const double t_end
const double t_start
void setAll(const T &_value)
Definition: vector.hpp:160
Provides an interface to Gnuplot for plotting algorithmic outputs.
virtual returnValue solve()
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:27