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:
- 33:e3fcc4d6bb9b
- Parent:
- 32:5badeff825dc
- Child:
- 34:f79db3bc2f86
--- a/Hardwares/ArduCAM.cpp Thu Mar 02 23:56:42 2017 +0000 +++ b/Hardwares/ArduCAM.cpp Fri Mar 03 18:26:44 2017 +0000 @@ -1,5 +1,8 @@ #include "ArduCAM.h" +#define RESOLUTION_WIDTH 160 +#define RESOLUTION_HEIGHT 120 + #include "GlobalVariable.h" #include "SWUSBServer.h" @@ -59,7 +62,7 @@ camReg->SCCBWrite(0xff, 0x01); camReg->SCCBWrite(0x12, 0x80); wait_ms(5); - camReg->WriteRegSet(OV2640Prog::QVGA); + camReg->WriteRegSet(OV2640Prog::QQVGA); wait_ms(100); camReg->SCCBWrite(0xff, 0x01); @@ -191,20 +194,20 @@ //g_core.GetUSBServer().PushReliableMsg('D', buf); VL = (VL & 0x00FF) | ((VH << 8) & 0xFF00); - uint8_t ch = ((VL & 0xF800) >> 11); - float pixel = (static_cast<float>(ch) * 0.33); + uint8_t ch = ((VL & 0xF800) >> 9);// << 2; + float pixel = (static_cast<float>(ch) * 0.21); //sprintf(buf, "c%#x", ch); //g_core.GetUSBServer().PushReliableMsg('D', buf); - ch = ((VL & 0x07E0) >> 5); - pixel += (static_cast<float>(ch) * 0.33); + ch = ((VL & 0x07E0) >> 3);// << 2; + pixel += (static_cast<float>(ch) * 0.72); //sprintf(buf, "c%#x", ch); //g_core.GetUSBServer().PushReliableMsg('D', buf); - ch = ((VL & 0x001F)); - pixel += (static_cast<float>(ch) * 0.33); + ch = (VL & 0x001F) << 2; + pixel += (static_cast<float>(ch) * 0.07); //sprintf(buf, "c%#x", ch); //g_core.GetUSBServer().PushReliableMsg('D', buf); @@ -221,24 +224,27 @@ sprintf(buf, "Cam L %#x", len); g_core.GetUSBServer().PushReliableMsg('D', buf); + //if(len < (RESOLUTION_HEIGHT * RESOLUTION_WIDTH * 2)) + // return; + + //Begin output the picture std::string lineBuf; - lineBuf.resize(321); + lineBuf.resize(RESOLUTION_WIDTH + 1); - for (uint8_t i = 0; i < 240; ++i) + ardu_cam_get_pixel(); //Get the first dummy pixel + + for (uint8_t i = 0; i < RESOLUTION_HEIGHT; ++i) { lineBuf[0] = i; - sprintf(buf, "Line %d", i); - g_core.GetUSBServer().PushReliableMsg('D', buf); - for (int j = 0; j < 320; ++j) + for (int j = 0; j < RESOLUTION_WIDTH; ++j) { - uint8_t p = ardu_cam_get_pixel(); - //if(j < 159) - lineBuf[j + 1] = p; + //uint8_t p = ardu_cam_get_pixel(); + lineBuf[j + 1] = ardu_cam_get_pixel(); } g_core.GetUSBServer().PushReliableMsg('P', lineBuf); - wait(0.5); + wait(0.4); } } \ No newline at end of file