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:
Wed Apr 19 19:43:15 2017 +0000
Revision:
96:ec89c4d1383d
Parent:
93:8e1bd3602d53
Child:
97:0ed9ede9a995
Child:
98:fc92bb37ee17
Removed commented code.

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
hazheng 36:7e747e19f660 59 #if defined(ARDUCAM_SHIELD)
hazheng 93:8e1bd3602d53 60 #define ARDUCHIP_VER_NUM 0x61 /*!< @brief ArduCam Version number for ArduCam Shield V2. */
hazheng 36:7e747e19f660 61 #elif defined(ARDUCAM_MINI)
hazheng 93:8e1bd3602d53 62 #define ARDUCHIP_VER_NUM 0x55 /*!< @brief ArduCam Version number for ArduCam Mini. */
hazheng 36:7e747e19f660 63 #endif
hazheng 36:7e747e19f660 64
hazheng 93:8e1bd3602d53 65 #define ARDUCHIP_TEST1 0x00 /*!< @brief The address for the ArduCam test register. */
hazheng 93:8e1bd3602d53 66 #define ARDUCHIP_TEST_MSG 0x72 /*!< @brief The message used to write/read/verify with the test register. */
hazheng 29:f87d8790f57d 67
hazheng 93:8e1bd3602d53 68 #define ARDUCHIP_CAP_CTRL 0x01 /*!< @brief The register address that used to set how many picture need to take. */
hazheng 29:f87d8790f57d 69
hazheng 40:be98219930e4 70 #if defined(ARDUCAM_SHIELD)
hazheng 93:8e1bd3602d53 71 #define ARDUCHIP_MODE 0x02 /*!< @brief The address for the ArduCam bus mode setting register. */
hazheng 93:8e1bd3602d53 72 #define MCU2LCD_MODE 0x00 /*!< @brief The byte used to set the ArduCam bus to MCU to LCD mode. */
hazheng 93:8e1bd3602d53 73 #define CAM2LCD_MODE 0x01 /*!< @brief The byte used to set the ArduCam bus to CAM to LCD mode. */
hazheng 40:be98219930e4 74 #endif
hazheng 29:f87d8790f57d 75
hazheng 93:8e1bd3602d53 76 #define ARDUCHIP_FIFO 0x04 /*!< @brief The address for the ArduCam FIFO and I2C setting register. */
hazheng 93:8e1bd3602d53 77 #define FIFO_CLEAR_MASK 0x01 /*!< @brief The mask used to clear the FIFO. */
hazheng 93:8e1bd3602d53 78 #define FIFO_START_MASK 0x02 /*!< @brief The mask used to start the FIFO write. */
hazheng 93:8e1bd3602d53 79 #define FIFO_RDPTR_RST_MASK 0x10 /*!< @brief The mask used to reset the FIFO read pointer. */
hazheng 93:8e1bd3602d53 80 #define FIFO_WRPTR_RST_MASK 0x20 /*!< @brief The mask used to reset the FIFO write pointer. */
hazheng 29:f87d8790f57d 81
hazheng 93:8e1bd3602d53 82 #define ARDUCHIP_TRIG 0x41 /*!< @brief The address for the ArduCam trigger status register. */
hazheng 93:8e1bd3602d53 83 #define VSYNC_MASK 0x01 /*!< @brief The mask used to check the Vsync status. */
hazheng 93:8e1bd3602d53 84 #define SHUTTER_MASK 0x02 /*!< @brief The mask used to check the shutter status. */
hazheng 93:8e1bd3602d53 85 #define CAP_DONE_MASK 0x08 /*!< @brief The mask used to check if the capture is done. */
hazheng 44:15de535c4005 86
hazheng 93:8e1bd3602d53 87 #define FIFO_SIZE1 0x42 /*!< @brief Camera write FIFO size[7:0] for burst to read. */
hazheng 93:8e1bd3602d53 88 #define FIFO_SIZE2 0x43 /*!< @brief Camera write FIFO size[15:8]. */
hazheng 93:8e1bd3602d53 89 #define FIFO_SIZE3 0x44 /*!< @brief Camera write FIFO size[18:16]. */
hazheng 32:5badeff825dc 90
hazheng 93:8e1bd3602d53 91 #define BURST_FIFO_READ 0x3C /*!< @brief Burst FIFO read operation. */
hazheng 93:8e1bd3602d53 92 #define SINGLE_FIFO_READ 0x3D /*!< @brief Single FIFO read operation. */
hazheng 29:f87d8790f57d 93
hazheng 46:a5eb9bd3bb55 94 #ifdef __cplusplus
hazheng 46:a5eb9bd3bb55 95 extern "C" {
hazheng 46:a5eb9bd3bb55 96 #endif
hazheng 46:a5eb9bd3bb55 97
hazheng 93:8e1bd3602d53 98 /**
hazheng 93:8e1bd3602d53 99 * @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 100 */
hazheng 28:271fc8445e89 101 bool ardu_cam_init();
hazheng 28:271fc8445e89 102
hazheng 93:8e1bd3602d53 103 /**
hazheng 93:8e1bd3602d53 104 * @brief Start the capture for one picture. The capture will automatically stop after a picture is captured.
hazheng 93:8e1bd3602d53 105 */
hazheng 29:f87d8790f57d 106 void ardu_cam_start_capture();
hazheng 29:f87d8790f57d 107
hazheng 93:8e1bd3602d53 108 /**
hazheng 93:8e1bd3602d53 109 * @brief Get the current FIFO length.
hazheng 93:8e1bd3602d53 110 * @return The length of the current FIFO.
hazheng 93:8e1bd3602d53 111 */
hazheng 32:5badeff825dc 112 uint32_t ardu_cam_get_fifo_length();
hazheng 32:5badeff825dc 113
hazheng 93:8e1bd3602d53 114 /**
hazheng 93:8e1bd3602d53 115 * @brief Get the array that describe the center line that detected by the image processing.
hazheng 93:8e1bd3602d53 116 * @return A volatile pointer points to the array.
hazheng 93:8e1bd3602d53 117 */
hazheng 44:15de535c4005 118 volatile const uint8_t* ardu_cam_get_center_array();
hazheng 44:15de535c4005 119
hazheng 93:8e1bd3602d53 120 /**
hazheng 93:8e1bd3602d53 121 * @brief Check if the capture is finished.
hazheng 93:8e1bd3602d53 122 * @return True if the capture is finished, otherwise, return false.
hazheng 93:8e1bd3602d53 123 */
hazheng 44:15de535c4005 124 uint8_t ardu_cam_is_capture_finished();
hazheng 43:0d1886f4848a 125
hazheng 93:8e1bd3602d53 126 /**
hazheng 93:8e1bd3602d53 127 * @brief Display the image on the UTFT screen.
hazheng 93:8e1bd3602d53 128 */
hazheng 46:a5eb9bd3bb55 129 void ardu_cam_display_img_utft();
hazheng 46:a5eb9bd3bb55 130
hazheng 93:8e1bd3602d53 131 /**
hazheng 93:8e1bd3602d53 132 * @brief Get a new picture, and run the image processing.
hazheng 93:8e1bd3602d53 133 */
hazheng 57:0d8a155d511d 134 void image_processing();
hazheng 57:0d8a155d511d 135
hazheng 93:8e1bd3602d53 136 /**
hazheng 93:8e1bd3602d53 137 * @brief Get wether the terminate line is detected.
hazheng 93:8e1bd3602d53 138 * @return 0 for no, 1 for yes.
hazheng 93:8e1bd3602d53 139 */
hazheng 64:43ab429a37e0 140 uint8_t ardu_cam_get_is_encounter_terminate();
hazheng 64:43ab429a37e0 141
hazheng 93:8e1bd3602d53 142 /**
hazheng 93:8e1bd3602d53 143 * @brief Get wether the borders are found.
hazheng 93:8e1bd3602d53 144 * @return ENUM for whether the border is found. Please refer to the definition above.
hazheng 93:8e1bd3602d53 145 */
hazheng 79:bdbac82c979b 146 uint8_t ardu_cam_get_is_border_found();
hazheng 79:bdbac82c979b 147
hazheng 46:a5eb9bd3bb55 148 #ifdef __cplusplus
hazheng 46:a5eb9bd3bb55 149 }
hazheng 46:a5eb9bd3bb55 150 #endif
hazheng 46:a5eb9bd3bb55 151
hazheng 34:f79db3bc2f86 152
hazheng 28:271fc8445e89 153 #endif //ARDU_CAM_H