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:
- 99:c6665262fd3d
- Parent:
- 97:0ed9ede9a995
- Parent:
- 98:fc92bb37ee17
- Child:
- 100:ffbeefc9e218
diff -r 0ed9ede9a995 -r c6665262fd3d Hardwares/ArduCAM.cpp --- a/Hardwares/ArduCAM.cpp Wed Apr 19 21:17:40 2017 +0000 +++ b/Hardwares/ArduCAM.cpp Thu Apr 20 16:23:19 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(); @@ -234,7 +235,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; @@ -270,6 +271,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) { @@ -291,51 +299,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; + } } } @@ -439,17 +420,23 @@ { return is_encounter_terminate; } - +/* uint8_t ardu_cam_get_is_border_found() { return is_border_find; } +*/ uint8_t ardu_cam_get_ver_num() { return ardu_cam_spi_read_8(ARDUCHIP_VER); } +uint8_t ardu_cam_get_is_intersection_detected() +{ + return is_intersection_detected; +} + #ifdef __cplusplus } #endif