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 Feb 01 00:35:48 2017 +0000
Revision:
3:c8867972ffc7
Added code for camera.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hazheng 3:c8867972ffc7 1 #include "Camera.h"
hazheng 3:c8867972ffc7 2
hazheng 3:c8867972ffc7 3 DigitalOut testLED(LED_BLUE, 1);
hazheng 3:c8867972ffc7 4
hazheng 3:c8867972ffc7 5 void Camera::OnPixelClock()
hazheng 3:c8867972ffc7 6 {
hazheng 3:c8867972ffc7 7 m_pics[m_currentIndex][(m_currentRow * CAM_MAX_COL) + m_currentCol++] = 0;//m_dIn[0].read();
hazheng 3:c8867972ffc7 8 m_pics[m_currentIndex][(m_currentRow * CAM_MAX_COL) + m_currentCol++] = 0;//m_dIn[1].read();
hazheng 3:c8867972ffc7 9 m_pics[m_currentIndex][(m_currentRow * CAM_MAX_COL) + m_currentCol++] = 0;//m_dIn[2].read();
hazheng 3:c8867972ffc7 10 m_pics[m_currentIndex][(m_currentRow * CAM_MAX_COL) + m_currentCol++] = 0;//m_dIn[3].read();
hazheng 3:c8867972ffc7 11 m_pics[m_currentIndex][(m_currentRow * CAM_MAX_COL) + m_currentCol++] = 0;//m_dIn[4].read();
hazheng 3:c8867972ffc7 12 m_pics[m_currentIndex][(m_currentRow * CAM_MAX_COL) + m_currentCol++] = 0;//m_dIn[5].read();
hazheng 3:c8867972ffc7 13 m_pics[m_currentIndex][(m_currentRow * CAM_MAX_COL) + m_currentCol++] = 0;//m_dIn[6].read();
hazheng 3:c8867972ffc7 14 m_pics[m_currentIndex][(m_currentRow * CAM_MAX_COL) + m_currentCol++] = 0;//m_dIn[7].read();
hazheng 3:c8867972ffc7 15
hazheng 3:c8867972ffc7 16 }
hazheng 3:c8867972ffc7 17
hazheng 3:c8867972ffc7 18 void Camera::OnHorizontalClock()
hazheng 3:c8867972ffc7 19 {
hazheng 3:c8867972ffc7 20 m_currentRow++;
hazheng 3:c8867972ffc7 21 m_currentCol = 0;
hazheng 3:c8867972ffc7 22 }
hazheng 3:c8867972ffc7 23
hazheng 3:c8867972ffc7 24 void Camera::OnFrameClock()
hazheng 3:c8867972ffc7 25 {
hazheng 3:c8867972ffc7 26 m_currentIndex = m_currentIndex == 0 ? 1 : 0;
hazheng 3:c8867972ffc7 27 m_currentRow = 0;
hazheng 3:c8867972ffc7 28 m_currentCol = 0;
hazheng 3:c8867972ffc7 29 m_hasPic = true;
hazheng 3:c8867972ffc7 30
hazheng 3:c8867972ffc7 31 testLED = testLED.read() == 1 ? 0 : 1;
hazheng 3:c8867972ffc7 32 }
hazheng 3:c8867972ffc7 33
hazheng 3:c8867972ffc7 34 Camera::Camera() :
hazheng 3:c8867972ffc7 35 m_pClock(InterruptIn(PTD7)),
hazheng 3:c8867972ffc7 36 m_href(InterruptIn(PTD6)),
hazheng 3:c8867972ffc7 37 m_vsnyc(InterruptIn(PTA17)),
hazheng 3:c8867972ffc7 38 m_currentIndex(0),
hazheng 3:c8867972ffc7 39 m_currentRow(0),
hazheng 3:c8867972ffc7 40 m_currentCol(0),
hazheng 3:c8867972ffc7 41 m_hasPic(false)
hazheng 3:c8867972ffc7 42 {
hazheng 3:c8867972ffc7 43 m_dIn.push_back(DigitalIn(PTE5));
hazheng 3:c8867972ffc7 44 m_dIn.push_back(DigitalIn(PTE4));
hazheng 3:c8867972ffc7 45 m_dIn.push_back(DigitalIn(PTE3));
hazheng 3:c8867972ffc7 46 m_dIn.push_back(DigitalIn(PTE2));
hazheng 3:c8867972ffc7 47 m_dIn.push_back(DigitalIn(PTB11));
hazheng 3:c8867972ffc7 48 m_dIn.push_back(DigitalIn(PTB10));
hazheng 3:c8867972ffc7 49 m_dIn.push_back(DigitalIn(PTB9));
hazheng 3:c8867972ffc7 50 m_dIn.push_back(DigitalIn(PTB8));
hazheng 3:c8867972ffc7 51
hazheng 3:c8867972ffc7 52 //m_pClock.fall(callback(this, &Camera::OnPixelClock));
hazheng 3:c8867972ffc7 53 m_href.rise(callback(this, &Camera::OnHorizontalClock));
hazheng 3:c8867972ffc7 54 m_vsnyc.rise(callback(this, &Camera::OnFrameClock));
hazheng 3:c8867972ffc7 55
hazheng 3:c8867972ffc7 56 }
hazheng 3:c8867972ffc7 57
hazheng 3:c8867972ffc7 58 Camera::~Camera()
hazheng 3:c8867972ffc7 59 {
hazheng 3:c8867972ffc7 60
hazheng 3:c8867972ffc7 61 }
hazheng 3:c8867972ffc7 62
hazheng 3:c8867972ffc7 63 bool Camera::HasPicture() const
hazheng 3:c8867972ffc7 64 {
hazheng 3:c8867972ffc7 65 return m_hasPic;
hazheng 3:c8867972ffc7 66 }
hazheng 3:c8867972ffc7 67
hazheng 3:c8867972ffc7 68 const unsigned char * Camera::GetPicture() const
hazheng 3:c8867972ffc7 69 {
hazheng 3:c8867972ffc7 70 return m_pics[m_currentIndex == 0 ? 1 : 0];
hazheng 3:c8867972ffc7 71 }