Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00034 #include <acado/transfer_device/transfer_device.hpp>
00035
00036
00037
00038 BEGIN_NAMESPACE_ACADO
00039
00040
00041
00042
00043
00044
00045
00046 TransferDevice::TransferDevice( ) : SimulationBlock( )
00047 {
00048 additiveNoise = 0;
00049
00050 setStatus( BS_NOT_INITIALIZED );
00051 }
00052
00053
00054 TransferDevice::TransferDevice( uint _dim,
00055 BlockName _name,
00056 double _samplingTime
00057 ) : SimulationBlock( _name,_samplingTime )
00058 {
00059 lastSignal.init( _dim,1 );
00060
00061 additiveNoise = new Noise*[_dim];
00062 for( uint i=0; i<_dim; ++i )
00063 additiveNoise[i] = 0;
00064
00065 noiseSamplingTimes.init( _dim );
00066 noiseSamplingTimes.setAll( 0.0 );
00067
00068 deadTimes.init( _dim );
00069 deadTimes.setAll( 0.0 );
00070
00071 setStatus( BS_NOT_INITIALIZED );
00072 }
00073
00074
00075 TransferDevice::TransferDevice( const TransferDevice& rhs ) : SimulationBlock( rhs )
00076 {
00077 lastSignal = rhs.lastSignal;
00078
00079 if ( rhs.additiveNoise != 0 )
00080 {
00081 additiveNoise = new Noise*[rhs.getDim( )];
00082
00083 for( uint i=0; i<getDim( ); ++i )
00084 if ( rhs.additiveNoise[i] != 0 )
00085 additiveNoise[i] = (rhs.additiveNoise[i])->clone( );
00086 else
00087 additiveNoise[i] = 0;
00088 }
00089 else
00090 additiveNoise = 0;
00091
00092 noiseSamplingTimes = rhs.noiseSamplingTimes;
00093
00094 deadTimes = rhs.deadTimes;
00095 }
00096
00097
00098 TransferDevice::~TransferDevice( )
00099 {
00100 if ( additiveNoise != 0 )
00101 {
00102 for( uint i=0; i<getDim( ); ++i )
00103 if ( additiveNoise[i] != 0 )
00104 delete additiveNoise[i];
00105
00106 delete[] additiveNoise;
00107 }
00108 }
00109
00110
00111 TransferDevice& TransferDevice::operator=( const TransferDevice& rhs )
00112 {
00113 if ( this != &rhs )
00114 {
00115 SimulationBlock::operator=( rhs );
00116
00117 if ( additiveNoise != 0 )
00118 {
00119 for( uint i=0; i<getDim( ); ++i )
00120 if ( additiveNoise[i] != 0 )
00121 delete additiveNoise[i];
00122
00123 delete[] additiveNoise;
00124 }
00125
00126
00127 lastSignal = rhs.lastSignal;
00128
00129 if ( rhs.additiveNoise != 0 )
00130 {
00131 additiveNoise = new Noise*[rhs.getDim( )];
00132
00133 for( uint i=0; i<getDim( ); ++i )
00134 if ( rhs.additiveNoise[i] != 0 )
00135 additiveNoise[i] = (rhs.additiveNoise[i])->clone( );
00136 else
00137 additiveNoise[i] = 0;
00138 }
00139 else
00140 additiveNoise = 0;
00141
00142 noiseSamplingTimes = rhs.noiseSamplingTimes;
00143
00144 deadTimes = rhs.deadTimes;
00145 }
00146
00147 return *this;
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 returnValue TransferDevice::init( double _startTime,
00159 const DVector& _startValue
00160 )
00161 {
00162
00163 lastSignal.init( getDim( ),1 );
00164
00165 lastSignal.setTime( 0,_startTime );
00166
00167 if ( _startValue.getDim( ) == getDim( ) )
00168 {
00169 lastSignal.setVector( 0,_startValue );
00170 }
00171 else
00172 {
00173 DVector tmp( getDim( ) );
00174 tmp.setAll( 0.0 );
00175 lastSignal.setVector( 0,tmp );
00176 }
00177
00178
00179 if ( additiveNoise != 0 )
00180 {
00181 for( uint i=0; i<getDim( ); ++i )
00182 {
00183 if ( additiveNoise[i] != 0 )
00184 additiveNoise[i]->init( );
00185 }
00186 }
00187
00188 setStatus( BS_READY );
00189
00190 return SUCCESSFUL_RETURN;
00191 }
00192
00193
00194 returnValue TransferDevice::generateNoise( double startTime,
00195 double endTime,
00196 VariablesGrid& currentNoise
00197 ) const
00198 {
00199 double horizonLength = endTime - startTime;
00200 if ( horizonLength <= 0.0 )
00201 return ACADOERROR( RET_INVALID_ARGUMENTS );
00202
00203
00204 Grid noiseGrid;
00205
00206 if ( acadoIsPositive( noiseSamplingTimes(0) ) == BT_TRUE )
00207 {
00208 for( uint i=0; i<=floor( horizonLength/noiseSamplingTimes(0) ); ++i )
00209 noiseGrid.addTime( ((double)i) * noiseSamplingTimes(0) );
00210
00211 if ( acadoIsInteger( horizonLength/noiseSamplingTimes(0) ) == BT_FALSE )
00212 noiseGrid.addTime( endTime );
00213
00214 noiseGrid.shiftTimes( startTime );
00215 }
00216 else
00217 {
00218 noiseGrid.init( startTime,endTime );
00219 }
00220
00221
00222 DVector noiseVector( 1 );
00223
00224 currentNoise.init( getDim( ),noiseGrid );
00225 currentNoise.setZero( );
00226
00227 if ( additiveNoise != 0 )
00228 {
00229
00230 for( uint i=0; i<getDim( ); ++i )
00231 {
00232 if ( additiveNoise[i] != 0 )
00233 {
00234 for( uint j=0; j<currentNoise.getNumPoints( )-1; ++j )
00235 {
00236 additiveNoise[i]->step( noiseVector );
00237 currentNoise( j,i ) = noiseVector( 0 );
00238 }
00239 currentNoise( currentNoise.getNumPoints( )-1,i ) = noiseVector( 0 );
00240 }
00241 }
00242 }
00243
00244 return SUCCESSFUL_RETURN;
00245 }
00246
00247
00248
00249 CLOSE_NAMESPACE_ACADO
00250
00251
00252
00253