8 #ifndef __generalIntegrator_hpp__
9 #define __generalIntegrator_hpp__
18 template<
typename _realT>
26 typedef std::vector<realT> commandT;
37 template<
typename _realT>
56 typedef Eigen::Array< realT, Eigen::Dynamic, Eigen::Dynamic>
imageT;
241 int gains(
const std::vector<realT> &
gains );
250 int gains(
const std::string & ogainf );
262 int filterCommands(
commandT & filtAmps,
273 template<
typename realT>
280 template<
typename realT>
289 m_a.resize(m_nModes, n);
293 m_commandsOut.resize( m_nModes, n);
294 m_commandsOut.setZero();
301 m_b.resize(m_nModes, n);
305 m_commandsIn.resize( m_nModes, n);
306 m_commandsIn.setZero();
309 m_closingGains.resize(1,m_nModes);
311 m_closingGains.setZero();
313 m_gains.resize(1,m_nModes);
321 template<
typename realT>
327 template<
typename realT>
334 template<
typename realT>
340 template<
typename realT>
343 m_openLoopDelay = old;
348 template<
typename realT>
351 return m_openLoopDelay;
354 template<
typename realT>
362 template<
typename realT>
365 return m_closingRamp;
368 template<
typename realT>
376 template<
typename realT>
379 return m_closingDelay;
382 template<
typename realT>
386 if( gains.size() != (
size_t) m_closingGains.cols())
388 mxError(
"generalIntegrator::closingGains", MXE_SIZEERR,
"input gain vector not same size as number of modes");
392 for(
int i=0;i<m_closingGains.cols(); ++i)
394 m_closingGains(0,i) = gains[i];
400 template<
typename realT>
403 for(
int i=0;i<m_closingGains.cols(); ++i)
405 m_closingGains(0,i) = g;
411 template<
typename realT>
419 template<
typename realT>
425 template<
typename realT>
431 m_a.resize(m_nModes, n);
432 m_commandsOut.resize(m_nModes, n);
437 m_commandsOut.resize(1, n);
442 m_commandsOut.setZero();
447 template<
typename realT>
455 template<
typename realT>
461 m_b.resize(m_nModes, n);
462 m_commandsIn.resize(m_nModes,n);
467 m_commandsIn.resize(1,n);
472 m_commandsIn.setZero();
477 template<
typename realT>
486 template<
class realT>
489 if(i < 0 || i >= m_nModes)
491 mxError(
"generalIntegrator::gain", MXE_INVALIDARG,
"mode index out of range");
498 template<
typename realT>
501 if(i < 0 || i >= m_nModes)
503 mxError(
"generalIntegrator::gain", MXE_INVALIDARG,
"mode index out of range");
513 template<
typename realT>
516 for(
int i=0;i<m_gains.cols(); ++i)
524 template<
typename realT>
528 if( gains.size() != (
size_t) m_gains.cols())
530 mxError(
"generalIntegrator::gains", MXE_SIZEERR,
"input gain vector not same size as number of modes");
534 for(
int i=0;i<m_gains.cols(); ++i)
536 m_gains(0,i) = gains[i];
545 template<
typename realT>
553 mxError(
"generalIntegrator::gains", MXE_FILEOERR,
"could not open gan file");
559 for(
int i=0;i<m_gains.cols();++i)
562 g = ioutils::convertFromString<realT>(tmpstr);
570 template<
class realT>
573 filtAmps.measurement.resize(m_nModes);
574 for(
size_t n=0; n<m_nModes; ++n) filtAmps.measurement[n] = 0;
577 rawAmps.measurement.resize(m_nModes);
578 for(
size_t n=0; n<m_nModes; ++n) rawAmps.measurement[n] = 0;
585 template<
typename realT>
590 filtAmps.iterNo = rawAmps.iterNo;
592 if(m_openLoop || iterNo < m_openLoopDelay)
594 for(
size_t n=0; n<m_nModes; ++n) filtAmps.measurement[n] = 0;
602 if( iterNo - m_openLoopDelay < m_closingDelay)
606 for(
int i=0; i< m_nModes; ++i)
609 if( std::isnan( rawAmps.measurement[i] ) || !std::isfinite(rawAmps.measurement[i])) rawAmps.measurement[i] = 0.0;
612 m_commandsIn(i, m_currB) = rawAmps.measurement[i];
614 aTot = m_commandsOut(i, m_currA);
618 int cA = m_currA + 1;
619 if(cA >= m_a.cols()) cA = 0;
624 if( iterNo - m_openLoopDelay < m_closingRamp) 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()) m_currB = 0;
647 if(m_currA >= m_a.cols()) m_currA = 0;
655 for(
int i=0; i< m_nModes; ++i)
660 filtAmps.measurement[i] = 0;
666 if( std::isnan( rawAmps.measurement[i] ) || !std::isfinite(rawAmps.measurement[i])) rawAmps.measurement[i] = 0.0;
669 for(
int j = 0; j < m_a.cols(); ++j)
672 if(
k < 0)
k += m_a.cols();
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)
682 if(
k < 0)
k += m_b.cols();
684 bTot += m_b(i,j) * m_commandsIn(i,
k);
689 if( cA >= m_a.cols()) cA = 0;
691 m_commandsOut(i, cA) = aTot + m_gains(i) * bTot;
693 filtAmps.measurement[i] = m_commandsOut(i, cA);
697 if(m_currB >= m_b.cols()) m_currB = 0;
700 if(m_currA >= m_a.cols()) m_currA = 0;
Implements a general integrator controller.
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 m_closingRamp
If > 0, then gains are famped linearly up to m_closingGains over this interval in time steps....
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.
Eigen::Array< realT, Eigen::Dynamic, Eigen::Dynamic > imageT
The image type, used here as a general storage array.
int m_lowOrders
If > 0, then this sets the maximum mode number which is filtered. All remaining modes are set to 0....
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.
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 m_closingDelay
If > 0, then the simple integrator,with m_closingGains is used up to this timestep....
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.