10 #include "../../libMagAOX/libMagAOX.hpp"
11 #include "../../magaox_git_version.h"
137 mx::improc::eigenImage<float>
m_ref;
154 mx::sigproc::circularBufferIndex<float, cbIndexT>
m_pcb;
155 mx::sigproc::circularBufferIndex<float, cbIndexT>
m_xcb;
156 mx::sigproc::circularBufferIndex<float, cbIndexT>
m_ycb;
183 mx::app::appConfigurator &_config );
207 int allocate( const dev::shmimT & );
209 int processImage(
void *curr_src, const dev::shmimT & );
354 "Device name for getting fps if time-based averaging is used. This device should have *.fps.current." );
356 config.add(
"fitter.deltaPixThresh",
358 "fitter.deltaPixThresh",
364 "Threshold in pixels for skipping frame due to mismatch between max and c.o.l. Default 2." );
365 config.add(
"fitter.sigmaMaxThreshUp",
367 "fitter.sigmaMaxThreshUp",
373 "Threshold in rms for skipping frame due to max positive difference from mean max. Default 5." );
374 config.add(
"fitter.sigmaMaxThreshDown",
376 "fitter.sigmaMaxThreshDown",
379 "sigmaMaxThreshDown",
382 "Threshold in rms for skipping frame due to max negative difference from mean max. Default 5." );
384 config.add(
"fitter.sigmaPixThresh",
386 "fitter.sigmaPixThresh",
392 "Threshold in rms for skipping frame due to max difference from last value. Example: if this is set "
393 "to 10, then the pixel postion has to change from -5 sigma to + 5 sigma to be rejected. Default 10." );
427 log<software_critical>( { __FILE__, __LINE__, errno, 0,
"Initializing S.M. semaphore" } );
500 for(
size_t n = 0; n <
m_xcb.size(); ++n )
550 std::vector<std::string>( {
"max_mean",
"max_rms",
"x_mean",
"x_rms",
"y_mean",
"y_rms" } ),
572 static_cast<void>( dummy );
581 m_pcb.maxEntries( 0 );
582 m_xcb.maxEntries( 0 );
583 m_ycb.maxEntries( 0 );
603 m_pcb.maxEntries( cbSz );
604 m_xcb.maxEntries( cbSz );
605 m_ycb.maxEntries( cbSz );
623 static_cast<void>( dummy );
626 static int skip_interval = 10;
627 static int last_passed = skip_interval + 1;
637 m_image.data()[nn] = ( (uint16_t *)curr_src )[nn] -
m_dark.data()[nn];
644 m_image.data()[nn] = ( (
float *)curr_src )[nn] -
m_dark.data()[nn];
654 m_image.data()[nn] = ( (uint16_t *)curr_src )[nn];
661 m_image.data()[nn] = ( (
float *)curr_src )[nn];
672 max =
m_image.maxCoeff( &x, &y );
680 if( last_passed > skip_interval )
682 std::cerr <<
"skip frame (delta from max) " <<
m_x <<
" " << x <<
" " <<
m_y <<
" " << y <<
"("
683 << (
m_x - x ) <<
" " << (
m_y - y ) <<
")\n";
690 else if( last_passed < skip_interval + 1 )
698 if(
m_xcb.maxEntries() > 0 )
700 m_pcb.nextEntry( max );
715 if(
m_pcb.maxEntries() > 0 )
717 m_pcb.nextEntry( max );
733 if(
m_pcb.maxEntries() > 0 )
735 m_pcb.nextEntry( max );
751 if(
m_xcb.maxEntries() > 0 )
753 m_pcb.nextEntry( max );
769 if(
m_ycb.maxEntries() > 0 )
771 m_pcb.nextEntry( max );
805 log<software_critical>( { __FILE__, __LINE__, errno, 0,
"Error posting to semaphore" } );
811 if(
m_xcb.maxEntries() > 0 )
813 m_pcb.nextEntry( max );
827 static_cast<void>( dummy );
844 static_cast<void>( dummy );
850 m_dark.data()[nn] = ( (
float *)curr_src )[nn];
862 static_cast<void>( dummy );
879 static_cast<void>( dummy );
885 m_ref.data()[nn] = ( (
float *)curr_src )[nn];
914 if( clock_gettime( CLOCK_REALTIME, &ts ) < 0 )
916 log<software_critical>( { __FILE__, __LINE__, errno, 0,
"clock_gettime" } );
944 ( (
float *)dest )[0] =
m_x -
m_dx;
945 ( (
float *)dest )[1] =
m_y -
m_dy;
949 ( (
float *)dest )[0] =
m_x;
950 ( (
float *)dest )[1] =
m_y;
967 if(
ipRecv.find(
"request" ) !=
true )
972 if(
ipRecv[
"request"].getSwitchState() == pcf::IndiElement::On )
975 shmimMonitorT::m_restart =
true;
987 if( indiTargetUpdate( m_indiP_statsTime, target,
ipRecv,
true ) < 0 )
989 log<software_error>( { __FILE__, __LINE__ } );
993 m_fitCircBuffMaxTime = target;
995 shmimMonitorT::m_restart =
true;
997 log<text_log>(
"set statsTime = " + std::to_string( m_fitCircBuffMaxTime ),
logPrio::LOG_NOTICE );
1008 if( indiTargetUpdate( m_indiP_deltaPixThresh, target,
ipRecv,
true ) < 0 )
1010 log<software_error>( { __FILE__, __LINE__ } );
1014 m_deltaPixThresh = target;
1016 log<text_log>(
"set deltaPixThresh = " + std::to_string( m_deltaPixThresh ),
logPrio::LOG_NOTICE );
1026 if( indiTargetUpdate( m_indiP_sigmaMaxThreshUp, target,
ipRecv,
true ) < 0 )
1028 log<software_error>( { __FILE__, __LINE__ } );
1032 m_sigmaMaxThreshUp = target;
1034 log<text_log>(
"set sigmaMaxThreshUp = " + std::to_string( m_sigmaMaxThreshUp ),
logPrio::LOG_NOTICE );
1044 if( indiTargetUpdate( m_indiP_sigmaMaxThreshDown, target,
ipRecv,
true ) < 0 )
1046 log<software_error>( { __FILE__, __LINE__ } );
1050 m_sigmaMaxThreshDown = target;
1052 log<text_log>(
"set sigmaMaxThreshDown = " + std::to_string( m_sigmaMaxThreshDown ),
logPrio::LOG_NOTICE );
1062 if( indiTargetUpdate( m_indiP_sigmaPixThresh, target,
ipRecv,
true ) < 0 )
1064 log<software_error>( { __FILE__, __LINE__ } );
1068 m_sigmaPixThresh = target;
1070 log<text_log>(
"set sigmaMaxThreshDown = " + std::to_string( m_sigmaPixThresh ),
logPrio::LOG_NOTICE );
1080 if( indiTargetUpdate( m_indiP_dx, target,
ipRecv,
true ) < 0 )
1082 log<software_error>( { __FILE__, __LINE__ } );
1098 if( indiTargetUpdate( m_indiP_dy, target,
ipRecv,
true ) < 0 )
1100 log<software_error>( { __FILE__, __LINE__ } );
1114 if(
ipRecv.find(
"current" ) !=
true )
1119 std::lock_guard<std::mutex> guard( m_indiMutex );
1121 realT fps =
ipRecv[
"current"].get<
float>();
1128 std::cerr <<
"got fps: " << m_fps <<
"\n";
1130 shmimMonitorT::m_restart =
true;
#define IMAGESTRUCT_FLOAT
The base-class for MagAO-X applications.
void updateIfChanged(pcf::IndiProperty &p, const std::string &el, const T &newVal, pcf::IndiProperty::PropertyStateType ipState=pcf::IndiProperty::Ok)
Update an INDI property element value if it has changed.
stateCodes::stateCodeT state()
Get the current state code.
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
timespec m_currImageTimestamp
The timestamp of the current image.
uint32_t m_width
The width of the image, once deinterlaced etc.
int recordFGTimings(bool force=false)
uint8_t m_dataType
The ImageStreamIO type code.
uint32_t m_height
The height of the image, once deinterlaced etc.
uint32_t m_width
The width of the images in the stream.
uint32_t m_height
The height of the images in the stream.
uint8_t m_dataType
The ImageStreamIO type code.
bool m_getExistingFirst
If set to true by derivedT, any existing image will be grabbed and sent to processImage before waitin...
virtual int appLogic()
Implementation of the FSM for psfFit.
pcf::IndiProperty m_indiP_values
float m_dx
The offset in x to apply to non-skipped measurements.
int loadImageIntoStream(void *dest)
Implementation of the framegrabber loadImageIntoStream interface.
int reconfig()
Implementation of the framegrabber reconfig interface.
float m_mnx
The mean x coord over the stats time.
int loadConfigImpl(mx::app::appConfigurator &_config)
Implementation of loadConfig logic, separated for testing.
float realT
Floating point type in which to do all calculations.
INDI_NEWCALLBACK_DECL(psfFit, m_indiP_sigmaMaxThreshUp)
mx::sigproc::circularBufferIndex< float, cbIndexT > m_pcb
Circular buffer for max pixel (p=peak)
bool m_skipped
Indicates that the image failed quality control and this is a skip frame.
float m_sigmaMaxThreshDown
static constexpr bool c_frameGrabber_flippable
app:dev config to tell framegrabber these images can not be flipped
INDI_NEWCALLBACK_DECL(psfFit, m_indiP_dy)
uint16_t m_fitCircBuffMaxLength
Maximum length of the latency measurement circular buffers.
INDI_NEWCALLBACK_DECL(psfFit, m_indiP_dx)
float fps()
Implementation of the framegrabber fps interface.
pcf::IndiProperty m_indiP_dx
float m_mny
The mean y coord over the stats time.
float m_x
The current x coordinate.
float m_rmsp
The rms max pixel over the stats time.
std::vector< float > m_ycbD
Vector for doing calcs on y COL coords.
float m_rmsy
The rms y coord over the stats time.
INDI_NEWCALLBACK_DECL(psfFit, m_indiP_sigmaMaxThreshDown)
sem_t m_smSemaphore
Semaphore used to synchronize the fg thread and the sm thread.
dev::telemeter< psfFit > telemeterT
mx::sigproc::circularBufferIndex< float, cbIndexT > m_xcb
Circular buffer for x COL coords.
pcf::IndiProperty m_indiP_reset
dev::shmimMonitor< psfFit, darkShmimT > darkShmimMonitorT
The dark shmimMonitor type.
virtual void loadConfig()
pcf::IndiProperty m_indiP_dy
~psfFit() noexcept
D'tor, declared and defined for noexcept.
int acquireAndCheckValid()
Implementation of the framegrabber acquireAndCheckValid interface.
std::vector< float > m_pcbD
Vector for doing calcs on max pixel.
dev::frameGrabber< psfFit > frameGrabberT
int recordTelem(const telem_fgtimings *)
pcf::IndiProperty m_indiP_sigmaPixThresh
float m_fps
The frame rate from the source camera.
INDI_NEWCALLBACK_DECL(psfFit, m_indiP_deltaPixThresh)
float m_last_y
The previous y coordinate.
int allocate(const dev::shmimT &)
INDI_NEWCALLBACK_DECL(psfFit, m_indiP_statsTime)
float m_fitCircBuffMaxTime
Maximum time of the latency meaurement circular buffers.
pcf::IndiProperty m_indiP_deltaPixThresh
mx::improc::eigenImage< float > m_dark
Holds the dark image.
float m_rmsx
The rms x coord over the stats time.
pcf::IndiProperty m_indiP_fpsSource
INDI_NEWCALLBACK_DECL(psfFit, m_indiP_reset)
virtual void setupConfig()
virtual int appShutdown()
Shutdown the app.
dev::shmimMonitor< psfFit, refShmimT > refShmimMonitorT
The reference shmimMonitor type.
mx::improc::eigenImage< float > m_ref
Holds the reference image.
std::vector< float > m_xcbD
Vector for doing calcs on x COL coords.
pcf::IndiProperty m_indiP_statsTime
mx::sigproc::circularBufferIndex< float, cbIndexT > m_ycb
Circular buffer for y COL coords.
float m_last_x
The previous x coordinate.
float m_y
The current y coordinate.
float m_mnp
The mean max pixel over the stats time.
INDI_SETCALLBACK_DECL(psfFit, m_indiP_fpsSource)
virtual int appStartup()
Startup function.
bool m_updated
Indicates that the coordinates were updated was updated.
int configureAcquisition()
Implementation of the framegrabber configureAcquisition interface.
pcf::IndiProperty m_indiP_sigmaMaxThreshUp
float m_dy
The offset in y to apply to non-skipped measurements.
int processImage(void *curr_src, const dev::shmimT &)
pcf::IndiProperty m_indiP_sigmaMaxThreshDown
mx::improc::eigenImage< float > m_image
Holds the raw image.
INDI_NEWCALLBACK_DECL(psfFit, m_indiP_sigmaPixThresh)
dev::shmimMonitor< psfFit > shmimMonitorT
The base shmimMonitor type.
int startAcquisition()
Implementation of the framegrabber startAcquisition interface.
#define FRAMEGRABBER_SETUP_CONFIG(cfig)
Call frameGrabberT::setupConfig with error checking for frameGrabber.
#define FRAMEGRABBER_APP_LOGIC
Call frameGrabberT::appLogic with error checking for frameGrabber.
#define FRAMEGRABBER_APP_SHUTDOWN
Call frameGrabberT::appShutdown with error checking for frameGrabber.
#define FRAMEGRABBER_UPDATE_INDI
Call frameGrabberT::updateINDI with error checking for frameGrabber.
#define FRAMEGRABBER_LOAD_CONFIG(cfig)
Call frameGrabberT::loadConfig with error checking for frameGrabber.
#define FRAMEGRABBER_APP_STARTUP
Call frameGrabberT::appStartup with error checking for frameGrabber.
#define CREATE_REG_INDI_NEW_REQUESTSWITCH(prop, name)
Create and register a NEW INDI property as a standard request switch, using the standard callback nam...
#define CREATE_REG_INDI_NEW_NUMBERF(prop, name, min, max, step, format, label, group)
Create and register a NEW INDI property as a standard number as float, using the standard callback na...
#define REG_INDI_SETPROP(prop, devName, propName)
Register a SET INDI property with the class, using the standard callback name.
#define CREATE_REG_INDI_RO_NUMBER(prop, name, label, group)
Create and register a RO INDI property as a number, using the standard callback name.
@ OPERATING
The device is operating, other than homing.
INDI_VALIDATE_CALLBACK_PROPS(function, ipRecv)
const pcf::IndiProperty & ipRecv
INDI_SETCALLBACK_DEFN(adcTracker, m_indiP_teldata)(const pcf
INDI_NEWCALLBACK_DEFN(acesxeCtrl, m_indiP_windspeed)(const pcf
std::unique_lock< std::mutex > lock(m_indiMutex)
constexpr static logPrioT LOG_INFO
Informational. The info log level is the lowest level recorded during normal operations.
constexpr static logPrioT LOG_NOTICE
A normal but significant condition.
#define SHMIMMONITORT_APP_STARTUP(SHMIMMONITORT)
Call shmimMonitorT::appStartup with error checking for a typedef-ed shmimMonitor.
#define SHMIMMONITOR_APP_SHUTDOWN
Call shmimMonitorT::appShutdown with error checking for shmimMonitor.
#define SHMIMMONITOR_APP_LOGIC
Call shmimMonitorT::appLogic with error checking for shmimMonitor.
#define SHMIMMONITORT_UPDATE_INDI(SHMIMMONITORT)
Call shmimMonitorT::updateINDI with error checking for a typedef-ed shmimMonitor.
#define SHMIMMONITOR_APP_STARTUP
Call shmimMonitorT::appStartup with error checking for shmimMonitor.
#define SHMIMMONITOR_LOAD_CONFIG(cfig)
Call shmimMonitorT::loadConfig with error checking for shmimMonitor.
#define SHMIMMONITORT_SETUP_CONFIG(SHMIMMONITORT, cfig)
Call shmimMonitorT::setupConfig with error checking for a typedef-ed shmimMonitor.
#define SHMIMMONITORT_APP_LOGIC(SHMIMMONITORT)
Call shmimMonitorT::appLogic with error checking for a typedef-ed shmimMonitor.
#define SHMIMMONITORT_APP_SHUTDOWN(SHMIMMONITORT)
Call shmimMonitorT::appShutodwn with error checking for a typedef-ed shmimMonitor.
#define SHMIMMONITOR_UPDATE_INDI
Call shmimMonitorT::updateINDI with error checking for shmimMonitor.
#define SHMIMMONITORT_LOAD_CONFIG(SHMIMMONITORT, cfig)
Call shmimMonitorT::loadConfig with error checking for a typedef-ed shmimMonitor.
#define SHMIMMONITOR_SETUP_CONFIG(cfig)
Call shmimMonitorT::setupConfig with error checking for shmimMonitor.
static std::string configSection()
static std::string indiPrefix()
A device base class which saves telemetry.
int checkRecordTimes(const telT &tel, telTs... tels)
Check the time of the last record for each telemetry type and make an entry if needed.
static std::string indiPrefix()
static std::string configSection()
Log entry recording framegrabber timings.
#define TELEMETER_APP_LOGIC
Call telemeter::appLogic with error checking.
#define TELEMETER_LOAD_CONFIG(cfig)
Call telemeter::loadConfig with error checking.
#define TELEMETER_APP_STARTUP
Call telemeter::appStartup with error checking.
#define TELEMETER_SETUP_CONFIG(cfig)
Call telemeter::setupConfig with error checking.
#define TELEMETER_APP_SHUTDOWN
Call telemeter::appShutdown with error checking.