You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
310 lines
9.3 KiB
310 lines
9.3 KiB
/*!
|
|
@brief Detector Class Header File
|
|
@copyright Laser Guard Ltd. ?2000-2012. All Rights Reserved.
|
|
@version 3.0 01/01/2012
|
|
@date 03/15/2012
|
|
@file Detector.h
|
|
@author Sergey Chizhevskiy
|
|
@author Evgeny Gagua
|
|
*/
|
|
#ifndef __DETECTOR__H__INCLUDED__
|
|
#define __DETECTOR__H__INCLUDED__
|
|
|
|
#include "StdAfx.h"
|
|
#include "..\lglib\comm\lgsm.h"
|
|
#include "stream.h"
|
|
#include "shadow.h"
|
|
#include "tracker.h"
|
|
#include "filters.h"
|
|
|
|
#ifdef STORE_FIRST_SAF
|
|
#ifdef WATCHDOG_ENABLED
|
|
#include "watchdog.h"
|
|
#endif
|
|
#endif
|
|
|
|
#define FREEZE_FLIP (-1)
|
|
|
|
typedef struct LGS_SETTINGS
|
|
{
|
|
int32_t nOrder;
|
|
int32_t nOffset;
|
|
int32_t nDelta;
|
|
int32_t nWidth;
|
|
int32_t nFlip;
|
|
int32_t nShift;
|
|
int32_t nSun;
|
|
}LGS_SETTINGS;
|
|
|
|
#define LRF_ID_MASTER 0
|
|
#define LRF_ID_SLAVE 1
|
|
#define LRF_ID_LFS_M1 0
|
|
#define LRF_ID_LFS_M2 1
|
|
#define LRF_ID_LFS_M3 2
|
|
#define LRF_ID_LFS_M4 3
|
|
/*!
|
|
@brief Class handles target detection from the ranges supplied from CBoard by CKernel object
|
|
|
|
*/
|
|
class CDetector {
|
|
public:
|
|
/*!
|
|
@brief Default Class Constructor
|
|
*/
|
|
CDetector();
|
|
/*!
|
|
@brief Default Class Destructor
|
|
*/
|
|
~CDetector();
|
|
|
|
public:
|
|
/*!
|
|
@brief Initialization of the object
|
|
@param[in] bDisabled Flag that is indicates if the detector is disabled
|
|
@param[in] pTracker Pointer to CTracker object to Track detected Targets
|
|
@param[in] pShadow Pointer to Masking engine CShadow
|
|
@param[in] nShift Angular Shift measured in sample units (not in degrees)
|
|
@param[in] nOrder Order of detection
|
|
@param[in] nOffset Offset of detection
|
|
@param[in] nDelta Delta of Detection
|
|
@param[in] nWidth Width to filter Targets
|
|
@param[in] nFlip initial number of Scans per Flip
|
|
@param[in] nSun - - --
|
|
@param[in] nLevelSST Scan to Scan alg. variable
|
|
@return true on successful initialization
|
|
@return false on failure
|
|
*/
|
|
bool Create( bool bDisabled, CTracker *pTracker, CShadow *pShadow, int32_t nShift, int32_t nOrder, int32_t nOffset, int32_t nDelta, int32_t nWidth, int32_t nFlip, int32_t nSun, int32_t nLevelSST );
|
|
/*!
|
|
@brief Initialization of the object
|
|
@param[in] bDisabled Flag that is indicates if the detector is disabled
|
|
@param[in] pTracker Pointer to CTracker object to Track detected Targets
|
|
@param[in] pShadow Pointer to Masking engine CShadow
|
|
@param[in] nShift Angular Shift in detection measured in samples (not in degrees)
|
|
@param[in] pFileName Pointer to String with Parameters File Name
|
|
@return true on successful initialization
|
|
@return false on failure
|
|
*/
|
|
#ifdef STORE_FIRST_SAF
|
|
#ifdef WATCHDOG_ENABLED
|
|
bool Create( bool bDisabled, CTracker *pTracker, CShadow *pShadow, int16_t nShift, PCHAR pFileName, CWatchDog *pWD, uint8_t LRFID );
|
|
#else
|
|
bool Create( bool bDisabled, CTracker *pTracker, CShadow *pShadow, int16_t nShift, PCHAR pFileName, uint8_t LRFID );
|
|
#endif
|
|
#else
|
|
bool Create( bool bDisabled, CTracker *pTracker, CShadow *pShadow, int16_t nShift, PCHAR pFileName );
|
|
#endif
|
|
void Destroy();
|
|
|
|
public:
|
|
bool Reset( bool bFullReset );
|
|
/*!
|
|
@brief Resets Ranges Conveyor
|
|
*/
|
|
void ResetAngles( void );
|
|
/*!
|
|
@brief Get Current Detection Parameters into structure LGS::LGS_PARAMETERS
|
|
@param[out] pParameters LGS::LGS_PARAMETERS Structure to hold retrieved parameters
|
|
*/
|
|
void GetParameters( LGS::LGS_PARAMETERS *pParameters );
|
|
/*!
|
|
@brief Set Detection Paramneters from the LGS::LGS_PARAMETERS structure
|
|
@param[in] pParameters LGS::LGS_PARAMETERS Structure to hold desired parameters
|
|
*/
|
|
void SetParameters( LGS::LGS_PARAMETERS *pParameters );
|
|
|
|
public:
|
|
void Invalidate( bool bZero, bool bSun, uint16_t Range, bool bAllowFlip, bool bTargetSSTDone = false );
|
|
bool IsAllowFlip() { if( m_bDisabled ) return true; return m_bAllowFlip; }
|
|
bool IsSSTPassed() { return m_bSSTPassed; }
|
|
public:
|
|
bool GetLastErrorSun() {
|
|
#ifndef NO_DETECTOR_FILTERS
|
|
return m_FilterSun.GetLastErrorSun();
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
bool GetLastErrorAngle() { bool bError = m_bErrorAngle; m_bErrorAngle = false; return bError; }
|
|
int16_t GetLastErrorAngleValue() { int16_t nAngle = m_nErrorAngle; m_nErrorAngle = 0; return nAngle; }
|
|
|
|
public:
|
|
void BorderEnable( bool bEnable );
|
|
#ifdef DRAW_BORDER_BY_SAF_MAX
|
|
bool GetBorderRange( uint16_t nAngle, PWORD pRange, bool GetMin = false );
|
|
bool GetFullBorderRange( uint16_t nAngle, PWORD pRange, bool GetMin = false );
|
|
#else
|
|
bool GetBorderRange( uint16_t nAngle, PWORD pRange, bool GetMin = true );
|
|
bool GetFullBorderRange( uint16_t nAngle, PWORD pRange, bool GetMin = true );
|
|
#endif
|
|
|
|
|
|
public:
|
|
CFilterWidth *GetFilterWidth() { return &m_FilterWidth; }
|
|
public:
|
|
bool StartLearningCycle( void );
|
|
public:
|
|
typedef struct SAF
|
|
{
|
|
uint16_t nMax;
|
|
uint16_t nMin;
|
|
}SAF, far * LPSAF;
|
|
public:
|
|
typedef struct QPD
|
|
{
|
|
uint8_t nOffset;
|
|
uint8_t nOrder;
|
|
}QPD, far * LPQPD;
|
|
|
|
#ifndef INCLUDE_WINDOWS_DEFINITIONS
|
|
public:
|
|
#else
|
|
private:
|
|
#endif
|
|
LPSAF m_ppSAF[3]; /*!< check max and min */
|
|
LPQPD m_ppQPD[2]; /*!< quality point description */
|
|
uint16_t SpDA[3]; /*!< For Calculation of the spikes */
|
|
int16_t m_nActiveSAF; /*!< stores number active SAF (detection SAF) */
|
|
int16_t m_nActiveSAFReady; /*!< holds amount of angles remainig until SAF threshold calculation stops */
|
|
public:
|
|
#ifdef LGS_BOARDSAMPLE_RATIO
|
|
int16_t m_vAngle; /*!< current virtual measurement angle ( according to encoder )*/
|
|
int16_t m_nAngleDivider; /*!< ratio of virtual angle to physycal */
|
|
#endif
|
|
int16_t m_nAngle; /*!< current physycal angle ( according to encoder ) */
|
|
#ifdef ALS_300
|
|
int16_t m_nAngle18K;
|
|
#endif
|
|
private:
|
|
bool m_bDisabled;
|
|
bool m_bBlind180;
|
|
bool m_bWaitFirstZero; /*!< used during waiting first ZERO */
|
|
bool m_bWaitFirstSAF; /*!< used during waiting first SAF (area studing) */
|
|
int16_t m_nFlip; /*!< stores number rounds before flip */
|
|
int16_t m_nFlipLoopSAF; /*!< stores number of angles after SAF start */
|
|
|
|
bool m_bSemiFlip; /*!< perform flip into to stages (for making more linear calculation power consumption) */
|
|
bool m_bAllowFlip; /*!< prevent simultaneous flip */
|
|
bool m_bSSTPassed;
|
|
bool m_bFlipIsFrozen;
|
|
bool m_bSAFIsFrozen;
|
|
|
|
bool m_bTarget; /*!< indicate that before this angle was target */
|
|
uint16_t m_nTargetRange; /*!< stores last target range */
|
|
int32_t m_nTargetWidth; /*!< used for accumulate target sun width */
|
|
int32_t m_nTargetDelta; /*!< used for accumulate target deltas */
|
|
int32_t m_nTargetCount; /*!< used for colculating target angle width */
|
|
bool m_bTargetWhite; /*!< used for delta calculation */
|
|
#ifdef CHECK_SHADOWED_TARGETS
|
|
bool m_bTargetSeenOutsideOfShadow; /*!< used for Masking targets */
|
|
#endif
|
|
#ifndef NO_DETECTOR_FILTERS
|
|
// spikes algorithm
|
|
int16_t m_nSpikeCount; // amount of spikes per current loop
|
|
int16_t m_nSpikeTempCount; // temporary storage for spikes amount during target building
|
|
|
|
// calculate long spikes to minimum (fog)
|
|
int16_t m_nSpikeFogCount;
|
|
int16_t m_nSpikeFogTempCount;
|
|
bool m_bSpikeFogBlind;
|
|
bool m_bSpikeFogNoTarget;
|
|
|
|
int16_t m_pSpikeHistory[ LGS_MAX_SPIKE_HISTORY ];
|
|
int16_t m_nSpikeHistoryPosition;
|
|
int16_t m_nSpikeHistoryCount;
|
|
int16_t m_nSpikeHistoryMax;
|
|
int16_t m_nFlipWaitHistory; // left FLIPs before floating starts
|
|
|
|
#endif // NO_DETECTOR_FILTERS
|
|
|
|
int16_t m_nFloatFlip; // floating flip
|
|
int16_t m_nFlipCounter;
|
|
#ifdef INFINITE_SAF_STUDY
|
|
LPWORD m_lpMinBorder;
|
|
LPWORD m_lpMaxBorder;
|
|
#else
|
|
LPWORD m_lpBorder;
|
|
#endif
|
|
uint16_t m_nBorderRangeCount;
|
|
#ifdef INFINITE_SAF_STUDY
|
|
int32_t m_nMinBorderRangeSum;
|
|
int32_t m_nMaxBorderRangeSum;
|
|
#else
|
|
int32_t m_nBorderRangeSum;
|
|
#endif
|
|
bool m_bBorderEnable;
|
|
int16_t m_nBorderAngle;
|
|
int32_t m_nBorderSector;
|
|
bool m_bBorderWaitZero;
|
|
|
|
bool m_bSkipDetection; // to perform soft reset
|
|
|
|
#ifdef STORE_FIRST_SAF
|
|
// Freezing Mode of Detector g_bSAFFreezEnable
|
|
public:
|
|
bool load_stored_SAF( void );
|
|
bool save_current_SAF( void );
|
|
bool isSAFFrozen( void ){ return m_bFreezingSAF; };
|
|
private:
|
|
#ifdef SKIP_FIRST_N_FLIPS
|
|
uint8_t m_bInitialFlipsToSkip;
|
|
#endif
|
|
#ifdef WATCHDOG_ENABLED
|
|
CWatchDog *m_pWatchDog;
|
|
#endif
|
|
uint8_t m_bSAFSaveStage;
|
|
void unifyDataSAF( void );
|
|
bool m_bFreezingSAF;
|
|
uint8_t m_nLRFID;
|
|
#endif
|
|
|
|
#ifndef NO_DETECTOR_FILTERS
|
|
// filters
|
|
CFilterSun m_FilterSun;
|
|
CFilterMediumRange m_FilterMediumRange;
|
|
CFilterPD m_FilterPD;
|
|
CFilterFog m_FilterFog;
|
|
#endif
|
|
|
|
CFilterWidth m_FilterWidth;
|
|
private:
|
|
CShadow * m_pShadow; // plaseholder for hiddenzones
|
|
CTracker * m_pTracker; // scan to scan tracking
|
|
|
|
private:
|
|
bool m_bErrorAngle; // error angle
|
|
int16_t m_nErrorAngle; // error angle
|
|
bool m_bShowErrorAngle; // prevent angle error immidiatly after reset
|
|
|
|
private:
|
|
LGS_SETTINGS m_Settings; // settings
|
|
CHAR m_pSettingsFileName[LGS_MAX_SETTINGS_FILENAME];
|
|
|
|
#ifndef INCLUDE_WINDOWS_DEFINITIONS
|
|
public:
|
|
enum{
|
|
SPIKE_NONE = 0, // 00000000
|
|
SPIKE_MASK = 1, // 00000001
|
|
SPIKE_BEFORE_SST = 2, // 00000010
|
|
SPIKE_AFTER_SST = 4, // 00000100
|
|
SPIKE_WHITE = 8, // 00001000
|
|
SPIKE_BLACK = 16 // 00010000
|
|
};
|
|
typedef struct SPIKE
|
|
{
|
|
uint8_t nType;
|
|
uint16_t nRange;
|
|
};
|
|
inline int16_t SAFGetActive() { return m_nActiveSAF; }
|
|
inline SAF& SAFGetSAF( int16_t nSAF, int16_t nAngle ) { return m_ppRealSAF[nSAF][nAngle]; }
|
|
inline SPIKE& SAFGetSpike( int16_t nAngle ) { return m_pSpike[nAngle]; }
|
|
inline bool SAFIsReady() { return (!m_bWaitFirstSAF) && (m_nFlip != m_Settings.nFlip); }
|
|
|
|
public:
|
|
SAF m_ppRealSAF[2][ LGS_REAL_DETECTOR_ANGLES ];
|
|
SPIKE m_pSpike[ LGS_REAL_DETECTOR_ANGLES ];
|
|
#endif
|
|
|
|
};
|
|
|
|
#endif
|