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
main.cpp@40:be98219930e4, 2017-03-22 (annotated)
- Committer:
- hazheng
- Date:
- Wed Mar 22 23:43:24 2017 +0000
- Revision:
- 40:be98219930e4
- Parent:
- 37:7074a6118d03
- Child:
- 41:7b21c5e3599e
Added code for UTFT screen. Nothing displayed on screen. Maybe screen is broken?
Who changed what in which revision?
User | Revision | Line number | New 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 | 37:7074a6118d03 | 22 | //g_spi_port.frequency(500000); |
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 | //ardu_cam_init(); |
hazheng | 40:be98219930e4 | 36 | |
hazheng | 40:be98219930e4 | 37 | ardu_utft_init(); |
hazheng | 29:f87d8790f57d | 38 | |
hazheng | 18:bf6c5f8281eb | 39 | float tempCount = 0; |
hazheng | 18:bf6c5f8281eb | 40 | //timer.reset(); |
hazheng | 16:66c7a09e71ee | 41 | timer.start(); |
hazheng | 18:bf6c5f8281eb | 42 | float timeWas = timer.read(); |
hazheng | 5:577b582e4fe9 | 43 | while (1) |
hazheng | 5:577b582e4fe9 | 44 | { |
hazheng | 18:bf6c5f8281eb | 45 | |
hazheng | 18:bf6c5f8281eb | 46 | float deltaTime = timeWas; |
hazheng | 18:bf6c5f8281eb | 47 | timeWas = timer.read(); |
hazheng | 18:bf6c5f8281eb | 48 | deltaTime = timeWas - deltaTime; |
hazheng | 18:bf6c5f8281eb | 49 | |
Bobymicjohn | 11:676ea42afd56 | 50 | //led = 0; |
hazheng | 29:f87d8790f57d | 51 | g_core.Update(deltaTime); |
hazheng | 25:6f63053cee81 | 52 | //motor.Update(deltaTime); |
hazheng | 25:6f63053cee81 | 53 | //servo.Update(deltaTime); |
hazheng | 25:6f63053cee81 | 54 | //wheelEncoder.Update(deltaTime); |
hazheng | 29:f87d8790f57d | 55 | //cam.Update(deltaTime); |
hazheng | 16:66c7a09e71ee | 56 | |
hazheng | 18:bf6c5f8281eb | 57 | tempCount += deltaTime; |
hazheng | 18:bf6c5f8281eb | 58 | if(tempCount > 1.0f) |
hazheng | 5:577b582e4fe9 | 59 | { |
hazheng | 29:f87d8790f57d | 60 | //led = !led; |
hazheng | 18:bf6c5f8281eb | 61 | tempCount = 0.0f; |
hazheng | 3:c8867972ffc7 | 62 | } |
hazheng | 3:c8867972ffc7 | 63 | |
hazheng | 40:be98219930e4 | 64 | /* |
hazheng | 32:5badeff825dc | 65 | if(!isRegRead && g_core.GetUSBServer().GetStatus() == SER_STAT_RUNNING && timer.read() > 2.5f && ardu_cam_get_fifo_length() > 0) |
hazheng | 13:7dcb1642ef99 | 66 | { |
hazheng | 32:5badeff825dc | 67 | //OV7725RegBuf * regBuf = new OV7725RegBuf(g_core); |
hazheng | 32:5badeff825dc | 68 | //regBuf->ReadRegisters(); |
hazheng | 32:5badeff825dc | 69 | //delete regBuf; |
hazheng | 32:5badeff825dc | 70 | ardu_cam_print_debug(); |
hazheng | 13:7dcb1642ef99 | 71 | isRegRead = true; |
hazheng | 13:7dcb1642ef99 | 72 | } |
hazheng | 40:be98219930e4 | 73 | */ |
hazheng | 29:f87d8790f57d | 74 | |
Bobymicjohn | 8:92f6baeea027 | 75 | wait(0.01); |
hazheng | 3:c8867972ffc7 | 76 | } |
hazheng | 3:c8867972ffc7 | 77 | } |
hazheng | 3:c8867972ffc7 | 78 | |
hazheng | 3:c8867972ffc7 | 79 | /* |
hazheng | 3:c8867972ffc7 | 80 | PwmOut servo(PTE20); |
hazheng | 3:c8867972ffc7 | 81 | |
hazheng | 3:c8867972ffc7 | 82 | int main() { |
hazheng | 3:c8867972ffc7 | 83 | servo.period(0.020); // servo requires a 20ms period |
hazheng | 3:c8867972ffc7 | 84 | |
hazheng | 3:c8867972ffc7 | 85 | while (1) { |
hazheng | 3:c8867972ffc7 | 86 | for(float offset=0.0; offset<0.001; offset+=0.0001) { |
hazheng | 3:c8867972ffc7 | 87 | servo.pulsewidth(0.001 + offset); // servo position determined by a pulsewidth between 1-2ms |
hazheng | 3:c8867972ffc7 | 88 | wait(0.25); |
hazheng | 3:c8867972ffc7 | 89 | } |
hazheng | 3:c8867972ffc7 | 90 | } |
hazheng | 3:c8867972ffc7 | 91 | |
hazheng | 3:c8867972ffc7 | 92 | } |
hazheng | 13:7dcb1642ef99 | 93 | */ |
hazheng | 13:7dcb1642ef99 | 94 | |
hazheng | 13:7dcb1642ef99 | 95 | /* //code for accelerometer sensor. |
hazheng | 13:7dcb1642ef99 | 96 | const char regAddr = 0x0D; |
hazheng | 13:7dcb1642ef99 | 97 | char readValue = 0; |
hazheng | 13:7dcb1642ef99 | 98 | int result1 = m_sccbCtrl.write(0x1D<<1, ®Addr, 1, true); |
hazheng | 13:7dcb1642ef99 | 99 | int result2 = m_sccbCtrl.read(0x1D<<1, &readValue, 1, false); |
hazheng | 13:7dcb1642ef99 | 100 | char buf[20]; |
hazheng | 13:7dcb1642ef99 | 101 | sprintf(buf, "%#x-%#x-%d-%d", regAddr, readValue, result1, result2); |
hazheng | 13:7dcb1642ef99 | 102 | m_core.GetUSBServer().PushUnreliableMsg('D', buf); |
hazheng | 3:c8867972ffc7 | 103 | */ |