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@10:fedb5786a109, 2017-02-07 (annotated)
- Committer:
- Bobymicjohn
- Date:
- Tue Feb 07 18:20:38 2017 +0000
- Revision:
- 10:fedb5786a109
- Parent:
- 8:92f6baeea027
- Child:
- 11:676ea42afd56
Added pin assignment for servo, and changed its pin from PTE20 to PTB0 for easier access.
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" |
hazheng | 5:577b582e4fe9 | 4 | |
hazheng | 5:577b582e4fe9 | 5 | #include "USBHIDServer.h" |
Bobymicjohn | 10:fedb5786a109 | 6 | |
Bobymicjohn | 10:fedb5786a109 | 7 | #include "PinAssignment.h" |
hazheng | 3:c8867972ffc7 | 8 | |
Bobymicjohn | 10:fedb5786a109 | 9 | PwmOut servo(ST_SERVO); |
Bobymicjohn | 8:92f6baeea027 | 10 | |
hazheng | 5:577b582e4fe9 | 11 | DigitalOut led(LED1, 1); |
hazheng | 5:577b582e4fe9 | 12 | |
hazheng | 3:c8867972ffc7 | 13 | int main(void) { |
Bobymicjohn | 4:25e028102625 | 14 | servo.period(0.020); |
Bobymicjohn | 10:fedb5786a109 | 15 | servo.pulsewidth(0.00185); |
hazheng | 5:577b582e4fe9 | 16 | //Camera cam; |
hazheng | 6:0682e1c90119 | 17 | |
Bobymicjohn | 8:92f6baeea027 | 18 | Motor motor; |
Bobymicjohn | 10:fedb5786a109 | 19 | motor.setLeftSpeed(0.5f); |
Bobymicjohn | 10:fedb5786a109 | 20 | motor.setRightSpeed(0.5f); |
Bobymicjohn | 10:fedb5786a109 | 21 | |
Bobymicjohn | 10:fedb5786a109 | 22 | wait(5); |
Bobymicjohn | 10:fedb5786a109 | 23 | |
Bobymicjohn | 10:fedb5786a109 | 24 | servo.pulsewidth(0.0012); |
Bobymicjohn | 10:fedb5786a109 | 25 | motor.setLeftSpeed(0.5f); |
Bobymicjohn | 10:fedb5786a109 | 26 | motor.setRightSpeed(0.5f); |
Bobymicjohn | 8:92f6baeea027 | 27 | |
Bobymicjohn | 8:92f6baeea027 | 28 | wait(2); |
Bobymicjohn | 8:92f6baeea027 | 29 | |
Bobymicjohn | 8:92f6baeea027 | 30 | motor.setLeftSpeed(-0.0f); |
Bobymicjohn | 8:92f6baeea027 | 31 | motor.setRightSpeed(-0.0f); |
Bobymicjohn | 4:25e028102625 | 32 | |
hazheng | 5:577b582e4fe9 | 33 | USBHIDServer server; |
hazheng | 6:0682e1c90119 | 34 | |
hazheng | 5:577b582e4fe9 | 35 | unsigned int testCount = 0; |
hazheng | 5:577b582e4fe9 | 36 | unsigned int testCount2 = 0; |
hazheng | 5:577b582e4fe9 | 37 | char buf[5]; |
hazheng | 3:c8867972ffc7 | 38 | |
hazheng | 5:577b582e4fe9 | 39 | while (1) |
hazheng | 5:577b582e4fe9 | 40 | { |
hazheng | 5:577b582e4fe9 | 41 | led = 0; |
hazheng | 5:577b582e4fe9 | 42 | server.Update(0.0f); |
Bobymicjohn | 8:92f6baeea027 | 43 | motor.Update(0.0f); |
hazheng | 5:577b582e4fe9 | 44 | testCount++; |
hazheng | 5:577b582e4fe9 | 45 | if(testCount >= 10000) |
hazheng | 5:577b582e4fe9 | 46 | { |
hazheng | 5:577b582e4fe9 | 47 | testCount2++; |
hazheng | 5:577b582e4fe9 | 48 | sprintf(buf, "%d", testCount2); |
hazheng | 5:577b582e4fe9 | 49 | //server.PushUnreliableMsg('D', "Test Message!"); |
hazheng | 5:577b582e4fe9 | 50 | server.PushUnreliableMsg('D', buf); |
hazheng | 5:577b582e4fe9 | 51 | testCount = 0; |
hazheng | 3:c8867972ffc7 | 52 | } |
hazheng | 3:c8867972ffc7 | 53 | |
Bobymicjohn | 8:92f6baeea027 | 54 | wait(0.01); |
hazheng | 3:c8867972ffc7 | 55 | } |
hazheng | 3:c8867972ffc7 | 56 | } |
hazheng | 3:c8867972ffc7 | 57 | |
hazheng | 3:c8867972ffc7 | 58 | /* |
hazheng | 3:c8867972ffc7 | 59 | PwmOut servo(PTE20); |
hazheng | 3:c8867972ffc7 | 60 | |
hazheng | 3:c8867972ffc7 | 61 | int main() { |
hazheng | 3:c8867972ffc7 | 62 | servo.period(0.020); // servo requires a 20ms period |
hazheng | 3:c8867972ffc7 | 63 | |
hazheng | 3:c8867972ffc7 | 64 | while (1) { |
hazheng | 3:c8867972ffc7 | 65 | for(float offset=0.0; offset<0.001; offset+=0.0001) { |
hazheng | 3:c8867972ffc7 | 66 | servo.pulsewidth(0.001 + offset); // servo position determined by a pulsewidth between 1-2ms |
hazheng | 3:c8867972ffc7 | 67 | wait(0.25); |
hazheng | 3:c8867972ffc7 | 68 | } |
hazheng | 3:c8867972ffc7 | 69 | } |
hazheng | 3:c8867972ffc7 | 70 | |
hazheng | 3:c8867972ffc7 | 71 | } |
hazheng | 3:c8867972ffc7 | 72 | */ |