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
Diff: main.cpp
- Revision:
- 4:25e028102625
- Parent:
- 3:c8867972ffc7
- Child:
- 6:0682e1c90119
diff -r c8867972ffc7 -r 25e028102625 main.cpp --- a/main.cpp Wed Feb 01 00:35:48 2017 +0000 +++ b/main.cpp Thu Feb 02 23:30:41 2017 +0000 @@ -1,36 +1,34 @@ #include "mbed.h" -#include "Camera.h" -#include "USBHID.h" - -//We declare a USBHID device. Input out output reports have a length of 8 bytes -USBHID hid(8, 8); + +//#include "Motor.h" -//This report will contain data to be sent -HID_REPORT send_report; -HID_REPORT recv_report; - -Serial pc(USBTX, USBRX); - -int main(void) { - Camera cam; - send_report.length = 8; +PwmOut servo(PTE20); + +//DigitalOut DIR_L(PTA13, 1); +//DigitalOut DIR_R(PTC9, 1); + +//PwmOut PWM_L(PTD0); +//PwmOut PWM_R(PTD5); + +int main(void) { + servo.period(0.020); + //Motor motor; + + //PWM_L.period_us(60); + //PWM_R.period_us(60); + while (1) { - //Fill the report - for (int i = 0; i < send_report.length; i++) { - send_report.data[i] = rand() & 0xff; - } - - //Send the report - hid.send(&send_report); + //motor.setLeftSpeed(20); + //motor.setRightSpeed(20); + //PWM_L.pulsewidth_us(60); + //PWM_R.pulsewidth_us(60); + //servo.pulsewidth(0.0015); - //try to read a msg - if(hid.readNB(&recv_report)) { - pc.printf("recv: "); - for(int i = 0; i < recv_report.length; i++) { - pc.printf("%d ", recv_report.data[i]); - } - pc.printf("\r\n"); + 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); } wait(0.1);