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:
Mon Mar 27 22:09:22 2017 +0000
Revision:
43:0d1886f4848a
Parent:
41:7b21c5e3599e
Child:
44:15de535c4005
display live camera view on screen

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hazheng 3:c8867972ffc7 1 #include "mbed.h"
hazheng 5:577b582e4fe9 2
Bobymicjohn 8:92f6baeea027 3 #include "Motor.h"
Bobymicjohn 11:676ea42afd56 4 #include "Servo.h"
Bobymicjohn 15:eb6a274b3dfb 5 #include "WheelEncoder.h"
Bobymicjohn 11:676ea42afd56 6 #include "Core.h"
Bobymicjohn 11:676ea42afd56 7 #include "SWUSBServer.h"
hazheng 29:f87d8790f57d 8
hazheng 29:f87d8790f57d 9 #include "ArduCAM.h"
hazheng 40:be98219930e4 10 #include "ArduUTFT.h"
Bobymicjohn 10:fedb5786a109 11
Bobymicjohn 10:fedb5786a109 12 #include "PinAssignment.h"
hazheng 29:f87d8790f57d 13 #include "GlobalVariable.h"
Bobymicjohn 8:92f6baeea027 14
hazheng 28:271fc8445e89 15 SPI g_spi_port(PIN_SPI_MOSI, PIN_SPI_MISO, PIN_SPI_SCK);
hazheng 29:f87d8790f57d 16 SW::Core g_core;
hazheng 5:577b582e4fe9 17
hazheng 3:c8867972ffc7 18 int main(void) {
hazheng 16:66c7a09e71ee 19
hazheng 16:66c7a09e71ee 20 Timer timer;
hazheng 16:66c7a09e71ee 21
hazheng 43:0d1886f4848a 22 g_spi_port.frequency(7000000);
hazheng 29:f87d8790f57d 23 //g_spi_port.format(8, 0);
hazheng 29:f87d8790f57d 24
hazheng 29:f87d8790f57d 25 //SW::Core core;
Bobymicjohn 10:fedb5786a109 26
hazheng 25:6f63053cee81 27 //Motor motor(core);
hazheng 25:6f63053cee81 28 //Servo servo(core);
hazheng 25:6f63053cee81 29 //WheelEncoder wheelEncoder(core);
hazheng 29:f87d8790f57d 30 //Camera cam(core);
hazheng 6:0682e1c90119 31
hazheng 16:66c7a09e71ee 32
hazheng 29:f87d8790f57d 33 bool isRegRead = false;
Bobymicjohn 14:88302da8bff0 34
hazheng 40:be98219930e4 35
hazheng 40:be98219930e4 36 ardu_utft_init();
hazheng 29:f87d8790f57d 37
hazheng 41:7b21c5e3599e 38
hazheng 41:7b21c5e3599e 39 ardu_cam_init();
hazheng 41:7b21c5e3599e 40
hazheng 18:bf6c5f8281eb 41 float tempCount = 0;
hazheng 18:bf6c5f8281eb 42 //timer.reset();
hazheng 16:66c7a09e71ee 43 timer.start();
hazheng 18:bf6c5f8281eb 44 float timeWas = timer.read();
hazheng 5:577b582e4fe9 45 while (1)
hazheng 5:577b582e4fe9 46 {
hazheng 18:bf6c5f8281eb 47
hazheng 18:bf6c5f8281eb 48 float deltaTime = timeWas;
hazheng 18:bf6c5f8281eb 49 timeWas = timer.read();
hazheng 18:bf6c5f8281eb 50 deltaTime = timeWas - deltaTime;
hazheng 18:bf6c5f8281eb 51
Bobymicjohn 11:676ea42afd56 52 //led = 0;
hazheng 29:f87d8790f57d 53 g_core.Update(deltaTime);
hazheng 25:6f63053cee81 54 //motor.Update(deltaTime);
hazheng 25:6f63053cee81 55 //servo.Update(deltaTime);
hazheng 25:6f63053cee81 56 //wheelEncoder.Update(deltaTime);
hazheng 29:f87d8790f57d 57 //cam.Update(deltaTime);
hazheng 16:66c7a09e71ee 58
hazheng 18:bf6c5f8281eb 59 tempCount += deltaTime;
hazheng 18:bf6c5f8281eb 60 if(tempCount > 1.0f)
hazheng 5:577b582e4fe9 61 {
hazheng 29:f87d8790f57d 62 //led = !led;
hazheng 18:bf6c5f8281eb 63 tempCount = 0.0f;
hazheng 3:c8867972ffc7 64 }
hazheng 3:c8867972ffc7 65
hazheng 41:7b21c5e3599e 66
hazheng 32:5badeff825dc 67 if(!isRegRead && g_core.GetUSBServer().GetStatus() == SER_STAT_RUNNING && timer.read() > 2.5f && ardu_cam_get_fifo_length() > 0)
hazheng 13:7dcb1642ef99 68 {
hazheng 32:5badeff825dc 69 //OV7725RegBuf * regBuf = new OV7725RegBuf(g_core);
hazheng 32:5badeff825dc 70 //regBuf->ReadRegisters();
hazheng 32:5badeff825dc 71 //delete regBuf;
hazheng 32:5badeff825dc 72 ardu_cam_print_debug();
hazheng 13:7dcb1642ef99 73 isRegRead = true;
hazheng 13:7dcb1642ef99 74 }
hazheng 41:7b21c5e3599e 75
hazheng 43:0d1886f4848a 76 ardu_cam_display_img_utft();
hazheng 29:f87d8790f57d 77
hazheng 43:0d1886f4848a 78 //wait(0.01);
hazheng 3:c8867972ffc7 79 }
hazheng 3:c8867972ffc7 80 }
hazheng 3:c8867972ffc7 81
hazheng 3:c8867972ffc7 82 /*
hazheng 3:c8867972ffc7 83 PwmOut servo(PTE20);
hazheng 3:c8867972ffc7 84
hazheng 3:c8867972ffc7 85 int main() {
hazheng 3:c8867972ffc7 86 servo.period(0.020); // servo requires a 20ms period
hazheng 3:c8867972ffc7 87
hazheng 3:c8867972ffc7 88 while (1) {
hazheng 3:c8867972ffc7 89 for(float offset=0.0; offset<0.001; offset+=0.0001) {
hazheng 3:c8867972ffc7 90 servo.pulsewidth(0.001 + offset); // servo position determined by a pulsewidth between 1-2ms
hazheng 3:c8867972ffc7 91 wait(0.25);
hazheng 3:c8867972ffc7 92 }
hazheng 3:c8867972ffc7 93 }
hazheng 3:c8867972ffc7 94
hazheng 3:c8867972ffc7 95 }
hazheng 13:7dcb1642ef99 96 */
hazheng 13:7dcb1642ef99 97
hazheng 13:7dcb1642ef99 98 /* //code for accelerometer sensor.
hazheng 13:7dcb1642ef99 99 const char regAddr = 0x0D;
hazheng 13:7dcb1642ef99 100 char readValue = 0;
hazheng 13:7dcb1642ef99 101 int result1 = m_sccbCtrl.write(0x1D<<1, &regAddr, 1, true);
hazheng 13:7dcb1642ef99 102 int result2 = m_sccbCtrl.read(0x1D<<1, &readValue, 1, false);
hazheng 13:7dcb1642ef99 103 char buf[20];
hazheng 13:7dcb1642ef99 104 sprintf(buf, "%#x-%#x-%d-%d", regAddr, readValue, result1, result2);
hazheng 13:7dcb1642ef99 105 m_core.GetUSBServer().PushUnreliableMsg('D', buf);
hazheng 3:c8867972ffc7 106 */