SmartWheels self-driving race car. Designed for NXP Cup. Uses FRDM-KL25Z, area-scan camera, and simple image processing to detect and navigate any NXP spec track.

Dependencies:   TSI USBDevice mbed-dev

Fork of SmartWheels by haofan Zheng

Revision:
96:ec89c4d1383d
Parent:
93:8e1bd3602d53
Child:
97:0ed9ede9a995
Child:
98:fc92bb37ee17
--- a/Hardwares/ArduCAM.cpp	Wed Apr 19 19:26:49 2017 +0000
+++ b/Hardwares/ArduCAM.cpp	Wed Apr 19 19:43:15 2017 +0000
@@ -34,12 +34,8 @@
 static volatile uint8_t centerLine[CAM_ROI_UPPER_LIMIT * 2];
 static volatile uint8_t is_encounter_terminate = 0;
 static volatile uint8_t is_border_find = BOTH_NOT_FOUND;
-//static Thread * m_imgProcessThread = NULL;
-//static Ticker m_tickerImgProc;
 
-//void image_processing();
 void cal_black_calibrate();
-//void tick_image_proc();
 
 inline void ardu_cam_spi_write_8(int address, int value)
 {
@@ -75,34 +71,9 @@
 #endif
     return value;
 }
-/*
-inline void ardu_cam_spi_set_burst()
-{
-    cam_cs = 0;
-    
-    g_spi_port.write(BURST_FIFO_READ & 0x7F);
-    
-    cam_cs = 1;
-}
-
-inline uint16_t ardu_cam_spi_burst_read_16()
-{
-    cam_cs = 0;
-    
-    uint16_t value = static_cast<uint16_t>(g_spi_port.write(0x00));
-    value = (value << 8) & 0xFF00;
-    value = value | static_cast<uint16_t>(g_spi_port.write(0x00));
-    
-    cam_cs = 1;
-    return value;
-}
-*/
-
 
 bool ardu_cam_init()
 {
-    //char buf[20];
-    
     CamRegBuf * camReg = new CamRegBuf(CAM_SCCB_WRITE, CAM_SCCB_READ);
 
     camReg->WriteRegSet(ResetProg);
@@ -113,54 +84,23 @@
 #if defined(ARDUCAM_OV2640)
     camReg->SCCBWrite(0xff, 0x01);
 #endif
-    //uint8_t camVer = camReg->SCCBRead(CAM_PID_ADDR);
-    //sprintf(buf, "Cam VerH %#x", camVer);
-    //g_core.GetUSBServer().PushReliableMsg('D', buf);
     
-    //camVer = camReg->SCCBRead(CAM_VER_ADDR);
-    //sprintf(buf, "Cam VerL %#x", camVer);
-    //g_core.GetUSBServer().PushReliableMsg('D', buf);
-
-
     delete camReg;
     camReg = NULL;
     
-    
-    
-    
     uint8_t VerNum = ardu_cam_spi_read_8(0x40);
     VerNum = ardu_cam_spi_read_8(0x40);
     
-    
-    //sprintf(buf, "Ardu Ver %#x", VerNum);
-    //g_core.GetUSBServer().PushReliableMsg('D', buf);
-    
     ardu_cam_spi_write_8(ARDUCHIP_TEST1, ARDUCHIP_TEST_MSG);
     uint8_t testV = ardu_cam_spi_read_8(ARDUCHIP_TEST1);
     if(VerNum != ARDUCHIP_VER_NUM || testV != ARDUCHIP_TEST_MSG)
     {
-        //g_core.GetUSBServer().PushReliableMsg('D', "CameraInit Fa");
         return false;
     }
-    //g_core.GetUSBServer().PushReliableMsg('D', "CameraInit Su");
-    
-    //ardu_cam_set_mode(MCU2LCD_MODE);
-    ardu_cam_spi_write_8(ARDUCHIP_CAP_CTRL, 0x00);
-    //ardu_cam_start_capture();
-    
     
-    //unsigned char tempV = ardu_cam_read_reg(ARDUCHIP_MODE);
-    //sprintf(buf, "Ardu Stat %#x", tempV);
-    //g_core.GetUSBServer().PushReliableMsg('D', buf);
+    ardu_cam_spi_write_8(ARDUCHIP_CAP_CTRL, 0x00);
     
-    //tempV = ardu_cam_read_reg(ARDUCHIP_CAP_CTRL);
-    //sprintf(buf, "Ardu FS1 %#x", tempV);
-    //g_core.GetUSBServer().PushReliableMsg('D', buf);
     cal_black_calibrate();
-    //m_imgProcessThread = new Thread(osPriorityRealtime); //osPriorityAboveNormal //osPriorityHigh //osPriorityRealtime
-    //m_imgProcessThread->set_priority(osPriorityRealtime);
-    //m_imgProcessThread->start(callback(image_processing));
-    //m_tickerImgProc.attach(&tick_image_proc, 0.1f);
     
     return true;
 }
