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:
65:295c222fdf88
Parent:
64:43ab429a37e0
Child:
70:311d32a596db
diff -r 43ab429a37e0 -r 295c222fdf88 Hardwares/ArduCAM.cpp
--- a/Hardwares/ArduCAM.cpp	Mon Apr 10 16:44:31 2017 +0000
+++ b/Hardwares/ArduCAM.cpp	Wed Apr 12 22:16:40 2017 +0000
@@ -25,13 +25,13 @@
 
 const static uint8_t CAM_BLK_CAL_LEFT  = ((RESOLUTION_WIDTH / 2) - 1);
 const static uint8_t CAM_BLK_CAL_RIGHT = ((RESOLUTION_WIDTH / 2) + 1);
-const static uint8_t TERMINATE_WIDTH = static_cast<uint8_t>(RESOLUTION_WIDTH * 0.14f);
+const static uint8_t TERMINATE_WIDTH = static_cast<uint8_t>(RESOLUTION_WIDTH * 0.30f);
 
 static DigitalOut cam_cs(PIN_ACC_CS, 1);
 
 static uint8_t temp_mid_pos = RESOLUTION_WIDTH / 2;
 static uint8_t black_calibrate = 70;
-static volatile uint8_t centerLine[CAM_ROI_UPPER_LIMIT];
+static volatile uint8_t centerLine[CAM_ROI_UPPER_LIMIT * 2];
 static volatile uint8_t is_encounter_terminate = 0;
 //static Thread * m_imgProcessThread = NULL;
 //static Ticker m_tickerImgProc;
@@ -296,10 +296,11 @@
     black_calibrate = temp * 0.7f;
 }
 
-inline void get_img_row_info(const uint8_t display, const uint8_t rowI, uint8_t * left, uint8_t * right)
+inline void get_img_row_info(const uint8_t display, const uint8_t rowI, uint8_t * left, uint8_t * right, uint8_t* isBorderFound)
 {
     *left = 0;
     *right = RESOLUTION_WIDTH;
+    *isBorderFound = BOTH_NOT_FOUND;
     uint8_t isRightFound = 0;
     static uint16_t pixel = 0x0000;
     static uint8_t pGreen = 0x00;
@@ -314,6 +315,7 @@
         {
             if(j < temp_mid_pos)
             {
+                *isBorderFound = LEFT_FOUND;
                 *left = j;
 #ifdef CAM_DISP_DEBUG
                 ardu_utft_write_DATA(0xF8, 0x00);
@@ -338,6 +340,16 @@
         ardu_utft_write_DATA(static_cast<uint8_t>(pixel >> 8), static_cast<uint8_t>(pixel));
 #endif
     }
+    
+    if(*isBorderFound == LEFT_FOUND && isRightFound)
+    {
+        *isBorderFound = BOTH_FOUND;
+    }
+    else if(isRightFound)
+    {
+        *isBorderFound = RIGHT_FOUND;
+    }
+
 }
 
 volatile const uint8_t* ardu_cam_get_center_array()
@@ -389,6 +401,8 @@
         //cal_black_calibrate();
         uint8_t leftPos = 0;
         uint8_t rightPos = 0;
+        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)
@@ -402,7 +416,7 @@
 #if defined(CAM_DISP_IMG) or defined(CAM_DISP_DEBUG)
             ardu_utft_set_camimg_row(CAM_ROI_UPPER_LIMIT - i);
 #endif
-            get_img_row_info(0, i, &leftPos, &rightPos);
+            get_img_row_info(0, i, &leftPos, &rightPos, &isBorderFound);
             temp_mid_pos = (leftPos + rightPos) / 2;
             uint8_t dis_btw_left_right = rightPos - leftPos - 1;
             if(dis_btw_left_right < TERMINATE_WIDTH)
@@ -416,6 +430,7 @@
 #endif
 
             centerLine[CAM_ROI_UPPER_LIMIT - i - 1] = temp_mid_pos;
+            centerLine[(2 * CAM_ROI_UPPER_LIMIT) - i - 1] = isBorderFound;
         }