8#ifndef __generalIntegrator_hpp__
9#define __generalIntegrator_hpp__
23#define MXLIB_GENERAL_INTEGRATOR_LOCAL_BREAD_CRUMB
25#define BREAD_CRUMB std::cout << "DEBUG: " << __FILE__ << " " << __LINE__ << "\n";
38template <
typename _realT>
46 typedef std::vector<realT> commandT;
57template <
typename _realT>
75 typedef Eigen::Array<realT, Eigen::Dynamic, Eigen::Dynamic>
imageT;
267 int gains(
const std::string &ogainf );
281template <
typename realT>
286template <
typename realT>
299 m_commandsOut.resize(
m_nModes, n );
300 m_commandsOut.setZero();
312 m_commandsIn.setZero();
326template <
typename realT>
332template <
typename realT>
339template <
typename realT>
345template <
typename realT>
353template <
typename realT>
359template <
typename realT>
367template <
typename realT>
373template <
typename realT>
381template <
typename realT>
387template <
typename realT>
393 mxError(
"generalIntegrator::closingGains",
MXE_SIZEERR,
"input gain vector not same size as number of modes" );
405template <
typename realT>
416template <
typename realT>
424template <
typename realT>
430template <
typename realT>
437 m_commandsOut.resize(
m_nModes, n );
442 m_commandsOut.resize( 1, n );
447 m_commandsOut.setZero();
452template <
typename realT>
460template <
typename realT>
472 m_commandsIn.resize( 1, n );
477 m_commandsIn.setZero();
482template <
typename realT>
490template <
class realT>
502template <
typename realT>
516template <
typename realT>
519 for(
int i = 0; i <
m_gains.cols(); ++i )
527template <
typename realT>
533 mxError(
"generalIntegrator::gains",
MXE_SIZEERR,
"input gain vector not same size as number of modes" );
537 for(
int i = 0; i <
m_gains.cols(); ++i )
545template <
typename realT>
559 for(
int i = 0; i <
m_gains.cols(); ++i )
569template <
class realT>
572 filtAmps.measurement.resize(
m_nModes );
573 for(
size_t n = 0; n <
m_nModes; ++n )
574 filtAmps.measurement[n] = 0;
577 rawAmps.measurement.resize(
m_nModes );
578 for(
size_t n = 0; n <
m_nModes; ++n )
579 rawAmps.measurement[n] = 0;
586template <
typename realT>
587int generalIntegrator<realT>::filterCommands( commandT &filtAmps, commandT &rawAmps,
int iterNo )
589 filtAmps.iterNo = rawAmps.iterNo;
591 if( m_openLoop || iterNo < m_openLoopDelay )
593 for(
size_t n = 0; n < m_nModes; ++n )
594 filtAmps.measurement[n] = 0;
601 if( iterNo - m_openLoopDelay < m_closingDelay )
605 for(
int i = 0; i < m_nModes; ++i )
609 if( std::isnan( rawAmps.measurement[i] ) || !std::isfinite( rawAmps.measurement[i] ) )
610 rawAmps.measurement[i] = 0.0;
613 m_commandsIn( i, m_currB ) = rawAmps.measurement[i];
615 aTot = m_commandsOut( i, m_currA );
618 int cA = m_currA + 1;
619 if( cA >= m_a.cols() )
624 if( iterNo - m_openLoopDelay < m_closingRamp )
625 gf = ( (realT)iterNo - m_openLoopDelay ) / m_closingRamp;
628 m_commandsOut( i, cA ) = aTot + gf * m_closingGains( i ) * rawAmps.measurement[i];
632 if( i <= m_lowOrders || m_lowOrders <= 0 )
634 filtAmps.measurement[i] = m_commandsOut( i, cA );
638 filtAmps.measurement[i] = 0;
643 if( m_currB >= m_b.cols() )
647 if( m_currA >= m_a.cols() )
653 for(
int i = 0; i < m_nModes; ++i )
655 if( m_gains( i ) == 0 )
658 filtAmps.measurement[i] = 0;
664 if( std::isnan( rawAmps.measurement[i] ) || !std::isfinite( rawAmps.measurement[i] ) )
665 rawAmps.measurement[i] = 0.0;
668 for(
int j = 0; j < m_a.cols(); ++j )
673 aTot += m_a( i, j ) * m_commandsOut( i, k );
676 m_commandsIn( i, m_currB ) = rawAmps.measurement[i];
679 for(
int j = 0; j < m_b.cols(); ++j )
685 bTot += m_b( i, j ) * m_commandsIn( i, k );
688 int cA = m_currA + 1;
689 if( cA >= m_a.cols() )
692 m_commandsOut( i, cA ) = aTot + m_gains( i ) * bTot;
694 filtAmps.measurement[i] = m_commandsOut( i, cA );
698 if( m_currB >= m_b.cols() )
702 if( m_currA >= m_a.cols() )
712#ifdef MXLIB_GENERAL_INTEGRATOR_LOCAL_BREAD_CRUMB
714#undef MXLIB_GENERAL_INTEGRATOR_LOCAL_BREAD_CRUMB
imageT m_closingGains
Column-vector of gains used for loop closing as simple integrator.
int nModes()
Get the number of modes.
generalIntegrator()
Default c'tor.
int m_openLoopDelay
If > 0, then the loop is open for this time in time steps. Default is 0.
int closingDelay()
Get the value of the m_closingDelay.
int setA(int i, const imageT &a)
Set the IIR coefficients for one mode.
bool openLoop()
Get the value of the m_openLoop flag.
wfMeasurement< realT > commandT
The wavefront data type.
bool m_openLoop
If true, then commands are not integrated. Default is false.
int gains(realT g)
Set the gain for all modes to a single value.
int closingGains(const std::vector< realT > &gains)
Set the simple integrator gains to use during closing.
int openLoopDelay()
Get the value of the m_openLoopDelay.
std::complex< realT > complexT
The real data type.
int setB(int i, const imageT &b)
Set the FIR coefficients for one mode.
int initialize(int nModes)
Allocate and initialize all state.
Eigen::Array< realT, Eigen::Dynamic, Eigen::Dynamic > imageT
The image type, used here as a general storage array.
int initMeasurements(commandT &filtAmps, commandT &rawAmps)
Allocate the provided command structures.
_realT realT
The real data type.
int lowOrders()
Get the value of the m_lowOrders.
int setBSize(int n)
Set the size of the FIR vector (the b coefficients).
int setASize(int n)
Set the size of the IIR vector (the a coefficients).
realT gain(int i)
Get the gain for a single mode.
int closingRamp()
Get the value of the m_closingRamp.
imageT m_gains
Column-vector of gains.
int m_nModes
The number of modes being filtered.
constexpr units::realT k()
Boltzmann Constant.
#define mxError(esrc, ecode, expl)
This reports an mxlib specific error.
#define MXE_INVALIDARG
An argument was invalid.
#define MXE_SIZEERR
A size was invalid or calculated incorrectly.
#define MXE_FILEOERR
An error occurred while opening a file.
typeT convertFromString(const std::string &str, error_t *errc=nullptr)
Convert a string to a numerical value.
Old version. Deprecated. Declares and defines the mxlib error reporting system.
Utilities for working with strings.