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
Diff: Hardwares/ArduCAM.cpp
- Revision:
- 98:fc92bb37ee17
- Parent:
- 96:ec89c4d1383d
- Child:
- 99:c6665262fd3d
--- a/Hardwares/ArduCAM.cpp Wed Apr 19 19:43:15 2017 +0000 +++ b/Hardwares/ArduCAM.cpp Thu Apr 20 16:18:45 2017 +0000 @@ -9,7 +9,7 @@ #include "ArduUTFT.h" -#include <string> +#include <math.h> #define CAM_BLK_CAL_ACTIVE @@ -33,7 +33,8 @@ static uint8_t black_calibrate = 70; 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 volatile uint8_t is_border_find = BOTH_NOT_FOUND; +static volatile uint8_t is_intersection_detected = 0; void cal_black_calibrate(); @@ -245,7 +246,7 @@ while (!(ardu_cam_spi_read_8(ARDUCHIP_TRIG) & CAP_DONE_MASK)); temp_mid_pos = RESOLUTION_WIDTH / 2; - is_border_find = BOTH_NOT_FOUND; + //is_border_find = BOTH_NOT_FOUND; #ifdef CAM_BLK_CAL_ACTIVE static float calTemp = 0.0f; calTemp = 0.0f; @@ -281,6 +282,13 @@ uint8_t leftPos = 0; uint8_t rightPos = 0; uint8_t isBorderFound = BOTH_NOT_FOUND; + + is_intersection_detected = 0; + uint8_t leftNearCenter1 = 0; + uint8_t leftNearCenter2 = 0; + uint8_t rightNearCenter1 = 0; + uint8_t rightNearCenter2 = 0; + is_encounter_terminate = 0; for (uint8_t i = 0; i < CAM_ROI_UPPER_LIMIT; ++i) { @@ -302,51 +310,24 @@ centerLine[CAM_ROI_UPPER_LIMIT - i - 1] = temp_mid_pos; centerLine[(2 * CAM_ROI_UPPER_LIMIT) - i - 1] = isBorderFound; - switch(is_border_find) + + if(leftPos > leftNearCenter1) + { + leftNearCenter2 = leftNearCenter1; + leftNearCenter1 = CAM_ROI_UPPER_LIMIT - i - 1; + } + if(rightPos < rightNearCenter1) { - case BOTH_NOT_FOUND: - switch(isBorderFound) - { - case LEFT_FOUND: - is_border_find = LEFT_FOUND; - break; - case RIGHT_FOUND: - is_border_find = RIGHT_FOUND; - break; - case BOTH_FOUND: - is_border_find = BOTH_FOUND; - break; - default: - break; - } - break; - case LEFT_FOUND: - switch(isBorderFound) - { - case RIGHT_FOUND: - case BOTH_FOUND: - is_border_find = BOTH_FOUND; - break; - default: - break; - } - break; - case RIGHT_FOUND: - switch(isBorderFound) - { - case LEFT_FOUND: - case BOTH_FOUND: - is_border_find = BOTH_FOUND; - break; - default: - break; - } - break; - case BOTH_FOUND: - default: - break; + rightNearCenter2 = rightNearCenter1; + rightNearCenter1 = CAM_ROI_UPPER_LIMIT - i - 1; } } + + if( ((1 < rightNearCenter1 && rightNearCenter1 < (CAM_ROI_UPPER_LIMIT - 2)) && (abs(rightNearCenter1 - rightNearCenter2) == 1)) || + ((1 < leftNearCenter1 && leftNearCenter1 < (CAM_ROI_UPPER_LIMIT - 2)) && (abs(leftNearCenter1 - leftNearCenter1) == 1)) ) + { + is_intersection_detected = 1; + } } } @@ -377,12 +358,17 @@ { return is_encounter_terminate; } - +/* uint8_t ardu_cam_get_is_border_found() { return is_border_find; } +*/ +uint8_t ardu_cam_get_is_intersection_detected() +{ + return is_intersection_detected; +} #ifdef __cplusplus } #endif