|
|
#include "opticFlowADNS.h"
#include <wiringPi.h>
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "../../../../data/stbi/stb_image.h"
#include "../../../../data/stbi/stb_image_write.h"
static const uint8_t SROM[1986]={ 0xe6,0xff,0x40,0x22,0x86,0xaa,0x9f,0x73,0xdc,0x34,0x5f,0x1d,0x0d,0x05,0xe2,0xae, 0x5c,0xe7,0x5e,0x67,0x2f,0xd2,0x45,0xaa,0xb7,0x2d,0xf9,0x71,0xc0,0xe2,0x89,0x8f, 0x18,0xc0,0x50,0xb1,0x4c,0x5b,0x1e,0xb3,0x53,0x32,0x56,0x3a,0x14,0xe7,0x64,0x58, 0x41,0x24,0x03,0x3c,0xc5,0x2a,0x9c,0x8c,0x06,0xa7,0xa2,0x1f,0x23,0xf7,0x64,0xe6, 0x1b,0x50,0x97,0x3a,0x8a,0x86,0x16,0x4a,0xf5,0x77,0x5b,0x28,0x5d,0xa6,0xe0,0xcf, 0xc1,0x4a,0x28,0x62,0xfb,0x85,0x09,0x80,0x07,0xce,0x11,0x59,0xd4,0x89,0xcf,0xc1, 0x42,0x1d,0x05,0xea,0xa2,0x47,0x2e,0x0f,0xa1,0x10,0x0c,0xb4,0xe1,0x3f,0x95,0x70, 0x6d,0x4d,0xc0,0xce,0x8b,0x49,0x46,0x6e,0xfd,0x77,0x84,0x7e,0x62,0x0a,0x5d,0xaa, 0xc7,0x5d,0xa7,0x64,0x8d,0xc6,0x17,0x0d,0x44,0x6a,0xdc,0x56,0xae,0xa2,0x35,0xd0, 0xd9,0xdb,0xa7,0x68,0xc1,0xa5,0xcb,0xdb,0xda,0xdf,0xe9,0x65,0xb9,0x55,0x49,0xf0, 0x8f,0xe8,0x6e,0x4b,0xca,0xfc,0xe4,0x14,0x91,0x7a,0xaf,0x59,0x74,0x54,0x11,0x69, 0xf1,0xce,0x80,0xc0,0xd1,0x99,0x40,0x81,0x36,0x20,0x48,0x69,0x92,0xb1,0x44,0xdc, 0x97,0x4f,0x0e,0x95,0xc3,0x27,0x23,0xcf,0x7a,0xcd,0xe8,0x33,0x1b,0x12,0x9f,0xde, 0x2f,0x60,0x04,0x05,0x43,0x80,0x6b,0x0c,0xa1,0x72,0x26,0x36,0x46,0x51,0xbd,0x6c, 0xa2,0x4b,0x93,0x4b,0x3e,0x9b,0x5a,0x60,0xd8,0x23,0xa5,0x37,0x6b,0x04,0x37,0x11, 0xa8,0x32,0xec,0x1b,0x0b,0x06,0x6e,0x59,0xe8,0xf7,0x6c,0x26,0x03,0xb7,0xf2,0xec, 0x97,0x9d,0xc9,0x74,0x65,0xf3,0x90,0x58,0xa7,0x36,0x7b,0x6f,0xe8,0x31,0x05,0xfe, 0x04,0x9a,0xa4,0x73,0xa7,0xcf,0x27,0x78,0x8f,0xdc,0xd3,0xc6,0x14,0x55,0x76,0xa1, 0x24,0xcc,0xb0,0x38,0x53,0x7f,0x7b,0xf8,0x23,0xd7,0x09,0xd7,0xee,0xb8,0x19,0x1d, 0x0a,0x9a,0x70,0xdd,0xd8,0x5e,0x70,0x6f,0xd4,0xe9,0x2c,0x23,0x44,0xe0,0x3e,0xa7, 0x7d,0x31,0xf4,0x79,0xd0,0x40,0xfe,0x8e,0x8f,0x01,0xbc,0x4e,0x7f,0xbd,0x16,0xde, 0x9b,0xd5,0xcb,0xf5,0x18,0xb0,0x2a,0x00,0x31,0x26,0x89,0x4b,0x62,0x14,0x95,0x21, 0x45,0x2a,0x6a,0x99,0x38,0x8e,0xf3,0xad,0x25,0xfd,0xd0,0x1d,0x4a,0x91,0xf6,0xb7, 0x71,0x01,0x5a,0xcd,0xc1,0x99,0x50,0xad,0x77,0x55,0x95,0xfd,0x88,0x0e,0xde,0xeb, 0xb6,0x54,0xe1,0x8d,0xfd,0x6d,0x02,0x3d,0x00,0x15,0x75,0x43,0x88,0x17,0x04,0x15, 0x39,0x95,0xaa,0x25,0x40,0x67,0x91,0x9b,0x7e,0x1d,0x6b,0xf2,0xaa,0x73,0x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,0x97,0x5d,0x74, 0x3a,0xa4,0x42,0xf5,0x97,0xe9,0x81,0x73,0x71,0xf3,0x81,0x94,0x47,0x96,0x91,0x60, 0x6e,0x8f,0x0d,0xf2,0xa4,0x62,0x1e,0x58,0xcf,0x03,0x7c,0x31,0x5b,0xa8,0x24,0x1b, 0xc9,0x31,0x30,0x07,0xdd,0xaa,0x31,0x86,0x55,0x93,0x42,0xec,0x17,0xca,0xdc,0x20, 0x2a,0x60,0x2d,0x4e,0xce,0xae,0xa4,0x66,0x48,0x09,0x7a,0xa5,0x4d,0x4d,0xdd,0xc2, 0xb3,0x85,0x1a,0x6f,0x0c,0x27,0xa8,0x5d,0xf8,0x2e,0xde,0xa3,0xde,0xf4,0xe8,0xaa, 0x64,0xa7,0x69,0x9a,0xf8,0x78,0xba,0x73,0x8a,0xfd,0xee,0x06,0x72,0x5d,0xf2,0xe4, 0x90,0xf7,0xa0,0x46,0xe5,0x06,0x44,0xe3,0xc1,0xee,0x92,0x23,0xc2,0x7c,0xd1,0xd2, 0x31,0xba,0xeb,0x2f,0x16,0x4d,0xe2,0xf0,0xcf,0x98,0x38,0xbc,0x11,0x68,0xd7,0xc2, 0xeb,0x91,0xe6,0x34,0x60,0xd1,0x48,0x95,0x54,0x30,0x49,0xb3,0x30,0x8a,0x5a,0xb2, 0xec,0x14,0x41,0xe9,0xf4,0x84,0x46,0xea,0x31,0x5a,0xbc,0x29,0xb9,0xa1,0xc5,0x2c, 0x07,0x16,0xfd,0x90,0x5f,0x95,0x41,0xdc,0xf2,0xc3,0x6e,0x57,0xf0,0xea,0x0f,0xdc, 0xf0,0x58,0x5c,0x83,0x59,0x8a,0xff,0xe2,0xc9,0x33,0x5a,0xfc,0xde,0x4f,0x42,0x89, 0xbe,0x66,0xfe,0x27,0x93,0x94,0x2a,0xfb,0xca,0xd5,0x78,0x79,0x4a,0x64,0x71,0xb0, 0xb2,0xda,0x84,0x2c,0xd6,0x16,0xf3,0x79,0xfc,0x31,0x89,0x13,0xb8,0x39,0x2b,0x37, 0x5c,0xd3,0x1e,0xb6,0xfa,0x4a,0x79,0x62,0x9c,0x86,0xb6,0x22,0x00,0xcc,0xc6,0x05, 0x8c,0x86,0x98,0xd5,0x61,0x11,0xc2,0x67,0x06,0x8a,0x14,0x34,0xe9,0xd3,0x0a,0xae, 0x45,0x50,0x52,0x23,0x43,0xd5,0x6d,0x1f,0x45,0x7c,0x91,0xe5,0x2b,0x2d,0x2c,0xef, 0xbf,0x70,0x3a,0x0a,0x8c,0x50,0xc1,0xf4,0x21,0x0c,0x1e,0x34,0xc5,0xe3,0xad,0x7c, 0x94,0x87,0x49,0x96,0x58,0x91,0x8c,0xf9,0x26,0xa6,0xb6,0x72,0x0e,0xad,0x36,0x75, 0x38,0x0e,0x84,0x40,0xa1,0x60,0xc2,0xeb,0xd0,0xa8,0xbd,0x13,0x8d,0x3c,0x14,0x87, 0x49,0x96,0x48,0x4d,0x9f,0x21,0x4c,0xc2,0xf6,0xce,0x6c,0xd9,0x5a,0x2f,0x55,0x40, 0x47,0xd4,0x8c,0x7d,0x9b,0xbf,0xff,0xbe,0x88,0x06,0x7e,0x72,0x96,0xd3,0x66,0x0c, 0x9c,0x29,0x62,0xaf,0xb1,0xd8,0x32,0x84,0x19,0x08,0x44,0xac,0xdc,0x80,0x03,0x47, 0x18,0x8e,0xb5,0x2d,0xde,0x6a,0x2a,0xcd,0x41,0x82,0x8c,0x19,0x78,0xc8,0x08,0xa8, 0x42,0x01,0x1f,0x9b,0x73,0xab,0x71,0x42,0x99,0x97,0x75,0x44,0xf3,0x7c,0x42,0x47, 0x89,0x5b,0xb1,0xb1,0x34,0xe1,0x73,0xf2,0x60,0x68,0xc6,0x25,0x3b,0x12,0xdb,0x9e, 0x1f,0x90,0x88,0xb6,0x9b,0x49,0xa0,0xa6,0x9e,0x0e,0xb7,0x0c,0x42,0xb4,0x62,0x4a, 0x0f,0x5c,0x59,0xc2,0x83,0xd9,0x53,0xea,0x4e,0x5e,0xf0,0x8c,0x9d,0xb1,0xe1,0x1c, 0xa6,0x7f,0x07,0x76,0x39,0x8c,0x4f,0xc0,0x10,0x8f,0xaf,0xf1,0x53,0xe8,0x40,0x0e, 0x8c,0x96,0x9d,0x95,0x7a,0x5b,0x07,0x80,0xb1,0xac,0xe9,0x6f,0xd1,0xb2,0xc7,0x36, 0x96,0x07,0xf0,0xcc,0x08,0x9e,0x8d,0x94,0x99,0x9d,0x8b,0xb6,0x8e,0x26,0x9b,0x7b, 0xd8,0xe3,0x8e,0x79,0x43,0x29,0xc2,0x0a,0x84,0x89,0x4b,0xa5,0x1b,0x9e,0x87,0x79, 0x90,0xce,0x0e,0x81,0xb5,0xd0,0x11,0x83,0xb8,0xf7,0x1f,0xc4,0x14,0xca,0x11,0xb2, 0xea,0x12,0xdd,0xb3,0xe0,0xf5,0x57,0xed,0x17,0x2e,0x44,0x0f,0x8e,0xbe,0xa6,0xaf, 0xdf,0xe9,0xcb,0x3b,0x70,0x12,0xe2,0x55,0x67,0x67,0x5e,0x13,0x76,0x2d,0x71,0x07, 0x9e,0x7c,0xed,0xc9,0xe5,0x7f,0x04,0xe4,0x58,0x1f,0x6e,0x73,0x57,0xe0,0x71,0x43, 0xd9,0xf4,0x44,0x08,0x80,0x8e,0xad,0xbd,0x11,0x4c,0xfa,0x43,0x40,0xb2,0x40,0x95, 0xd8,0x8d,0x19,0x85,0x4d,0x89,0x14,0xfb,0x29,0x58,0x35,0xed,0x83,0x8b,0x61,0x35, 0x3c,0xd6,0x18,0xaa,0xe0,0xad,0x73,0x11,0x24,0x61,0x69,0x7b,0x14,0x56,0xf9,0x95, 0x48,0xfc,0x02,0xe9,0xf7,0xf1,0x28,0x15,0x4c,0xa0,0x73,0xc5,0x29,0x7d,0xab,0x4c, 0x67,0xd9,0xc5,0xd0,0x86,0xec,0x38,0xb9,0xa8,0x21,0xf4,0x53,0x78,0x78,0x3c,0xc6, 0xfb,0x12,0xe5,0xb3,0x94,0x37,0x7e,0x19,0x53,0xc1,0x75,0x03,0x57,0xab,0x59,0x2a, 0xcc,0x9a,0x60,0x34,0x08,0x8f,0x1e,0x36,0xec,0x89,0xb8,0x27,0xdc,0x8d,0x3d,0x2d, 0xbd,0x3f,0x5e,0x54,0x12,0x5f,0x6a,0x2c,0xfc,0x17,0x9a,0x92,0xc0,0x38,0x7f,0x7c, 0x67,0x37,0x47,0x8e,0x0e,0x1d,0x95,0x2c,0x10,0x0d,0x73,0xcd,0x9d,0x56,0x2c,0x68, 0x5b,0x05,0x2f,0xf5,0x07,0x5d,0x78,0x29,0xf6,0xbb,0x22,0xb8,0x58,0x8c,0x85,0x89, 0xe2,0x89,0x1c,0xd1,0x83,0x0f,0x8d,0x2e,0x4f,0xe8,0xff,0x6c,0x3f,0x99,0x4d,0xa7, 0xca,0x15,0xa9,0x59,0xea,0x33,0x25,0xff,0x80,0xaf,0x88,0x6e,0x93,0x0d,0xab,0x61, 0x00,0x18,0x11,0x9a,0x67,0xda,0x42,0x83,0xf8,0xf7,0x8d,0x19,0x3c,0xe4,0x36,0x64, 0x69,0xf0,0x07,0x55,0x7f,0x1f,0x23,0xbf,0x03,0x55,0xb0,0x5c,0x08,0x84,0x4b,0xc1, 0x0a,0xb9,0x53,0x75,0x9a,0x09,0x0b,0x37,0x55,0x63,0x9c,0xa5,0x7f,0x62,0xab,0x34, 0x1e,0xb4,0x24,0x48,0x83,0x57,0x93,0xff,0x1f,0x08,0x03,0x5c,0xe6,0xb6,0x6f,0x9b, 0x98,0x97,0x69,0x97,0xdb,0x67,0xc9,0xd7,0x84,0x66,0xc9,0xb6,0x9f,0x40,0x07,0x4b, 0x93,0x95,0x6d,0x9f,0x65,0xe6,0xcf,0xba,0x9d,0x70,0xa7,0x0b,0x2f,0x95,0x4c,0xdd, 0x1e,0xcc,0xfc,0x9c,0x35,0x89,0x70,0xa5,0x66,0xcc,0x1b,0x73,0xd8,0xf6,0x88,0x55, 0xb7,0x8f,0x7a,0x90,0xc0,0xba,0x35,0x2f,0xac,0x03,0x4c,0x7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9,0xdf,0x6d,0x84,0xa9,0x36,0x5f,0x20,0x51,0x0d, 0x00,0x88};
#define LOG( X ) m_pLog->Log( "OPFLOW", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "OPFLOW", this, _LOG_ERROR, X )
opticFlow::opticFlow( config_setting_t *Settings, PATHFINDER_DBC *DBC ):basicThread(){ m_pLog = basicLogCollection::getInstance(); m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "OPTIC_FLOW" ); m_pBLOG = objectPathfinderBinaryLog::getInstance(); m_pDBC = DBC; m_pBus = NULL; m_bWM = OF_WM_PICTURES;};
opticFlow::~opticFlow(){ waitThreadEnd( true ); if( m_pBus != NULL ) delete( m_pBus );};
// https://github.com/x75/adsn3080-emd/blob/master/ADNS3080-getmotion.c
bool opticFlow::create(){ uint8_t prodID; uint8_t revID; char tBuffer[128];
m_pBus = new spiPort( "/dev/spidev0.0", 500000 ); if( m_pBus == NULL ){ LOG_ERROR("Failed to open the SPI bus."); return false; }; prodID = m_pBus->read8( OF_SROM_PRODUCT_ID ); usleep(10); revID = m_pBus->read8( OF_SROM_REVISION_ID );
sprintf( tBuffer, "ADNS3080 ProductID: %d Rev. %d", prodID, revID ); LOG( tBuffer ); if( prodID != 0x17 ){ LOG_ERROR("SPI communication failed"); return false; } else { LOG("Load SROM"); if( ! uploadSRAM() ) { LOG_ERROR("Loading failure"); return false; }; m_nConfigB = m_pBus->read8( OF_SROM_CONFIG_BITS ); m_nConfigE = m_pBus->read8( OF_SROM_EXTEND_CONFIG ); //Apply config
m_nConfigB |= OF_REG_CB_RES; m_pBus->write8( OF_SROM_CONFIG_BITS, m_nConfigB ); SLEEP( 10 ); m_nConfigB = m_pBus->read8( OF_SROM_CONFIG_BITS );
sprintf( tBuffer, "Current Config: 0x%02X 0x%02X", m_nConfigB, m_nConfigE ); LOG( tBuffer );#ifdef DEBUG
if( ( OF_REG_CB_NLED & m_nConfigB ) == OF_REG_CB_NLED ) { LOG("Shutter mode On (LED only on when illumination is required)"); } else { LOG("Shutter mode Off (LED always on)"); }; if( ( OF_REG_CB_STEST & m_nConfigB ) == OF_REG_CB_STEST ) { LOG("Perform all System Tests"); } else { LOG("No Tests"); }; if( ( OF_REG_CB_RES & m_nConfigB ) == OF_REG_CB_RES ) { LOG("Resolution 1600 DPI"); } else { LOG("Resolution 400 DPI"); }; if( ( OF_REG_ECB_BUSY & m_nConfigE ) == OF_REG_ECB_BUSY ) { LOG("Write to the registers BUSY"); } else { LOG("Writing to the registers is allowed"); }; if( ( OF_REG_ECB_NPU & m_nConfigE ) == OF_REG_ECB_NPU ) { LOG("Enable serial port pull-up"); } else { LOG("Disable serial port pull-up"); }; if( ( OF_REG_ECB_NAGC & m_nConfigE ) == OF_REG_ECB_NAGC ) { LOG("AGC is disabled"); } else { LOG("AGC is active"); }; if( ( OF_REG_ECB_FFR & m_nConfigE ) == OF_REG_ECB_FFR ) { LOG("Fixed frame rate"); } else { LOG("Automatic frame rate"); };#endif
if( m_pDBC != NULL ) { m_pDBC->setOpfMode( 1 ); }; readBurstPixels(); }; return init();};
void opticFlow::m_fThreadProc( void ){ uint32_t pic_idx = 0; m_bThreadStatus = TH_WORKING; while( m_bThreadStatus < TH_ENDED ){ switch( m_bWM ) { case OF_WM_PICTURES:{ if( readBurstPixels( pic_idx, false ) ) pic_idx++; break; }; case OF_WM_MOVEMENT:{ PF_TIMESTAMP ts; if( readBurstMotion() ) { getPFTS(&ts); m_sEvent.seconds = ts.seconds; m_sEvent.milliseconds = ts.milliseconds; m_sEvent.bFLAGS = m_sMotion.bFLAGS; m_sEvent.dX = m_sMotion.dX; m_sEvent.dY = m_sMotion.dY; m_sEvent.bSurfaceQuality = m_sMotion.bSurfaceQuality; m_sEvent.bMaxPixel = m_sMotion.bMaxPixel; if( m_pBLOG!= NULL ) { m_pBLOG->registerOPF( &m_sEvent ); }; if( ( m_sMotion.bFLAGS & OF_MO_FLG_MD )== OF_MO_FLG_MD ){ if( m_pDBC != NULL ) { m_pDBC->updateOPF_MOV( &ts, &m_sMotion ); }; }; }; break; }; case OF_WM_SWITCH2MOV:{ if( uploadSRAM() ) { m_bWM = OF_WM_MOVEMENT; m_pDBC->setOpfMode( 0 ); } else { m_bWM = OF_WM_PICTURES; }; break; }; case OF_WM_SWITCH2PIC:{ if( readBurstPixels() ){ m_bWM = OF_WM_PICTURES; m_pDBC->setOpfMode( 1 ); } else { m_bWM = OF_WM_MOVEMENT; }; break; }; }; SLEEP(100); };};
bool opticFlow::resetChip(){ digitalWrite( OF_RESET_PIN, 1 ); usleep(100); digitalWrite( OF_RESET_PIN, 0 ); usleep(35000); return true;};bool opticFlow::resetMotion(){ if( m_pBus == NULL )return false; m_pBus->write8( OF_SROM_MOTION_CLR, 0xFF ); return true;};
bool opticFlow::setMode( uint8_t mode ){ if( m_pBus == NULL )return false; if( m_bWM == mode ) return true; if( mode == OF_WM_PICTURES ) { m_bWM = OF_WM_SWITCH2PIC; return true; }; if( mode == OF_WM_MOVEMENT ) { m_bWM = OF_WM_SWITCH2MOV; return true; }; return false;};
bool opticFlow::uploadSRAM(){ if( m_pBus == NULL )return false; resetChip(); m_pBus->write8( 0x20, 0x44 ); m_pBus->write8( 0x23, 0x07 ); m_pBus->write8( 0x24, 0x88 ); usleep( 10000 ); m_pBus->write8( OF_SROM_ENABLE, 0x18 ); m_pBus->writeMZ( OF_SROM_LOAD, (uint8_t *)&SROM, 1986 ); usleep( 200 ); m_pBus->write8( OF_SROM_ENABLE, 0xA1 ); usleep( 10000 ); uint8_t dL, dH, stt; uint16_t tCS; dL = m_pBus->read8( OF_SROM_DATA_OUT_LB ); dH = m_pBus->read8( OF_SROM_DATA_OUT_HB ); tCS = dH; tCS = ( tCS << 8 ) | dL;#ifdef DEBUG
char tBuff[64]; sprintf( tBuff, "SROM CS=0x%04X Must be: 0x%04X", tCS, OF_SROM_CS ); LOG( tBuff );#endif
if( tCS != OF_SROM_CS ) return false;
m_pBus->write8( OF_SROM_OBSERVATION, 0x00 ); usleep( 10000 ); stt = m_pBus->read8( OF_SROM_OBSERVATION );#ifdef DEBUG
sprintf( tBuff, "SROM Observation: 0x%02X", stt ); LOG( tBuff );#endif
return true;};
bool opticFlow::readBurstMotion(){ if( m_pBus == NULL )return false; //memset(&m_sMotion, 0, sizeof(OPF_MOTION));
return m_pBus->readMZ( OF_SROM_MOTION_BURST, (uint8_t *)&m_sMotion, sizeof(OPF_MOTION));};
bool opticFlow::readBurstPixels( uint32_t idx, bool wm_srom ){ uint8_t fBuffer[900]; PF_TIMESTAMP * tTS = NULL; if( m_pBus == NULL ) return false; if( m_pBus->write8( OF_SROM_FRAME_CAP, 0x83 ) ){ tTS = getPFTS(); if( tTS != NULL ){ usleep( 1510 ); if( m_pBus->readMZ( OF_SROM_PIXEL_BURST, (uint8_t *)fBuffer, 900 ) ){ for( int i = 0; i < 900; i++ ) { fBuffer[i] = ( fBuffer[i] & 0x3f ) << 2; }; if( m_pDBC == NULL ){ char tBuff[64]; sprintf( tBuff, "pic_%05d.png", idx ); stbi_write_png( tBuff, 30, 30, 1, (const void *)fBuffer, 30); } else { int olen; uint8_t * tPtr; tPtr = stbi_write_png_to_mem( fBuffer, 30, 30, 30, 1, &olen ); if( tPtr!= NULL ) { m_pDBC->updateOPF_PIC( tTS, tPtr, olen ); free( tPtr ); }; }; free( tTS ); resetChip(); if( wm_srom ) return uploadSRAM(); return true; }; }; free( tTS ); }; return false; };
bool opticFlow::isDead(){ return false;};
#undef LOG
#undef LOG_ERROR
|