@@ -200,76 +140,7 @@
     
     return static_cast<uint8_t>(pixel);
 }
-/*
-void ardu_cam_print_debug()
-{
-    uint32_t len = ardu_cam_get_fifo_length();
-    //char buf[20];
-    //sprintf(buf, "Cam L %#x", len);
-    //g_core.GetUSBServer().PushReliableMsg('D', buf);
-    
-    //if(len < (RESOLUTION_HEIGHT * RESOLUTION_WIDTH * 2))
-    //    return;
-    
-    //Begin output the picture
-    std::string lineBuf;
-#if defined(MANUAL_REDUCE_RESULOTION_BY2)
-    lineBuf.resize((RESOLUTION_WIDTH / 2) + 1);
-#else
-    lineBuf.resize(RESOLUTION_WIDTH + 1);
-#endif
-    
-    //ardu_cam_spi_set_burst();
 
-    //ardu_cam_get_pixel(); //Get the first dummy pixel
-
-
-    for (uint8_t i = 0; i < RESOLUTION_HEIGHT; ++i)
-    {
-#if defined(MANUAL_REDUCE_RESULOTION_BY2)
-        lineBuf[0] = i / 2;
-        
-        for (int j = 0; j < RESOLUTION_WIDTH; ++j)
-        {
-            if(i % 2 == 0 || j % 2 == 0)
-            {
-                ardu_cam_get_pixel();
-            }
-            else
-            {
-                lineBuf[(j / 2) + 1] = ardu_cam_get_pixel();
-            }
-        }
-        
-        if(i % 2 == 0)
-        {
-            
-        }
-        else
-        {
-            g_core.GetUSBServer().PushReliableMsg('P', lineBuf);
-            wait(0.35);
-        }
-        
-#else
-
-        lineBuf[0] = i;
-        
-        for (int j = 0; j < RESOLUTION_WIDTH; ++j)
-        {
-            //uint8_t p = ardu_cam_get_pixel();
-            lineBuf[j + 1] = ardu_cam_get_pixel();
-        }
-        
-        //g_core.GetUSBServer().PushReliableMsg('P', lineBuf);
-        wait(0.35);
-        
-#endif
-        
-    }
-
-}
-*/
 uint8_t ardu_cam_is_capture_finished()
 {
     return (ardu_cam_spi_read_8(ARDUCHIP_TRIG) & CAP_DONE_MASK);
@@ -412,14 +283,6 @@
         uint8_t isBorderFound = BOTH_NOT_FOUND;
         is_encounter_terminate = 0;
         for (uint8_t i = 0; i < CAM_ROI_UPPER_LIMIT; ++i)
-        /*{
-            for (uint8_t j = 0; j < RESOLUTION_WIDTH; ++j)
-            {
-                ardu_cam_spi_read_8(SINGLE_FIFO_READ);
-                ardu_cam_spi_read_8(SINGLE_FIFO_READ);
-            }
-        }*/
-        //for(uint8_t i = CAM_ROI_UPPER_LIMIT; i < (2 * CAM_ROI_UPPER_LIMIT); ++i)
         {
 #if defined(CAM_DISP_IMG) or defined(CAM_DISP_DEBUG)
             ardu_utft_set_camimg_row(CAM_ROI_UPPER_LIMIT - i);
@@ -484,10 +347,6 @@
                 break;
             }
         }
-        
-        
-        //counter.Update();
-        //Thread::signal_wait(IMG_PROC_SIGNAL, osWaitForever);
     }
 }
 
@@ -523,12 +382,7 @@
 {
     return is_border_find;
 }
-/*
-void tick_image_proc()
-{
-    m_imgProcessThread->signal_set(IMG_PROC_SIGNAL);
-}
-*/
+
 #ifdef __cplusplus
 }
 #endif