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
- Committer:
- Bobymicjohn
- Date:
- 2017-02-14
- Revision:
- 21:60377d6f1cc2
- Parent:
- 20:4cdbd1ae4ead
- Child:
- 25:6f63053cee81
File content as of revision 21:60377d6f1cc2:
#include "mbed.h" #include "Motor.h" #include "Servo.h" #include "WheelEncoder.h" #include "Core.h" #include "SWUSBServer.h" #include "Camera.h" #include "PinAssignment.h" //DigitalOut led(LED1, 1); int main(void) { Timer timer; SW::Core core; Motor motor(core); Servo servo(core); WheelEncoder wheelEncoder(core); Camera cam(core); DigitalOut led(LED3, 1); bool isRegRead = false; //motor.setLeftSpeed(0.2); float tempCount = 0; //timer.reset(); timer.start(); float timeWas = timer.read(); while (1) { float deltaTime = timeWas; timeWas = timer.read(); deltaTime = timeWas - deltaTime; //led = 0; core.Update(deltaTime); motor.Update(deltaTime); servo.Update(deltaTime); wheelEncoder.Update(deltaTime); tempCount += deltaTime; if(tempCount > 1.0f) { led = !led; tempCount = 0.0f; } /* if(!isRegRead && core.GetUSBServer().GetStatus() == SER_STAT_RUNNING) { cam.ReadRegisters(); isRegRead = true; } */ wait(0.01); } } /* PwmOut servo(PTE20); int main() { servo.period(0.020); // servo requires a 20ms period while (1) { for(float offset=0.0; offset<0.001; offset+=0.0001) { servo.pulsewidth(0.001 + offset); // servo position determined by a pulsewidth between 1-2ms wait(0.25); } } } */ /* //code for accelerometer sensor. const char regAddr = 0x0D; char readValue = 0; int result1 = m_sccbCtrl.write(0x1D<<1, ®Addr, 1, true); int result2 = m_sccbCtrl.read(0x1D<<1, &readValue, 1, false); char buf[20]; sprintf(buf, "%#x-%#x-%d-%d", regAddr, readValue, result1, result2); m_core.GetUSBServer().PushUnreliableMsg('D', buf); */