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:
Fri Feb 10 03:23:20 2017 +0000
Revision:
16:66c7a09e71ee
Parent:
13:7dcb1642ef99
Child:
18:bf6c5f8281eb
Added delta time.

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 11:676ea42afd56 5 #include "Core.h"
Bobymicjohn 11:676ea42afd56 6 #include "SWUSBServer.h"
hazheng 13:7dcb1642ef99 7 #include "Camera.h"
Bobymicjohn 10:fedb5786a109 8
Bobymicjohn 10:fedb5786a109 9 #include "PinAssignment.h"
Bobymicjohn 8:92f6baeea027 10
Bobymicjohn 11:676ea42afd56 11 //DigitalOut led(LED1, 1);
hazheng 5:577b582e4fe9 12
hazheng 3:c8867972ffc7 13 int main(void) {
hazheng 16:66c7a09e71ee 14
hazheng 16:66c7a09e71ee 15 Timer timer;
hazheng 16:66c7a09e71ee 16
Bobymicjohn 11:676ea42afd56 17 SW::Core core;
Bobymicjohn 10:fedb5786a109 18
Bobymicjohn 11:676ea42afd56 19 Motor motor(core);
Bobymicjohn 11:676ea42afd56 20 Servo servo(core);
hazheng 13:7dcb1642ef99 21 Camera cam(core);
hazheng 6:0682e1c90119 22
hazheng 16:66c7a09e71ee 23
hazheng 13:7dcb1642ef99 24 bool isRegRead = false;
hazheng 16:66c7a09e71ee 25
hazheng 16:66c7a09e71ee 26 timer.start();
hazheng 5:577b582e4fe9 27 while (1)
hazheng 5:577b582e4fe9 28 {
hazheng 16:66c7a09e71ee 29 float deltaTime = timer.read();
hazheng 16:66c7a09e71ee 30 timer.reset();
Bobymicjohn 11:676ea42afd56 31 //led = 0;
hazheng 16:66c7a09e71ee 32 core.Update(deltaTime);
hazheng 16:66c7a09e71ee 33 motor.Update(deltaTime);
hazheng 16:66c7a09e71ee 34 servo.Update(deltaTime);
hazheng 16:66c7a09e71ee 35
hazheng 3:c8867972ffc7 36
hazheng 13:7dcb1642ef99 37 if(!isRegRead && core.GetUSBServer().GetStatus() == SER_STAT_RUNNING)
hazheng 13:7dcb1642ef99 38 {
hazheng 13:7dcb1642ef99 39 cam.ReadRegisters();
hazheng 13:7dcb1642ef99 40 isRegRead = true;
hazheng 13:7dcb1642ef99 41 }
hazheng 13:7dcb1642ef99 42
hazheng 16:66c7a09e71ee 43 //wait(0.01);
hazheng 3:c8867972ffc7 44 }
hazheng 3:c8867972ffc7 45 }
hazheng 3:c8867972ffc7 46
hazheng 3:c8867972ffc7 47 /*
hazheng 3:c8867972ffc7 48 PwmOut servo(PTE20);
hazheng 3:c8867972ffc7 49
hazheng 3:c8867972ffc7 50 int main() {
hazheng 3:c8867972ffc7 51 servo.period(0.020); // servo requires a 20ms period
hazheng 3:c8867972ffc7 52
hazheng 3:c8867972ffc7 53 while (1) {
hazheng 3:c8867972ffc7 54 for(float offset=0.0; offset<0.001; offset+=0.0001) {
hazheng 3:c8867972ffc7 55 servo.pulsewidth(0.001 + offset); // servo position determined by a pulsewidth between 1-2ms
hazheng 3:c8867972ffc7 56 wait(0.25);
hazheng 3:c8867972ffc7 57 }
hazheng 3:c8867972ffc7 58 }
hazheng 3:c8867972ffc7 59
hazheng 3:c8867972ffc7 60 }
hazheng 13:7dcb1642ef99 61 */
hazheng 13:7dcb1642ef99 62
hazheng 13:7dcb1642ef99 63 /* //code for accelerometer sensor.
hazheng 13:7dcb1642ef99 64 const char regAddr = 0x0D;
hazheng 13:7dcb1642ef99 65 char readValue = 0;
hazheng 13:7dcb1642ef99 66 int result1 = m_sccbCtrl.write(0x1D<<1, &regAddr, 1, true);
hazheng 13:7dcb1642ef99 67 int result2 = m_sccbCtrl.read(0x1D<<1, &readValue, 1, false);
hazheng 13:7dcb1642ef99 68 char buf[20];
hazheng 13:7dcb1642ef99 69 sprintf(buf, "%#x-%#x-%d-%d", regAddr, readValue, result1, result2);
hazheng 13:7dcb1642ef99 70 m_core.GetUSBServer().PushUnreliableMsg('D', buf);
hazheng 3:c8867972ffc7 71 */