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

Committer:
hazheng
Date:
Thu Apr 20 16:23:19 2017 +0000
Revision:
99:c6665262fd3d
Parent:
97:0ed9ede9a995
Parent:
98:fc92bb37ee17
Child:
100:ffbeefc9e218
Merge

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hazheng 93:8e1bd3602d53 1 /**
hazheng 93:8e1bd3602d53 2 * @file ArduCAM.h
hazheng 93:8e1bd3602d53 3 * @brief The header file for all functions that controls the ArduCam Mini camera.
hazheng 93:8e1bd3602d53 4 * @author Jordan Brack <jabrack@mix.wvu.edu>, Haofan Zheng <hazheng@mix.wvu.edu>
hazheng 93:8e1bd3602d53 5 *
hazheng 93:8e1bd3602d53 6 */
hazheng 28:271fc8445e89 7 #pragma once
hazheng 28:271fc8445e89 8 #ifndef ARDU_CAM_H
hazheng 28:271fc8445e89 9 #define ARDU_CAM_H
hazheng 28:271fc8445e89 10
hazheng 29:f87d8790f57d 11 #include <mbed.h>
hazheng 28:271fc8445e89 12 #include "PinAssignment.h"
hazheng 28:271fc8445e89 13
hazheng 93:8e1bd3602d53 14 #define RESOLUTION_WIDTH 80 /*!< @brief The resolution width we are using. */
hazheng 93:8e1bd3602d53 15 #define RESOLUTION_HEIGHT 60 /*!< @brief The resolution height we are using. */
hazheng 41:7b21c5e3599e 16 //#define MANUAL_REDUCE_RESULOTION_BY2
hazheng 93:8e1bd3602d53 17 #define CAM_ROI_UPPER_LIMIT 6 /*!< @brief The number of lines we actually using for the image processing. */
hazheng 65:295c222fdf88 18
hazheng 65:295c222fdf88 19
hazheng 93:8e1bd3602d53 20 #define BOTH_NOT_FOUND 0 /*!< @brief ENUM for whether the border is found. Both sides of the border is not found. */
hazheng 93:8e1bd3602d53 21 #define LEFT_FOUND 1 /*!< @brief ENUM for whether the border is found. Left side of the border is found. */
hazheng 93:8e1bd3602d53 22 #define RIGHT_FOUND 2 /*!< @brief ENUM for whether the border is found. Right side of the border is found. */
hazheng 93:8e1bd3602d53 23 #define BOTH_FOUND 3 /*!< @brief ENUM for whether the border is found. Both sides of the border is found. */
hazheng 38:0fb273b28cee 24
hazheng 36:7e747e19f660 25 //=====Must pick one and only one here!=====
hazheng 93:8e1bd3602d53 26 //#define ARDUCAM_SHIELD_OV2640 /*!< @brief Use ArduCam Shield V2 with OV2640 camera module. */
hazheng 93:8e1bd3602d53 27 //#define ARDUCAM_SHIELD_OV7725 /*!< @brief Use ArduCam Shield V2 with OV7725 camera module. */
hazheng 93:8e1bd3602d53 28 //#define ARDUCAM_SHIELD_OV7670 /*!< @brief Use ArduCam Shield V2 with OV7670 camera module. */
hazheng 93:8e1bd3602d53 29 #define ARDUCAM_MINI_OV2640 /*!< @brief Use ArduCam Mini with OV2640 camera module. */
hazheng 36:7e747e19f660 30 //==========================================
hazheng 36:7e747e19f660 31
hazheng 37:7074a6118d03 32
hazheng 37:7074a6118d03 33 #if defined(ARDUCAM_SHIELD_OV2640) || defined(ARDUCAM_SHIELD_OV7725) || defined(ARDUCAM_SHIELD_OV7670)
hazheng 93:8e1bd3602d53 34 #define ARDUCAM_SHIELD /*!< @brief Use ArduCam Shield V2. (Automatically defined, DO NOT touch.) */
hazheng 36:7e747e19f660 35 #elif defined(ARDUCAM_MINI_OV2640)
hazheng 93:8e1bd3602d53 36 #define ARDUCAM_MINI /*!< @brief Use ArduCam Mini. (Automatically defined, DO NOT touch.) */
hazheng 36:7e747e19f660 37 #else
hazheng 36:7e747e19f660 38 #error Must pick one and only one ArduCam type!
hazheng 36:7e747e19f660 39 #endif
hazheng 36:7e747e19f660 40
hazheng 36:7e747e19f660 41 #if defined(ARDUCAM_SHIELD_OV2640) || defined(ARDUCAM_MINI_OV2640)
hazheng 93:8e1bd3602d53 42 #define ARDUCAM_OV2640 /*!< @brief Use OV2640 camera module. (Automatically defined, DO NOT touch.) */
hazheng 36:7e747e19f660 43 #elif defined(ARDUCAM_SHIELD_OV7725)
hazheng 93:8e1bd3602d53 44 #define ARDUCAM_OV7725 /*!< @brief Use OV7725 camera module. (Automatically defined, DO NOT touch.) */
hazheng 37:7074a6118d03 45 #elif defined(ARDUCAM_SHIELD_OV7670)
hazheng 93:8e1bd3602d53 46 #define ARDUCAM_OV7670 /*!< @brief Use OV7670 camera module. (Automatically defined, DO NOT touch.) */
hazheng 36:7e747e19f660 47 #else
hazheng 36:7e747e19f660 48 #error Must pick one and only one ArduCam type!
hazheng 36:7e747e19f660 49 #endif
hazheng 36:7e747e19f660 50
hazheng 36:7e747e19f660 51 #if defined(ARDUCAM_OV2640)
hazheng 36:7e747e19f660 52 #include "OV2640RegProg.h"
hazheng 36:7e747e19f660 53 #elif defined(ARDUCAM_OV7725)
hazheng 36:7e747e19f660 54 #include "OV7725RegProg.h"
hazheng 37:7074a6118d03 55 #elif defined(ARDUCAM_OV7670)
hazheng 37:7074a6118d03 56 #include "OV7670RegProg.h"
hazheng 36:7e747e19f660 57 #endif
hazheng 36:7e747e19f660 58
Bobymicjohn 97:0ed9ede9a995 59 #define ARDUCHIP_VER 0x40 /*!< @brief The address for the ArduCam version register. */
hazheng 36:7e747e19f660 60 #if defined(ARDUCAM_SHIELD)
hazheng 93:8e1bd3602d53 61 #define ARDUCHIP_VER_NUM 0x61 /*!< @brief ArduCam Version number for ArduCam Shield V2. */
hazheng 36:7e747e19f660 62 #elif defined(ARDUCAM_MINI)
hazheng 93:8e1bd3602d53 63 #define ARDUCHIP_VER_NUM 0x55 /*!< @brief ArduCam Version number for ArduCam Mini. */
hazheng 36:7e747e19f660 64 #endif
hazheng 36:7e747e19f660 65
hazheng 93:8e1bd3602d53 66 #define ARDUCHIP_TEST1 0x00 /*!< @brief The address for the ArduCam test register. */
hazheng 93:8e1bd3602d53 67 #define ARDUCHIP_TEST_MSG 0x72 /*!< @brief The message used to write/read/verify with the test register. */
hazheng 29:f87d8790f57d 68
hazheng 93:8e1bd3602d53 69 #define ARDUCHIP_CAP_CTRL 0x01 /*!< @brief The register address that used to set how many picture need to take. */
hazheng 29:f87d8790f57d 70
hazheng 40:be98219930e4 71 #if defined(ARDUCAM_SHIELD)
hazheng 93:8e1bd3602d53 72 #define ARDUCHIP_MODE 0x02 /*!< @brief The address for the ArduCam bus mode setting register. */
hazheng 93:8e1bd3602d53 73 #define MCU2LCD_MODE 0x00 /*!< @brief The byte used to set the ArduCam bus to MCU to LCD mode. */
hazheng 93:8e1bd3602d53 74 #define CAM2LCD_MODE 0x01 /*!< @brief The byte used to set the ArduCam bus to CAM to LCD mode. */
hazheng 40:be98219930e4 75 #endif
hazheng 29:f87d8790f57d 76
hazheng 93:8e1bd3602d53 77 #define ARDUCHIP_FIFO 0x04 /*!< @brief The address for the ArduCam FIFO and I2C setting register. */
hazheng 93:8e1bd3602d53 78 #define FIFO_CLEAR_MASK 0x01 /*!< @brief The mask used to clear the FIFO. */
hazheng 93:8e1bd3602d53 79 #define FIFO_START_MASK 0x02 /*!< @brief The mask used to start the FIFO write. */
hazheng 93:8e1bd3602d53 80 #define FIFO_RDPTR_RST_MASK 0x10 /*!< @brief The mask used to reset the FIFO read pointer. */
hazheng 93:8e1bd3602d53 81 #define FIFO_WRPTR_RST_MASK 0x20 /*!< @brief The mask used to reset the FIFO write pointer. */
hazheng 29:f87d8790f57d 82
hazheng 93:8e1bd3602d53 83 #define ARDUCHIP_TRIG 0x41 /*!< @brief The address for the ArduCam trigger status register. */
hazheng 93:8e1bd3602d53 84 #define VSYNC_MASK 0x01 /*!< @brief The mask used to check the Vsync status. */
hazheng 93:8e1bd3602d53 85 #define SHUTTER_MASK 0x02 /*!< @brief The mask used to check the shutter status. */
hazheng 93:8e1bd3602d53 86 #define CAP_DONE_MASK 0x08 /*!< @brief The mask used to check if the capture is done. */
hazheng 44:15de535c4005 87
hazheng 93:8e1bd3602d53 88 #define FIFO_SIZE1 0x42 /*!< @brief Camera write FIFO size[7:0] for burst to read. */
hazheng 93:8e1bd3602d53 89 #define FIFO_SIZE2 0x43 /*!< @brief Camera write FIFO size[15:8]. */
hazheng 93:8e1bd3602d53 90 #define FIFO_SIZE3 0x44 /*!< @brief Camera write FIFO size[18:16]. */
hazheng 32:5badeff825dc 91
hazheng 93:8e1bd3602d53 92 #define BURST_FIFO_READ 0x3C /*!< @brief Burst FIFO read operation. */
hazheng 93:8e1bd3602d53 93 #define SINGLE_FIFO_READ 0x3D /*!< @brief Single FIFO read operation. */
hazheng 29:f87d8790f57d 94
hazheng 46:a5eb9bd3bb55 95 #ifdef __cplusplus
hazheng 46:a5eb9bd3bb55 96 extern "C" {
hazheng 46:a5eb9bd3bb55 97 #endif
hazheng 46:a5eb9bd3bb55 98
hazheng 93:8e1bd3602d53 99 /**
hazheng 93:8e1bd3602d53 100 * @brief Init the camera. There is only one camera in the system, thus, this function is required to be called only once during the system initialization.
hazheng 93:8e1bd3602d53 101 */
hazheng 28:271fc8445e89 102 bool ardu_cam_init();
hazheng 28:271fc8445e89 103
hazheng 93:8e1bd3602d53 104 /**
hazheng 93:8e1bd3602d53 105 * @brief Start the capture for one picture. The capture will automatically stop after a picture is captured.
hazheng 93:8e1bd3602d53 106 */
hazheng 29:f87d8790f57d 107 void ardu_cam_start_capture();
hazheng 29:f87d8790f57d 108
hazheng 93:8e1bd3602d53 109 /**
hazheng 93:8e1bd3602d53 110 * @brief Get the current FIFO length.
hazheng 93:8e1bd3602d53 111 * @return The length of the current FIFO.
hazheng 93:8e1bd3602d53 112 */
hazheng 32:5badeff825dc 113 uint32_t ardu_cam_get_fifo_length();
hazheng 32:5badeff825dc 114
hazheng 93:8e1bd3602d53 115 /**
hazheng 93:8e1bd3602d53 116 * @brief Get the array that describe the center line that detected by the image processing.
hazheng 93:8e1bd3602d53 117 * @return A volatile pointer points to the array.
hazheng 93:8e1bd3602d53 118 */
hazheng 44:15de535c4005 119 volatile const uint8_t* ardu_cam_get_center_array();
hazheng 44:15de535c4005 120
hazheng 93:8e1bd3602d53 121 /**
hazheng 93:8e1bd3602d53 122 * @brief Check if the capture is finished.
hazheng 93:8e1bd3602d53 123 * @return True if the capture is finished, otherwise, return false.
hazheng 93:8e1bd3602d53 124 */
hazheng 44:15de535c4005 125 uint8_t ardu_cam_is_capture_finished();
hazheng 43:0d1886f4848a 126
hazheng 93:8e1bd3602d53 127 /**
hazheng 93:8e1bd3602d53 128 * @brief Display the image on the UTFT screen.
hazheng 93:8e1bd3602d53 129 */
hazheng 46:a5eb9bd3bb55 130 void ardu_cam_display_img_utft();
hazheng 46:a5eb9bd3bb55 131
hazheng 93:8e1bd3602d53 132 /**
hazheng 93:8e1bd3602d53 133 * @brief Get a new picture, and run the image processing.
hazheng 93:8e1bd3602d53 134 */
hazheng 57:0d8a155d511d 135 void image_processing();
hazheng 57:0d8a155d511d 136
hazheng 93:8e1bd3602d53 137 /**
hazheng 93:8e1bd3602d53 138 * @brief Get wether the terminate line is detected.
hazheng 93:8e1bd3602d53 139 * @return 0 for no, 1 for yes.
hazheng 93:8e1bd3602d53 140 */
hazheng 64:43ab429a37e0 141 uint8_t ardu_cam_get_is_encounter_terminate();
hazheng 64:43ab429a37e0 142
hazheng 93:8e1bd3602d53 143 /**
hazheng 93:8e1bd3602d53 144 * @brief Get wether the borders are found.
hazheng 93:8e1bd3602d53 145 * @return ENUM for whether the border is found. Please refer to the definition above.
hazheng 93:8e1bd3602d53 146 */
hazheng 98:fc92bb37ee17 147 //uint8_t ardu_cam_get_is_border_found();
hazheng 79:bdbac82c979b 148
Bobymicjohn 97:0ed9ede9a995 149 /**
Bobymicjohn 97:0ed9ede9a995 150 * @brief Gets the version number from ArduCam.
Bobymicjohn 97:0ed9ede9a995 151 * @return The version number.
Bobymicjohn 97:0ed9ede9a995 152 */
Bobymicjohn 97:0ed9ede9a995 153 uint8_t ardu_cam_get_ver_num();
Bobymicjohn 97:0ed9ede9a995 154
hazheng 98:fc92bb37ee17 155 uint8_t ardu_cam_get_is_intersection_detected();
hazheng 99:c6665262fd3d 156
hazheng 46:a5eb9bd3bb55 157 #ifdef __cplusplus
hazheng 46:a5eb9bd3bb55 158 }
hazheng 46:a5eb9bd3bb55 159 #endif
hazheng 46:a5eb9bd3bb55 160
hazheng 34:f79db3bc2f86 161
hazheng 28:271fc8445e89 162 #endif //ARDU_CAM_H