8 #ifndef __leakyIntegrator_hpp__
9 #define __leakyIntegrator_hpp__
18 template<
typename _realT>
25 typedef Eigen::Array< realT, Eigen::Dynamic, Eigen::Dynamic> commandT;
34 template<
typename _realT>
50 typedef Eigen::Array< realT, Eigen::Dynamic, Eigen::Dynamic>
imageT;
155 int gains(
const std::vector<realT> & vgains );
163 int gains(
const std::string & ogainf );
205 template<
typename realT>
221 template<
typename realT>
226 _gains.resize(1,nModes);
227 _leaks.resize(1, nModes);
228 _commands.resize(1, nModes);
240 template<
typename realT>
246 template<
typename realT>
253 template<
typename realT>
259 template<
typename realT>
267 template<
typename realT>
270 return _closingDelay;
273 template<
typename realT>
281 template<
typename realT>
287 template<
typename realT>
290 if(i < 0 || i >= _nModes)
292 mxError(
"leakyIntegrator::gain", MXE_INVALIDARG,
"mode index out of range");
300 template<
typename realT>
303 if(i < 0 || i >= _nModes)
305 mxError(
"leakyIntegrator::gain", MXE_INVALIDARG,
"mode index out of range");
314 template<
typename realT>
317 for(
int i=0;i<_gains.cols(); ++i)
325 template<
typename realT>
329 if( gains.size() != _gains.cols())
331 mxError(
"leakyIntegrator::gain", MXE_SIZEERR,
"input gain vector not same size as number of modes");
335 for(
int i=0;i<_gains.cols(); ++i)
337 _gains(0,i) = gains[i];
343 template<
typename realT>
351 mxError(
"leakyIntegrator::gains", MXE_FILEOERR,
"could not open gan file");
357 for(
int i=0;i<_gains.cols();++i)
360 g = mx::convertFromString<realT>(tmpstr);
369 template<
typename realT>
375 template<
typename realT>
378 for(
int i=0;i<_leaks.cols(); ++i) _leaks(0,i) = l;
383 template<
class realT>
386 filtAmps.measurement.resize(1, _nModes);
387 filtAmps.measurement.setZero();
389 rawAmps.measurement.resize(1, _nModes);
390 rawAmps.measurement.setZero();
395 template<
class realT>
400 filtAmps.iterNo = rawAmps.iterNo;
404 filtAmps.measurement.setZero();
408 int topN = rawAmps.measurement.cols();
417 if( iterNo < _closingDelay) gainF = ((
realT) iterNo)/_closingDelay;
423 if( iterNo >= _closingDelay+_lowOrderDelay)
431 if( iterNo >= _closingDelay )
433 HOgainF = ( (
realT) (iterNo - _closingDelay) )/( _lowOrderDelay );
441 for(
int i=0; i< topN; ++i)
443 if( std::isnan( rawAmps.measurement(0,i) ) || !std::isfinite(rawAmps.measurement(0,i))) rawAmps.measurement(0,i) = 0.0;
445 _commands(0,i) = (1.0-_leaks(0,i))*_commands(0,i) + gainF*_gains(0,i)*rawAmps.measurement(0,i);
447 filtAmps.measurement(0,i) = _commands(0,i);
450 for(
int i=topN; i< rawAmps.measurement.cols(); ++i)
452 if( std::isnan( rawAmps.measurement(0,i) ) || !std::isfinite(rawAmps.measurement(0,i))) rawAmps.measurement(0,i) = 0.0;
454 _commands(0,i) = (1.0-_leaks(0,i))*_commands(0,i) + HOgainF*_gains(0,i)*rawAmps.measurement(0,i);
456 filtAmps.measurement(0,i) = _commands(0,i);
Implements the leaky integrator controller.
imageT _gains
Column-vector of gains.
_realT realT
The real data type.
bool openLoop()
Get the value of the _openLoop flag.
wfMeasurement< realT > commandT
The command type.
int closingDelay()
Get the value of the _closingDelay.
wavefront< realT > wavefrontT
The wavefront data type.
int leaks(realT l)
Set a leak for all modes.
Eigen::Array< realT, Eigen::Dynamic, Eigen::Dynamic > imageT
The image type, used here as a general storage array.
imageT _leaks
Column-vector of leaks.
int filterCommands(commandT &filtAmps, commandT &rawAmps, int iterNo)
Apply the leaky integrator.
int initMeasurements(commandT &filtAmps, commandT &rawAmps)
Allocate the provided command structures.
leakyIntegrator()
Default c'tor.
int initialize(int nModes)
Allocate and initialize all state.
realT gain(int i)
Get the gain for a single mode.
int gains(realT g)
Set the gain for all modes to a single value.
int leak(int i, realT l)
Set the leak for a single mode.
int _nModes
The number of modes being filtered.
bool _openLoop
If true, then commands are not integrated.
imageT _commands
Column-vector past commands.
int _closingDelay
If > 0, then the gains are ramped linearly up to this value. Default = 0.
int lowOrders()
Get the value of the _lowOrders.
int nModes()
Get the number of modes.
int _lowOrders
If > 0, then this sets the maximum mode number which is filtered. All remaining modes are set to 0....
Structure containing the phase and amplitude of a wavefront