10#include "../../libMagAOX/libMagAOX.hpp"
11#include "../../magaox_git_version.h"
145 mx::improc::eigenImage<float>
m_ref;
164 mx::sigproc::circularBufferIndex<float, cbIndexT>
m_pcb;
165 mx::sigproc::circularBufferIndex<float, cbIndexT>
m_xcb;
166 mx::sigproc::circularBufferIndex<float, cbIndexT>
m_ycb;
376 config.add(
"fitter.fpsDevice",
384 "Device name for getting fps to set circular buffer length." );
385 config.add(
"fitter.fpsProperty",
387 "fitter.fpsProperty",
393 "Property name for getting fps to set circular buffer length. Default is 'fps'." );
394 config.add(
"fitter.fpsElement",
402 "Property name for getting fps to set circular buffer length. Default is 'current'." );
403 config.add(
"fitter.fpsTol",
411 "Tolerance for detecting a change in FPS. Default is 0." );
412 config.add(
"fitter.defaultFPS",
420 "Default FPS at startup, will enable changing average length with psdTime before INDI available." );
422 config.add(
"fitter.shutterDevice",
424 "fitter.shutterDevice",
430 "Device name for getting shutter state to reset circular buffers" );
431 config.add(
"fitter.shutterProperty",
433 "fitter.shutterProperty",
439 "Property name for getting shutter state to reset circular buffers. Default is 'shutter'." );
440 config.add(
"fitter.shutterElement",
442 "fitter.shutterElement",
448 "Property name for getting shutter state to reset circular buffers. Default is 'toggle'." );
450 config.add(
"fitter.deltaPixThresh",
452 "fitter.deltaPixThresh",
458 "Threshold in pixels for skipping frame due to mismatch between max and c.o.l. Default 8." );
459 config.add(
"fitter.sigmaMaxThreshUp",
461 "fitter.sigmaMaxThreshUp",
467 "Threshold in rms for skipping frame due to max positive difference from mean max. Default 5." );
468 config.add(
"fitter.fractionMaxThreshDown",
470 "fitter.fractionMaxThreshDown",
473 "fractionMaxThreshDown",
476 "Threshold in fraction of the mean max for skipping frame due to drop from mean max. Default 0.1" );
478 config.add(
"fitter.sigmaPixThresh",
480 "fitter.sigmaPixThresh",
486 "Threshold in rms for skipping frame due to max difference from last value. Example: if this is set "
487 "to 10, then the pixel postion has to change from -5 sigma to + 5 sigma to be rejected. Default 10." );
608 for(
size_t n = 0;
n <
m_xcbD.size(); ++
n )
647 std::cerr <<
"skipping frames: \n";
682 {
"max_mean",
"max_rms",
"x_mean",
"x_rms",
"y_mean",
"y_rms" },
705 static_cast<void>(
dummy );
714 m_pcb.maxEntries( 0 );
715 m_xcb.maxEntries( 0 );
716 m_ycb.maxEntries( 0 );
761 static_cast<void>(
dummy );
812 max =
m_image.maxCoeff( &x, &y );
834 if(
m_xcb.maxEntries() > 0 )
836 m_pcb.nextEntry( max );
851 if(
m_pcb.maxEntries() > 0 )
853 m_pcb.nextEntry( max );
867 if(
m_pcb.maxEntries() > 0 )
869 m_pcb.nextEntry( max );
883 if(
m_xcb.maxEntries() > 0 )
885 m_pcb.nextEntry( max );
899 if(
m_ycb.maxEntries() > 0 )
901 m_pcb.nextEntry( max );
949 if(
m_xcb.maxEntries() > 0 )
951 m_pcb.nextEntry( max );
965 static_cast<void>(
dummy );
982 static_cast<void>(
dummy );
1000 static_cast<void>(
dummy );
1017 static_cast<void>(
dummy );
1082 (
reinterpret_cast<float *
>(
dest ) )[0] =
m_x -
m_dx;
1083 (
reinterpret_cast<float *
>(
dest ) )[1] =
m_y -
m_dy;
1087 (
reinterpret_cast<float *
>(
dest ) )[0] =
m_x;
1088 (
reinterpret_cast<float *
>(
dest ) )[1] =
m_y;
1105 if(
ipRecv.find(
"request" ) !=
true )
1110 if(
ipRecv[
"request"].getSwitchState() == pcf::IndiElement::On )
1113 shmimMonitorT::m_restart =
true;
1125 if( indiTargetUpdate( m_indiP_statsTime, target,
ipRecv,
true ) < 0 )
1127 log<software_error>( { __FILE__, __LINE__ } );
1131 m_fitCircBuffMaxTime = target;
1133 shmimMonitorT::m_restart =
true;
1135 log<text_log>(
"set statsTime = " + std::to_string( m_fitCircBuffMaxTime ),
logPrio::LOG_NOTICE );
1146 if( indiTargetUpdate( m_indiP_deltaPixThresh, target,
ipRecv,
true ) < 0 )
1148 log<software_error>( { __FILE__, __LINE__ } );
1152 m_deltaPixThresh = target;
1153 updatesIfChanged<float>( m_indiP_deltaPixThresh, {
"current",
"target" }, { m_deltaPixThresh, m_deltaPixThresh } );
1154 log<text_log>(
"set deltaPixThresh = " + std::to_string( m_deltaPixThresh ),
logPrio::LOG_NOTICE );
1164 if( indiTargetUpdate( m_indiP_sigmaMaxThreshUp, target,
ipRecv,
true ) < 0 )
1166 log<software_error>( { __FILE__, __LINE__ } );
1170 m_sigmaMaxThreshUp = target;
1171 updatesIfChanged<float>(
1172 m_indiP_sigmaMaxThreshUp, {
"current",
"target" }, { m_sigmaMaxThreshUp, m_sigmaMaxThreshUp } );
1174 log<text_log>(
"set sigmaMaxThreshUp = " + std::to_string( m_sigmaMaxThreshUp ),
logPrio::LOG_NOTICE );
1184 if( indiTargetUpdate( m_indiP_fractionMaxThreshDown, target,
ipRecv,
true ) < 0 )
1186 log<software_error>( { __FILE__, __LINE__ } );
1190 m_fractionMaxThreshDown = target;
1191 updatesIfChanged<float>(
1192 m_indiP_fractionMaxThreshDown, {
"current",
"target" }, { m_fractionMaxThreshDown, m_fractionMaxThreshDown } );
1194 log<text_log>(
"set fractionMaxThreshDown = " + std::to_string( m_fractionMaxThreshDown ),
logPrio::LOG_NOTICE );
1204 if( indiTargetUpdate( m_indiP_sigmaPixThresh, target,
ipRecv,
true ) < 0 )
1206 log<software_error>( { __FILE__, __LINE__ } );
1210 m_sigmaPixThresh = target;
1211 updatesIfChanged<float>( m_indiP_sigmaPixThresh, {
"current",
"target" }, { m_sigmaPixThresh, m_sigmaPixThresh } );
1213 log<text_log>(
"set fractionMaxThreshDown = " + std::to_string( m_sigmaPixThresh ),
logPrio::LOG_NOTICE );
1223 if( indiTargetUpdate( m_indiP_dx, target,
ipRecv,
true ) < 0 )
1225 log<software_error>( { __FILE__, __LINE__ } );
1241 if( indiTargetUpdate( m_indiP_dy, target,
ipRecv,
true ) < 0 )
1243 log<software_error>( { __FILE__, __LINE__ } );
1257 if(
ipRecv.find( m_fpsElement ) !=
true )
1262 std::lock_guard<std::mutex> guard( m_indiMutex );
1264 realT fps =
ipRecv[m_fpsElement].get<
float>();
1266 if( fabs( fps - m_fps ) > m_fpsTol )
1270 shmimMonitorT::m_restart =
true;
1271 frameGrabberT::m_reconfig =
true;
1281 if(
ipRecv.find( m_shutterElement ) !=
true )
1286 std::lock_guard<std::mutex> guard( m_indiMutex );
1289 if(
ipRecv[m_shutterElement].getSwitchState() == pcf::IndiElement::On )
1298 if( shutter != m_shutter )
1300 m_shutter = shutter;
1302 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.
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_fractionMaxThreshDown
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.
uint64_t m_skipped_DeltaFromMax
INDI_NEWCALLBACK_DECL(psfFit, m_indiP_sigmaMaxThreshUp)
mx::sigproc::circularBufferIndex< float, cbIndexT > m_pcb
Circular buffer for max pixel (p=peak)
uint64_t m_skipped_DeltaFromMax_last
std::string m_shutterProperty
Property name for getting shutter state.
bool m_skipped
Indicates that the image failed quality control and this is a skip frame.
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 m_fpsTol
The tolerance for detecting a change in FPS.
float fps()
Implementation of the framegrabber fps interface.
pcf::IndiProperty m_indiP_dx
uint64_t m_skipped_YRms_last
float m_mny
The mean y coord over the stats time.
uint64_t m_skipped_XRms_last
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.
std::string m_shutterElement
Element name for getting shutter state.
float m_rmsy
The rms y coord over the stats time.
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.
std::string m_fpsDevice
Device name for getting fps to set circular buffer length.
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
std::string m_fpsProperty
Property name for getting fps to set circular buffer length.
float m_fps
The frame rate from the source camera.
INDI_NEWCALLBACK_DECL(psfFit, m_indiP_deltaPixThresh)
pcf::IndiProperty m_indiP_shutter
float m_last_y
The previous y coordinate.
int allocate(const dev::shmimT &)
pcf::IndiProperty m_indiP_fractionMaxThreshDown
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
uint64_t m_skipped_MaxRmsUp_last
std::string m_fpsElement
Element name for getting fps to set circular buffer length.
std::string m_shutterDevice
Device name for getting shutter state.
mx::sigproc::circularBufferIndex< float, cbIndexT > m_ycb
Circular buffer for y COL coords.
INDI_SETCALLBACK_DECL(psfFit, m_indiP_shutter)
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.
uint64_t m_skipped_updating_last
bool m_updated
Indicates that the coordinates were updated was updated.
int configureAcquisition()
Implementation of the framegrabber configureAcquisition interface.
uint64_t m_skipped_MaxRmsUp
pcf::IndiProperty m_indiP_sigmaMaxThreshUp
float m_dy
The offset in y to apply to non-skipped measurements.
uint64_t m_skipped_updating
int processImage(void *curr_src, const dev::shmimT &)
INDI_NEWCALLBACK_DECL(psfFit, m_indiP_fractionMaxThreshDown)
mx::improc::eigenImage< float > m_image
Holds the raw image.
uint64_t m_skipped_MaxRmsDown
uint64_t m_skipped_MaxRmsDown_last
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 INDI_NEWCALLBACK_DEFN(class, prop)
Define the callback for a new property request.
#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 INDI_SETCALLBACK_DEFN(class, prop)
Define the callback for a set property request.
#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.
#define INDI_VALIDATE_CALLBACK_PROPS(prop1, prop2)
Standard check for matching INDI properties in a callback.
const pcf::IndiProperty & ipRecv
std::unique_lock< std::mutex > lock(m_indiMutex)
static constexpr logPrioT LOG_NOTICE
A normal but significant condition.
static constexpr logPrioT LOG_INFO
Informational. The info log level is the lowest level recorded during normal operations.
#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.