process.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 
35 
36 #ifdef WIN32
37 #define round( value ) floor( value + 0.5 )
38 #endif
39 
41 
42 
43 // #define SIM_DEBUG
44 
45 
46 //
47 // PUBLIC MEMBER FUNCTIONS:
48 //
49 
51 {
52  setupOptions( );
53  setupLogging( );
54 
55  nDynSys = 0;
56  dynamicSystems = 0;
57 
59 
60  actuator = 0;
61  sensor = 0;
62 
64 
65  lastTime = 0.0;
66 
68 }
69 
70 
71 Process::Process( const DynamicSystem& _dynamicSystem,
72  IntegratorType _integratorType
74 {
75  setupOptions( );
76  setupLogging( );
77 
78  nDynSys = 0;
79  dynamicSystems = 0;
80 
82 
83  actuator = 0;
84  sensor = 0;
85 
87 
88  if ( _dynamicSystem.getNumDynamicEquations( ) > 0 )
89  {
90  returnValue returnvalue = setDynamicSystem( _dynamicSystem,_integratorType );
91  ASSERT( returnvalue == SUCCESSFUL_RETURN );
92  }
93 
94  lastTime = 0.0;
95 
97 }
98 
99 
101 {
102  x = rhs.x;
103  xa = rhs.xa;
104 
105  if ( rhs.dynamicSystems != 0 )
106  {
107  nDynSys = rhs.nDynSys;
108  dynamicSystems = (DynamicSystem**) calloc( rhs.nDynSys,sizeof(DynamicSystem*) );
109  for( uint i=0; i<rhs.nDynSys; ++i )
110  dynamicSystems[i] = new DynamicSystem( *(rhs.dynamicSystems[i]) );
111  }
112  else
113  {
114  nDynSys = 0;
115  dynamicSystems = 0;
116  }
117 
118  if ( rhs.integrationMethod != 0 )
120  else
121  integrationMethod = 0;
122 
123  if ( rhs.actuator != 0 )
124  actuator = new Actuator( *(rhs.actuator) );
125  else
126  actuator = 0;
127 
128  if ( rhs.sensor != 0 )
129  sensor = new Sensor( *(rhs.sensor) );
130  else
131  sensor = 0;
132 
133  if ( rhs.processDisturbance != 0 )
135  else
136  processDisturbance = 0;
137 
138  y = rhs.y;
139 
140  lastTime = rhs.lastTime;
141 }
142 
143 
145 {
146  clear( );
147 }
148 
149 
151 {
152  if ( this != &rhs )
153  {
154  clear( );
155 
157 
158  x = rhs.x;
159  xa = rhs.xa;
160 
161  if ( rhs.dynamicSystems != 0 )
162  {
163  nDynSys = rhs.nDynSys;
164  dynamicSystems = (DynamicSystem**) calloc( rhs.nDynSys,sizeof(DynamicSystem*) );
165  for( uint i=0; i<rhs.nDynSys; ++i )
166  dynamicSystems[i] = new DynamicSystem( *(rhs.dynamicSystems[i]) );
167  }
168  else
169  {
170  nDynSys = 0;
171  dynamicSystems = 0;
172  }
173 
174  if ( rhs.integrationMethod != 0 )
176  else
177  integrationMethod = 0;
178 
179  if ( rhs.actuator != 0 )
180  actuator = new Actuator( *(rhs.actuator) );
181  else
182  actuator = 0;
183 
184  if ( rhs.sensor != 0 )
185  sensor = new Sensor( *(rhs.sensor) );
186  else
187  sensor = 0;
188 
189  if ( rhs.processDisturbance != 0 )
191  else
192  processDisturbance = 0;
193 
194  y = rhs.y;
195 
196  lastTime = rhs.lastTime;
197  }
198 
199  return *this;
200 }
201 
202 
203 
205  IntegratorType _integratorType
206  )
207 {
208  if ( _dynamicSystem.hasImplicitSwitches( ) == BT_TRUE )
210 
211  // setup simulation algorithm
212  if ( integrationMethod != 0 )
213  delete integrationMethod;
214 
215  integrationMethod = new ShootingMethod( this );
216 
217  Grid dummy( 0.0, 1.0 ); // bad idea ... QUICK HACK
218 
219  addStage( _dynamicSystem, dummy, _integratorType );
220 
221 
222  integratorType = _integratorType; // weird hack -- make clean later.
223 
224 // NOTE: THE "integratorType" can
225 // change during the use of the process, it might be better to load the integrator type from the options
226 // every time the routine "simulate" is called. This enables the user to change options online.
227 // (SORRY, THIS IS NOT YET IMPLEMENTED - AT THE MOMENT THE "integratorType" GETS LOST.)
228 
229  y.init( _dynamicSystem.getNumOutputs( ),1 );
230  y.setZero( );
231 
233 
234  return SUCCESSFUL_RETURN;
235 }
236 
237 
239  IntegratorType _integratorType
240  )
241 {
242  // setup simulation algorithm
243  if ( integrationMethod == 0 )
244  return setDynamicSystem( _dynamicSystem,_integratorType );
245 
246  if ( getNumStages( ) == 0 )
247  return setDynamicSystem( _dynamicSystem,_integratorType );
248  else
250 }
251 
252 
253 
255  )
256 {
257  if ( _actuator.isDefined( ) == BT_TRUE )
258  {
259  if ( actuator != 0 )
260  *actuator = _actuator;
261  else
262  actuator = new Actuator( _actuator );
263 
265  }
266 
267  return SUCCESSFUL_RETURN;
268 }
269 
270 
272  )
273 {
274  if ( _sensor.isDefined( ) == BT_TRUE )
275  {
276  if ( sensor != 0 )
277  *sensor = _sensor;
278  else
279  sensor = new Sensor( _sensor );
280 
282  }
283 
284  return SUCCESSFUL_RETURN;
285 }
286 
287 
288 
290  )
291 {
292  if ( processDisturbance != 0 )
293  *processDisturbance = _processDisturbance;
294  else
295  processDisturbance = new Curve( _processDisturbance );
296 
298 
299  return SUCCESSFUL_RETURN;
300 }
301 
302 
304  )
305 {
306  if ( _processDisturbance.isEmpty( ) == BT_TRUE )
308 
309  Curve _processDisturbanceCurve;
310  _processDisturbanceCurve.add( _processDisturbance );
311 
312  return setProcessDisturbance( _processDisturbanceCurve );
313 }
314 
315 
316 returnValue Process::setProcessDisturbance( const char* _processDisturbance
317  )
318 {
319  VariablesGrid _processDisturbanceFromFile;
320  _processDisturbanceFromFile.read( _processDisturbance );
321 
322  if ( _processDisturbanceFromFile.isEmpty( ) == BT_TRUE )
324 
325  return setProcessDisturbance( _processDisturbanceFromFile );
326 }
327 
328 
329 
331  const DVector& _xaStart
332  )
333 {
334  x = _xStart;
335 
336  if ( _xaStart.getDim( ) > 0 )
337  xa = _xaStart;
338 
340 
341  return SUCCESSFUL_RETURN;
342 }
343 
344 
346  )
347 {
348  return initializeStartValues( x,_xaStart );
349 }
350 
351 
352 
353 returnValue Process::init( double _startTime,
354  const DVector& _xStart,
355  const DVector& _uStart,
356  const DVector& _pStart
357  )
358 {
359  DVector uStart;
360  DVector pStart;
361 
362  /* 1) Assign values */
363  lastTime = _startTime;
364 
365  if ( _xStart.getDim( ) > 0 )
366  x = _xStart;
367  else
368  {
369  if ( x.getDim() == 0 )
370  {
371  x.init( getNX() );
372  x.setZero( );
373  }
374  }
375 
376  if ( ( xa.getDim( ) == 0 ) && ( getNXA( ) > 0 ) )
377  {
378  xa.init( getNXA() );
379  xa.setZero( );
380  }
381 
382  if ( _uStart.getDim( ) > 0 )
383  uStart = _uStart;
384  else
385  {
386  uStart.init( getNU() );
387  uStart.setZero( );
388  }
389 
390  if ( _pStart.getDim( ) > 0 )
391  pStart = _pStart;
392  else
393  {
394  pStart.init( getNP() );
395  pStart.setZero( );
396  }
397 
398 
399  #ifdef SIM_DEBUG
400  uStart.print("uStart(0)");
401  #endif
402 
403 
404  DynamicSystem* dynSys = dynamicSystems[0];
405  OutputFcn outputFcn = dynSys->getOutputFcn( );
406 
407  /* 2) Consistency checks. */
408  if ( getNumStages( ) == 0 )
410 
411  if ( getNX( ) != x.getDim( ) )
413 
414  if ( getNXA( ) != xa.getDim( ) )
416 
417  if ( hasActuator( ) == BT_TRUE )
418  {
419  if ( actuator->getNU( ) != getNU( ) )
421 
422  if ( actuator->getNP( ) != getNP( ) )
424 
425  if ( dynSys->isDiscretized( ) == BT_TRUE )
426  {
427  if ( acadoIsInteger( actuator->getSamplingTime( ) / dynSys->getSampleTime( ) ) == BT_FALSE )
429  }
430  }
431 
432  if ( hasSensor( ) == BT_TRUE )
433  {
434  if ( sensor->getNY( ) != getNY( ) )
436 
437  if ( dynSys->isDiscretized( ) == BT_TRUE )
438  {
439  if ( acadoIsInteger( sensor->getSamplingTime( ) / dynSys->getSampleTime( ) ) == BT_FALSE )
441  }
442  }
443 
444  if ( hasProcessDisturbance( ) == BT_TRUE )
445  {
446  for( uint i=0; i<getNumStages( ); ++i )
447  if ( (int) getNW( i ) > processDisturbance->getDim( ) )
449 
450  if ( processDisturbance->isInTimeDomain( _startTime ) == BT_FALSE )
452  }
453  else
454  {
455  if ( getNW( ) > 0 )
457  }
458 
459 
460  /* 3) Initialize all sub-blocks. */
461  if ( hasActuator( ) == BT_TRUE )
462  if ( actuator->init( _startTime,_uStart,_pStart ) != SUCCESSFUL_RETURN )
464 
465  if ( hasSensor( ) == BT_TRUE )
466  if ( sensor->init( _startTime ) != SUCCESSFUL_RETURN )
468 
469 
470  /* 4) Evalute output function with initial values */
471  Grid currentGrid( 1 );
472  currentGrid.setTime( _startTime );
473 
474  // get process disturbances
475  DVector _wStart;
476 
477  if ( hasProcessDisturbance( ) == BT_TRUE )
478  {
479  if ( processDisturbance->evaluate( _startTime,_wStart ) != SUCCESSFUL_RETURN )
481  }
482 
483  if ( outputFcn.isDefined( ) == BT_TRUE )
484  {
485  // y = outputFcn(x,xa,p,u,w)
486  y.init( dynSys->getNumOutputs( ),currentGrid,VT_OUTPUT );
487 
488  DVector yTmp( dynSys->getNumOutputs( ) );
489  // yTmp = outputFcn.evaluate( 0, _startTime, x, xa, _pStart, _uStart, _wStart );
490 
491  y.setVector( 0,yTmp );
492  }
493  else
494  {
495  // y = x
496  y.init( _xStart.getDim( ),currentGrid,VT_OUTPUT );
497  y.setVector( 0,_xStart );
498  }
499 
500 
501  setStatus( BS_READY );
502 
503  return SUCCESSFUL_RETURN;
504 }
505 
506 
507 
509  const VariablesGrid& _p
510  )
511 {
512  /* Consistency checks. */
513  if ( getStatus( ) != BS_READY )
515 
516  if ( checkInputConsistency( _u,_p ) != SUCCESSFUL_RETURN )
518 
519  if ( acadoIsEqual( _u.getFirstTime( ),lastTime ) == BT_FALSE )
521 
522 
523  /* 0) Log original process inputs */
524  if ( _u.isEmpty( ) == BT_FALSE )
526 
527  if ( _p.isEmpty( ) == BT_FALSE )
529 
530 
531  /* 1) Get actuator outputs. */
532  VariablesGrid uAct = _u;
533  VariablesGrid pAct = _p;
534 
535  if ( hasActuator( ) == BT_TRUE )
536  {
537  if ( actuator->step( uAct,pAct ) != SUCCESSFUL_RETURN )
539  }
540 
541 // printf("uAct:\n" );
542 // uAct.print();
543 // printf("pAct:\n" );
544 // pAct.print();
545 
546  /* 2) Get process disturbances. */
547  VariablesGrid _w;
548 
549  if ( hasProcessDisturbance( ) == BT_TRUE )
550  {
553  }
554 // _w.print( "read w" );
555 
556  /* 3) Call SimulationByIntegration and evaluate output function. */
557  Grid commonGrid, tmpGrid;
558 
559  uAct.getGrid( commonGrid );
560 
561  if ( hasProcessDisturbance( ) == BT_TRUE )
562  {
563  _w.getGrid( tmpGrid );
564  commonGrid & tmpGrid;
565  }
566 // commonGrid.print();
567 
568  uAct.refineGrid( commonGrid );
569  pAct.refineGrid( commonGrid );
570 
571  if ( hasProcessDisturbance( ) == BT_TRUE )
572  _w.refineGrid( commonGrid );
573 
574 // _w.print( "passed w" );
575  if ( simulate( uAct,pAct,_w ) != SUCCESSFUL_RETURN )
577 
578 // y.print("ySim");
579 
580  /* 4) Get sensor output. */
581  if ( hasSensor( ) == BT_TRUE )
582  {
583  if ( sensor->step( y ) != SUCCESSFUL_RETURN )
585  }
586 
587 // y.print("ySens");
589  //logCollection.setLast( LOG_SAMPLED_PROCESS_OUTPUT,y );
590 
591  /* 5) Update lastTime. */
592  lastTime = _u.getLastTime( );
593 
594  // plot results
595  replot( PLOT_AT_END );
596 
597  return SUCCESSFUL_RETURN;
598 }
599 
600 
602  const DVector& _p
603  )
604 {
605  VariablesGrid pTmp( _p.getDim( ),_u.getFirstTime( ),_u.getLastTime( ),_u.getNumPoints(),VT_PARAMETER );
606  for( uint i=0; i<_u.getNumPoints(); ++i )
607  pTmp.setVector( i,_p );
608 
609  return step( _u,pTmp );
610 }
611 
612 
613 returnValue Process::step( double startTime,
614  double endTime,
615  const DVector& _u,
616  const DVector& _p
617  )
618 {
619  VariablesGrid uTmp( _u.getDim( ),startTime,endTime,2,VT_CONTROL );
620  uTmp.setVector( 0,_u );
621  uTmp.setVector( 1,_u );
622 
623  VariablesGrid pTmp( _p.getDim( ),startTime,endTime,2,VT_PARAMETER );
624  pTmp.setVector( 0,_p );
625  pTmp.setVector( 1,_p );
626 
627  return step( uTmp,pTmp );
628 }
629 
630 
631 
633  const VariablesGrid& _p
634  )
635 {
636  // Ensure that process is initialised
637  if ( getStatus( ) == BS_NOT_INITIALIZED )
638  {
639  if ( init( _u.getFirstTime( ),x,_u.getFirstVector( ),_p.getFirstVector( ) ) != SUCCESSFUL_RETURN )
641  }
642 
643  return step( _u,_p );
644 }
645 
646 
648  const DVector& _p
649  )
650 {
651  VariablesGrid pTmp( _p.getDim( ),_u.getFirstTime( ),_u.getLastTime( ),_u.getNumPoints(),VT_PARAMETER );
652  for( uint i=0; i<_u.getNumPoints(); ++i )
653  pTmp.setVector( i,_p );
654 
655  return run( _u,pTmp );
656 }
657 
658 
659 returnValue Process::run( double startTime,
660  double endTime,
661  const DVector& _u,
662  const DVector& _p
663  )
664 {
665  VariablesGrid uTmp( _u.getDim( ),startTime,endTime,2,VT_CONTROL );
666  uTmp.setVector( 0,_u );
667  uTmp.setVector( 1,_u );
668 
669  VariablesGrid pTmp( _p.getDim( ),startTime,endTime,2,VT_PARAMETER );
670  pTmp.setVector( 0,_p );
671  pTmp.setVector( 1,_p );
672 
673  return run( uTmp,pTmp );
674 }
675 
676 
677 
679  )
680 {
681  int controlPlotting, parameterPlotting, outputPlotting;
682 
683  get( CONTROL_PLOTTING, controlPlotting );
684  get( PARAMETER_PLOTTING, parameterPlotting );
685  get( OUTPUT_PLOTTING, outputPlotting );
686 
687  if ( (ProcessPlotName)controlPlotting == PLOT_NOMINAL )
689  else
691 
692  if ( (ProcessPlotName)parameterPlotting == PLOT_NOMINAL )
694  else
696 
697  if ( (ProcessPlotName)outputPlotting == PLOT_NOMINAL )
699  else
701 
702  return Plotting::replot( _frequency );
703 }
704 
705 
706 
707 //
708 // PROTECTED MEMBER FUNCTIONS:
709 //
710 
712 {
713  //printf( "Process::setupOptions( ) called.\n" );
714 
719 
720  // add integration options
725 
726  // add integrator options
729  addOption( ABSOLUTE_TOLERANCE , 1.0e-12 );
740 
741  return SUCCESSFUL_RETURN;
742 }
743 
744 
746 {
748 
751  tmp.addItem( LOG_PARAMETERS );
752  tmp.addItem( LOG_CONTROLS );
753  tmp.addItem( LOG_DISTURBANCES );
755 
758 
761 
768 
770 
771  addLogRecord( tmp );
772 
773  return SUCCESSFUL_RETURN;
774 }
775 
776 
777 
779  const Grid &stageIntervals,
780  const IntegratorType &_integratorType
781  )
782 {
783  if ( _dynamicSystem.hasImplicitSwitches( ) == BT_TRUE )
785 
786  // add dynamic system to list...
787  ++nDynSys;
788 
790  dynamicSystems[ nDynSys-1 ] = new DynamicSystem( _dynamicSystem );
791 
792  // ... and add stage to integration algorithm
793  return integrationMethod->addStage( _dynamicSystem, stageIntervals, _integratorType );
794 }
795 
796 
798 {
799  if ( dynamicSystems != 0 )
800  {
801  for( uint i=0; i<nDynSys; ++i )
802  delete dynamicSystems[i];
803 
804  free( dynamicSystems );
805  dynamicSystems = 0;
806  }
807 
808  nDynSys = 0;
809 
810  if ( integrationMethod != 0 )
811  delete integrationMethod;
812 
813  if ( actuator != 0 )
814  delete actuator;
815 
816  if ( sensor != 0 )
817  delete sensor;
818 
819  if ( processDisturbance != 0 )
820  delete processDisturbance;
821 
822  return SUCCESSFUL_RETURN;
823 }
824 
825 
826 
828  const VariablesGrid& _p,
829  const VariablesGrid& _w
830  )
831 {
832  DynamicSystem* dynSys = dynamicSystems[0];
833  DifferentialEquation diffEqn = dynSys->getDifferentialEquation( );
834  OutputFcn outputFcn = dynSys->getOutputFcn( );
835 
836  Grid currentGrid;
837  _u.getGrid( currentGrid );
838 
839  OCPiterate iter;
840 
841  // allocate memory for call to simulation algorithm
842  // and initialise states with start value
843  DVector xComponents = diffEqn.getDifferentialStateComponents( );
844 
845  iter.x = new VariablesGrid( (int)round( xComponents.getMax( )+1.0 ),currentGrid,VT_DIFFERENTIAL_STATE );
846  for( uint i=0; i<xComponents.getDim( ); ++i )
847  iter.x->operator()( 0,(int)xComponents(i) ) = x(i);
848 
849 // DVector xaComponents;
850  if ( getNXA() > 0 )
851  {
852  iter.xa = new VariablesGrid( getNXA(),currentGrid,VT_ALGEBRAIC_STATE );
853  iter.xa->setVector( 0,xa );
854  }
855 
856  if ( ( _u.getNumPoints( ) > 0 ) && ( _u.getNumValues( ) > 0 ) )
857  iter.u = new VariablesGrid( _u );
858 
859  if ( ( _p.getNumPoints( ) > 0 ) && ( _p.getNumValues( ) > 0 ) )
860  iter.p = new VariablesGrid( _p );
861 
862  if ( ( _w.getNumPoints( ) > 0 ) && ( _w.getNumValues( ) > 0 ) )
863  iter.w = new VariablesGrid( _w );
864 
865 
866  // simulate process...
867 
868 // delete integrationMethod;
869 // integrationMethod = new ShootingMethod( this );
872 
873 // iter.u->print( "u" );
874 
875  #ifdef SIM_DEBUG
876 // printf("process step \n");
877  (iter.x->getVector(0)).print("iter.x(0)");
878  (iter.u->getVector(0)).print("iter.u(0)");
879 // (iter.x->getVector(1)).print("iter.x(1)");
880 // (iter.u->getVector(1)).print("iter.u(1)");
881  #endif
882 
883  iter.enableSimulationMode();
885 
886 
887  // calculate sampled output
888 // if ( calculateOutput( outputFcn,iter.x,xComponents,iter.xa,iter.p,iter.u,iter.w, &y ) != SUCCESSFUL_RETURN )
889 // return ACADOERROR( RET_PROCESS_STEP_FAILED );
890 
891 
892  // log simulation results
893  VariablesGrid xCont;
894  VariablesGrid xContFull;
895  VariablesGrid xaCont;
896  VariablesGrid pCont;
897  VariablesGrid uCont;
898  VariablesGrid wCont;
899 
900  if ( iter.x != 0 )
901  {
903 
904  xCont.init( getNX( ),xContFull.getTimePoints( ) );
905  projectToComponents( xContFull,xComponents, xCont );
907  }
908 
909  if ( iter.xa != 0 )
910  {
913  }
914 
915  if ( iter.p != 0 )
916  {
920  }
921 
922  if ( iter.u != 0 )
923  {
927  }
928 
929  if ( iter.w != 0 )
930  {
934  }
935 
936 
937  // calculate and log continuous output
938 // VariablesGrid yTmp;
939 
940  if ( calculateOutput( outputFcn,&xContFull,xComponents,&xaCont,&pCont,&uCont,&wCont, &y ) != SUCCESSFUL_RETURN )
943 
944 
945  for( uint i=0; i<xComponents.getDim( ); ++i )
946  x(i) = iter.x->operator()( iter.x->getNumPoints( )-1,(int)xComponents(i) );
947 
948  if ( iter.xa != 0 )
949  xa = iter.xa->getLastVector( );
950 
951  return SUCCESSFUL_RETURN;
952 }
953 
954 
955 
956 /* identitical to same function within the class Actuator! */
958  const VariablesGrid& _p
959  ) const
960 {
961  if ( _u.getNumPoints( ) < 2 )
963 
964  if ( _u.getNumRows( ) != getNU( ) )
966 
967  if ( _p.isEmpty( ) == BT_TRUE )
968  {
969  if ( getNP( ) > 0 )
971  }
972  else
973  {
974  if ( _p.getNumPoints( ) < 2 )
976 
977  if ( _p.getNumRows( ) < getNP( ) )
979 
980  if ( acadoIsEqual( _u.getFirstTime( ),_p.getFirstTime( ) ) == BT_FALSE )
982 
983  if ( acadoIsEqual( _u.getLastTime( ),_p.getLastTime( ) ) == BT_FALSE )
985  }
986 
987  return SUCCESSFUL_RETURN;
988 }
989 
990 
991 
993  const VariablesGrid* _x,
994  const DVector& _xComponents,
995  const VariablesGrid* _xa,
996  const VariablesGrid* _p,
997  const VariablesGrid* _u,
998  const VariablesGrid* _w,
999  VariablesGrid* _output
1000  ) const
1001 {
1002  if ( _output == 0 )
1004 
1005  if ( _outputFcn.isDefined( ) == BT_TRUE )
1006  {
1007  VariablesGrid pTmp = _p->getRefinedGrid( *_x );
1008  VariablesGrid uTmp = _u->getRefinedGrid( *_x );
1009 
1010  // y = outputFcn(x,xa,p,u,w)
1011  _outputFcn.evaluate( _x,_xa,&pTmp,&uTmp,_w, _output );
1012  }
1013  else
1014  {
1015  // output = x
1016  Grid outputGrid;
1017  _x->getGrid( outputGrid );
1018  _output->init( _xComponents.getDim( ),outputGrid );
1019 
1020  projectToComponents( *_x,_xComponents, *_output );
1021  }
1022 
1023  return SUCCESSFUL_RETURN;
1024 }
1025 
1026 
1027 
1029  const DVector& _xComponents,
1030  VariablesGrid& _output
1031  ) const
1032 {
1033  for( uint j=0; j<_x.getNumPoints( ); ++j )
1034  for( uint i=0; i<_xComponents.getDim( ); ++i )
1035  _output(j,i) = _x( j,(int)_xComponents(i) );
1036 
1037  return SUCCESSFUL_RETURN;
1038 }
1039 
1040 
1041 
1043 
1044 // end of file.
T getMax() const
Definition: vector.hpp:180
returnValue setTime(double _time)
Definition: grid.cpp:307
Data class for storing generic optimization variables.
Definition: ocp_iterate.hpp:57
virtual returnValue replot(PlotFrequency _frequency=PLOT_IN_ANY_CASE)
VariablesGrid y
Definition: process.hpp:614
virtual returnValue clear()
Actuator * actuator
Definition: process.hpp:610
Curve * processDisturbance
Definition: process.hpp:612
const int defaultFeasibilityCheck
virtual returnValue evaluate(OCPiterate &iter)
returnValue addItem(LogName _name, const char *const _label=DEFAULT_LABEL)
Definition: log_record.cpp:70
returnValue setActuator(const Actuator &_actuator)
Definition: process.cpp:254
returnValue evaluate(double *x, double *_result)
Definition: output_fcn.cpp:91
VariablesGrid * x
const double defaultRelaxationParameter
IntegratorType integratorType
Definition: process.hpp:619
Allows to setup and evaluate output functions based on SymbolicExpressions.
Definition: output_fcn.hpp:55
virtual returnValue step(VariablesGrid &_y)
Definition: sensor.cpp:192
const double defaultMaxStepsize
double getSampleTime() const
double getFirstTime() const
BooleanType acadoIsEqual(double x, double y, double TOL)
Definition: acado_utils.cpp:88
returnValue addStage(const DynamicSystem &dynamicSystem_, const Grid &stageIntervals, const IntegratorType &integratorType_=INT_UNKNOWN)
Definition: process.cpp:778
VariablesGrid * u
Stores a DifferentialEquation together with an OutputFcn.
BooleanType hasActuator() const
DVector getDifferentialStateComponents() const
uint getNumDynamicEquations() const
virtual returnValue setupOptions()
Definition: process.cpp:711
returnValue evaluate(double t, double *result) const
Definition: curve.cpp:314
returnValue setStatus(BlockStatus _status)
BooleanType isDefined() const
Process()
Definition: process.cpp:50
returnValue add(double tStart, double tEnd, const DVector constant)
Definition: curve.cpp:143
void init(unsigned _dim=0)
Definition: vector.hpp:155
Discretizes a DifferentialEquation by means of single or multiple shooting.
returnValue projectToComponents(const VariablesGrid &_x, const DVector &_xComponents, VariablesGrid &_output) const
Definition: process.cpp:1028
Provides a time grid consisting of vector-valued optimization variables at each grid point...
returnValue disableNominalParameters()
int addLogRecord(LogRecord &record)
Definition: logging.cpp:58
BooleanType isDiscretized() const
Allows to pass back messages to the calling function.
returnValue print() const
uint getNU(uint stageIdx=0) const
BooleanType isInTimeDomain(double t) const
Definition: curve.cpp:445
uint getNumOutputs() const
const double defaultStepsizeTuning
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
const double defaultMinStepsize
Allows to conveniently handle (one-dimensional) grids consisting of time points.
Definition: grid.hpp:58
BooleanType isEmpty() const
uint getNP() const
const DifferentialEquation & getDifferentialEquation(uint stageIdx=0) const
Allows to simulate the behaviour of sensors within the Process.
Definition: sensor.hpp:54
const int defaultMaxNumSteps
BooleanType hasProcessDisturbance() const
virtual returnValue step(const VariablesGrid &_u, const VariablesGrid &_p=emptyVariablesGrid)
Definition: process.cpp:508
virtual returnValue setupLogging()
Definition: process.cpp:745
PlotCollection plotCollection
Definition: plotting.hpp:194
Sensor * sensor
Definition: process.hpp:611
virtual returnValue replot(PlotFrequency _frequency=PLOT_IN_ANY_CASE)
Definition: process.cpp:678
#define CLOSE_NAMESPACE_ACADO
MatrixVariablesGrid getCoarsenedGrid(const Grid &arg) const
const double defaultIntegratorTolerance
returnValue initializeStartValues(const DVector &_xStart, const DVector &_xaStart=emptyConstVector)
Definition: process.cpp:330
MatrixVariablesGrid getRefinedGrid(const Grid &arg, InterpolationMode mode=IM_CONSTANT) const
uint getNY() const
returnValue setLast(LogName _name, const DMatrix &value, double time=-INFTY)
VariablesGrid * xa
uint getNW(uint stageIdx=0) const
const int defaultIntegratorPrintlevel
#define ACADO_TRY(X)
PlotFrequency
returnValue calculateOutput(OutputFcn &_outputFcn, const VariablesGrid *_x, const DVector &_xComponents, const VariablesGrid *_xa, const VariablesGrid *_p, const VariablesGrid *_u, const VariablesGrid *_w, VariablesGrid *_output) const
Definition: process.cpp:992
uint nDynSys
Definition: process.hpp:605
BlockStatus getStatus() const
uint getNX(uint stageIdx=0) const
DynamicSystem ** dynamicSystems
Definition: process.hpp:606
returnValue initializeAlgebraicStates(const DVector &_xaStart)
Definition: process.cpp:345
double lastTime
Definition: process.hpp:616
returnValue enableSimulationMode()
Process & operator=(const Process &rhs)
Definition: process.cpp:150
BooleanType hasSensor() const
returnValue setVector(uint pointIdx, const DVector &_values)
IntegratorType
Grid getUnionGrid() const
BEGIN_NAMESPACE_ACADO BooleanType acadoIsInteger(double x)
Definition: acado_utils.cpp:37
const OutputFcn & getOutputFcn(uint stageIdx=0) const
uint getNXA(uint stageIdx=0) const
unsigned getDim() const
Definition: vector.hpp:172
DVector getFirstVector() const
virtual returnValue print(std::ostream &stream=std::cout, const std::string &name=DEFAULT_LABEL, const std::string &startString=DEFAULT_START_STRING, const std::string &endString=DEFAULT_END_STRING, uint width=DEFAULT_WIDTH, uint precision=DEFAULT_PRECISION, const std::string &colSeparator=DEFAULT_COL_SEPARATOR, const std::string &rowSeparator=DEFAULT_ROW_SEPARATOR) const
Definition: vector.cpp:97
returnValue getGrid(Grid &_grid) const
returnValue addDynamicSystemStage(const DynamicSystem &_dynamicSystem, IntegratorType _integratorType=INT_UNKNOWN)
Definition: process.cpp:238
const double defaultCorrectorTolerance
DVector getLastVector() const
returnValue refineGrid(const Grid &arg, InterpolationMode mode=IM_CONSTANT)
returnValue init()
uint getNP(uint stageIdx=0) const
Derived & setZero(Index size)
uint getNU() const
Allows to work with piecewise-continous function defined over a scalar time interval.
Definition: curve.hpp:52
void rhs(const real_t *x, real_t *f)
virtual returnValue init(double _startTime=0.0, const DVector &_startValueU=emptyConstVector, const DVector &_startValueP=emptyConstVector)
Definition: actuator.cpp:286
double getSamplingTime() const
const double defaultInitialStepsize
returnValue checkInputConsistency(const VariablesGrid &_u, const VariablesGrid &_p) const
Definition: process.cpp:957
virtual returnValue run(const VariablesGrid &_u, const VariablesGrid &_p=emptyVariablesGrid)
Definition: process.cpp:632
ShootingMethod * integrationMethod
Definition: process.hpp:608
BooleanType hasImplicitSwitches() const
const int defaultprintIntegratorProfile
returnValue read(std::istream &stream)
ProcessPlotName
#define ASSERT(x)
VariablesGrid * p
#define BT_TRUE
Definition: acado_types.hpp:47
DVector x
Definition: process.hpp:602
const int defaultAlgebraicRelaxation
const int defaultParameterPlotting
virtual ~Process()
Definition: process.cpp:144
returnValue setProcessDisturbance(const Curve &_processDisturbance)
Definition: process.cpp:289
returnValue disableNominalOutputs()
uint getNumPoints() const
Base class for building-blocks of the SimulationEnvironment.
returnValue disableNominalControls()
uint getNumStages() const
BooleanType isDefined() const
DVector getVector(uint pointIdx) const
double getLastTime() const
returnValue clear()
Definition: process.cpp:797
Allows to setup and store user-specified log records of algorithmic information.
Definition: log_record.hpp:72
VariablesGrid * w
Simulates the process to be controlled based on a dynamic model.
Definition: process.hpp:71
#define BEGIN_NAMESPACE_ACADO
returnValue enableNominalParameters()
uint getNY(uint stageIdx=0) const
virtual returnValue init(double _startTime=0.0, const DVector &_startValue=emptyConstVector)
Definition: sensor.cpp:180
const int defaultControlPlotting
returnValue enableNominalOutputs()
#define BT_FALSE
Definition: acado_types.hpp:49
const int defaultPlotResoltion
SimulationBlock & operator=(const SimulationBlock &rhs)
const int defaultLinearAlgebraSolver
Allows to simulate the behaviour of actuators within the Process.
Definition: actuator.hpp:54
DVector xa
Definition: process.hpp:603
returnValue addOption(OptionsName name, int value)
Definition: options.cpp:301
returnValue simulate(const VariablesGrid &_u, const VariablesGrid &_p, const VariablesGrid &_w)
Definition: process.cpp:827
virtual returnValue step(VariablesGrid &_u, VariablesGrid &_p=emptyVariablesGrid)
Definition: actuator.cpp:307
const int defaultOutputPlotting
virtual returnValue addStage(const DynamicSystem &dynamicSystem_, const Grid &stageIntervals, const IntegratorType &integratorType_=INT_UNKNOWN)
returnValue setDynamicSystem(const DynamicSystem &_dynamicSystem, IntegratorType _integratorType=INT_UNKNOWN)
Definition: process.cpp:204
const int defaultSimulationAlgorithm
returnValue enableNominalControls()
int getDim() const
returnValue setSensor(const Sensor &_sensor)
Definition: process.cpp:271
#define ACADOERROR(retval)
returnValue getLast(LogName _name, DMatrix &lastValue) const
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


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