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@25:6f63053cee81, 2017-02-21 (annotated)
- Committer:
- hazheng
- Date:
- Tue Feb 21 20:00:41 2017 +0000
- Revision:
- 25:6f63053cee81
- Parent:
- 21:60377d6f1cc2
- Child:
- 26:5814404856e2
Added formal version of OV7725RegBuf class.
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 | 13:7dcb1642ef99 | 8 | #include "Camera.h" |
Bobymicjohn | 10:fedb5786a109 | 9 | |
Bobymicjohn | 10:fedb5786a109 | 10 | #include "PinAssignment.h" |
Bobymicjohn | 8:92f6baeea027 | 11 | |
Bobymicjohn | 11:676ea42afd56 | 12 | //DigitalOut led(LED1, 1); |
hazheng | 5:577b582e4fe9 | 13 | |
hazheng | 3:c8867972ffc7 | 14 | int main(void) { |
hazheng | 16:66c7a09e71ee | 15 | |
hazheng | 16:66c7a09e71ee | 16 | Timer timer; |
hazheng | 16:66c7a09e71ee | 17 | |
Bobymicjohn | 11:676ea42afd56 | 18 | SW::Core core; |
Bobymicjohn | 10:fedb5786a109 | 19 | |
hazheng | 25:6f63053cee81 | 20 | //Motor motor(core); |
hazheng | 25:6f63053cee81 | 21 | //Servo servo(core); |
hazheng | 25:6f63053cee81 | 22 | //WheelEncoder wheelEncoder(core); |
hazheng | 13:7dcb1642ef99 | 23 | Camera cam(core); |
hazheng | 6:0682e1c90119 | 24 | |
hazheng | 18:bf6c5f8281eb | 25 | DigitalOut led(LED3, 1); |
hazheng | 16:66c7a09e71ee | 26 | |
hazheng | 25:6f63053cee81 | 27 | //bool isRegRead = false; |
Bobymicjohn | 14:88302da8bff0 | 28 | |
Bobymicjohn | 21:60377d6f1cc2 | 29 | //motor.setLeftSpeed(0.2); |
Bobymicjohn | 21:60377d6f1cc2 | 30 | |
hazheng | 18:bf6c5f8281eb | 31 | float tempCount = 0; |
hazheng | 18:bf6c5f8281eb | 32 | //timer.reset(); |
hazheng | 16:66c7a09e71ee | 33 | timer.start(); |
hazheng | 18:bf6c5f8281eb | 34 | float timeWas = timer.read(); |
hazheng | 5:577b582e4fe9 | 35 | while (1) |
hazheng | 5:577b582e4fe9 | 36 | { |
hazheng | 18:bf6c5f8281eb | 37 | |
hazheng | 18:bf6c5f8281eb | 38 | float deltaTime = timeWas; |
hazheng | 18:bf6c5f8281eb | 39 | timeWas = timer.read(); |
hazheng | 18:bf6c5f8281eb | 40 | deltaTime = timeWas - deltaTime; |
hazheng | 18:bf6c5f8281eb | 41 | |
Bobymicjohn | 11:676ea42afd56 | 42 | //led = 0; |
hazheng | 16:66c7a09e71ee | 43 | core.Update(deltaTime); |
hazheng | 25:6f63053cee81 | 44 | //motor.Update(deltaTime); |
hazheng | 25:6f63053cee81 | 45 | //servo.Update(deltaTime); |
hazheng | 25:6f63053cee81 | 46 | //wheelEncoder.Update(deltaTime); |
hazheng | 16:66c7a09e71ee | 47 | |
hazheng | 18:bf6c5f8281eb | 48 | tempCount += deltaTime; |
hazheng | 18:bf6c5f8281eb | 49 | if(tempCount > 1.0f) |
hazheng | 5:577b582e4fe9 | 50 | { |
hazheng | 18:bf6c5f8281eb | 51 | led = !led; |
hazheng | 18:bf6c5f8281eb | 52 | tempCount = 0.0f; |
hazheng | 3:c8867972ffc7 | 53 | } |
hazheng | 3:c8867972ffc7 | 54 | |
Bobymicjohn | 15:eb6a274b3dfb | 55 | /* |
hazheng | 13:7dcb1642ef99 | 56 | if(!isRegRead && core.GetUSBServer().GetStatus() == SER_STAT_RUNNING) |
hazheng | 13:7dcb1642ef99 | 57 | { |
hazheng | 13:7dcb1642ef99 | 58 | cam.ReadRegisters(); |
hazheng | 13:7dcb1642ef99 | 59 | isRegRead = true; |
hazheng | 13:7dcb1642ef99 | 60 | } |
Bobymicjohn | 15:eb6a274b3dfb | 61 | */ |
Bobymicjohn | 8:92f6baeea027 | 62 | wait(0.01); |
hazheng | 3:c8867972ffc7 | 63 | } |
hazheng | 3:c8867972ffc7 | 64 | } |
hazheng | 3:c8867972ffc7 | 65 | |
hazheng | 3:c8867972ffc7 | 66 | /* |
hazheng | 3:c8867972ffc7 | 67 | PwmOut servo(PTE20); |
hazheng | 3:c8867972ffc7 | 68 | |
hazheng | 3:c8867972ffc7 | 69 | int main() { |
hazheng | 3:c8867972ffc7 | 70 | servo.period(0.020); // servo requires a 20ms period |
hazheng | 3:c8867972ffc7 | 71 | |
hazheng | 3:c8867972ffc7 | 72 | while (1) { |
hazheng | 3:c8867972ffc7 | 73 | for(float offset=0.0; offset<0.001; offset+=0.0001) { |
hazheng | 3:c8867972ffc7 | 74 | servo.pulsewidth(0.001 + offset); // servo position determined by a pulsewidth between 1-2ms |
hazheng | 3:c8867972ffc7 | 75 | wait(0.25); |
hazheng | 3:c8867972ffc7 | 76 | } |
hazheng | 3:c8867972ffc7 | 77 | } |
hazheng | 3:c8867972ffc7 | 78 | |
hazheng | 3:c8867972ffc7 | 79 | } |
hazheng | 13:7dcb1642ef99 | 80 | */ |
hazheng | 13:7dcb1642ef99 | 81 | |
hazheng | 13:7dcb1642ef99 | 82 | /* //code for accelerometer sensor. |
hazheng | 13:7dcb1642ef99 | 83 | const char regAddr = 0x0D; |
hazheng | 13:7dcb1642ef99 | 84 | char readValue = 0; |
hazheng | 13:7dcb1642ef99 | 85 | int result1 = m_sccbCtrl.write(0x1D<<1, ®Addr, 1, true); |
hazheng | 13:7dcb1642ef99 | 86 | int result2 = m_sccbCtrl.read(0x1D<<1, &readValue, 1, false); |
hazheng | 13:7dcb1642ef99 | 87 | char buf[20]; |
hazheng | 13:7dcb1642ef99 | 88 | sprintf(buf, "%#x-%#x-%d-%d", regAddr, readValue, result1, result2); |
hazheng | 13:7dcb1642ef99 | 89 | m_core.GetUSBServer().PushUnreliableMsg('D', buf); |
hazheng | 3:c8867972ffc7 | 90 | */ |