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@15:eb6a274b3dfb, 2017-02-14 (annotated)
- Committer:
- Bobymicjohn
- Date:
- Tue Feb 14 19:51:57 2017 +0000
- Revision:
- 15:eb6a274b3dfb
- Parent:
- 14:88302da8bff0
- Child:
- 20:4cdbd1ae4ead
Finished wheelEncoder 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) { |
Bobymicjohn | 11:676ea42afd56 | 15 | |
Bobymicjohn | 11:676ea42afd56 | 16 | SW::Core core; |
Bobymicjohn | 10:fedb5786a109 | 17 | |
Bobymicjohn | 11:676ea42afd56 | 18 | Motor motor(core); |
Bobymicjohn | 11:676ea42afd56 | 19 | Servo servo(core); |
Bobymicjohn | 15:eb6a274b3dfb | 20 | WheelEncoder wheelEncoder(core); |
hazheng | 13:7dcb1642ef99 | 21 | Camera cam(core); |
hazheng | 6:0682e1c90119 | 22 | |
hazheng | 5:577b582e4fe9 | 23 | unsigned int testCount = 0; |
hazheng | 5:577b582e4fe9 | 24 | unsigned int testCount2 = 0; |
hazheng | 5:577b582e4fe9 | 25 | char buf[5]; |
hazheng | 13:7dcb1642ef99 | 26 | bool isRegRead = false; |
Bobymicjohn | 14:88302da8bff0 | 27 | |
hazheng | 5:577b582e4fe9 | 28 | while (1) |
hazheng | 5:577b582e4fe9 | 29 | { |
Bobymicjohn | 11:676ea42afd56 | 30 | //led = 0; |
Bobymicjohn | 11:676ea42afd56 | 31 | core.Update(0.0f); |
Bobymicjohn | 8:92f6baeea027 | 32 | motor.Update(0.0f); |
hazheng | 5:577b582e4fe9 | 33 | testCount++; |
Bobymicjohn | 11:676ea42afd56 | 34 | if(testCount >= 200) |
hazheng | 5:577b582e4fe9 | 35 | { |
hazheng | 5:577b582e4fe9 | 36 | testCount2++; |
hazheng | 5:577b582e4fe9 | 37 | sprintf(buf, "%d", testCount2); |
Bobymicjohn | 11:676ea42afd56 | 38 | servo.setAngle(SERVO_RT * SERVO_MAX_ANGLE); |
Bobymicjohn | 11:676ea42afd56 | 39 | //core.GetUSBServer().PushUnreliableMsg('D', buf); |
hazheng | 5:577b582e4fe9 | 40 | testCount = 0; |
hazheng | 3:c8867972ffc7 | 41 | } |
hazheng | 3:c8867972ffc7 | 42 | |
Bobymicjohn | 15:eb6a274b3dfb | 43 | /* |
hazheng | 13:7dcb1642ef99 | 44 | if(!isRegRead && core.GetUSBServer().GetStatus() == SER_STAT_RUNNING) |
hazheng | 13:7dcb1642ef99 | 45 | { |
hazheng | 13:7dcb1642ef99 | 46 | cam.ReadRegisters(); |
hazheng | 13:7dcb1642ef99 | 47 | isRegRead = true; |
hazheng | 13:7dcb1642ef99 | 48 | } |
Bobymicjohn | 15:eb6a274b3dfb | 49 | */ |
Bobymicjohn | 8:92f6baeea027 | 50 | wait(0.01); |
hazheng | 3:c8867972ffc7 | 51 | } |
hazheng | 3:c8867972ffc7 | 52 | } |
hazheng | 3:c8867972ffc7 | 53 | |
hazheng | 3:c8867972ffc7 | 54 | /* |
hazheng | 3:c8867972ffc7 | 55 | PwmOut servo(PTE20); |
hazheng | 3:c8867972ffc7 | 56 | |
hazheng | 3:c8867972ffc7 | 57 | int main() { |
hazheng | 3:c8867972ffc7 | 58 | servo.period(0.020); // servo requires a 20ms period |
hazheng | 3:c8867972ffc7 | 59 | |
hazheng | 3:c8867972ffc7 | 60 | while (1) { |
hazheng | 3:c8867972ffc7 | 61 | for(float offset=0.0; offset<0.001; offset+=0.0001) { |
hazheng | 3:c8867972ffc7 | 62 | servo.pulsewidth(0.001 + offset); // servo position determined by a pulsewidth between 1-2ms |
hazheng | 3:c8867972ffc7 | 63 | wait(0.25); |
hazheng | 3:c8867972ffc7 | 64 | } |
hazheng | 3:c8867972ffc7 | 65 | } |
hazheng | 3:c8867972ffc7 | 66 | |
hazheng | 3:c8867972ffc7 | 67 | } |
hazheng | 13:7dcb1642ef99 | 68 | */ |
hazheng | 13:7dcb1642ef99 | 69 | |
hazheng | 13:7dcb1642ef99 | 70 | /* //code for accelerometer sensor. |
hazheng | 13:7dcb1642ef99 | 71 | const char regAddr = 0x0D; |
hazheng | 13:7dcb1642ef99 | 72 | char readValue = 0; |
hazheng | 13:7dcb1642ef99 | 73 | int result1 = m_sccbCtrl.write(0x1D<<1, ®Addr, 1, true); |
hazheng | 13:7dcb1642ef99 | 74 | int result2 = m_sccbCtrl.read(0x1D<<1, &readValue, 1, false); |
hazheng | 13:7dcb1642ef99 | 75 | char buf[20]; |
hazheng | 13:7dcb1642ef99 | 76 | sprintf(buf, "%#x-%#x-%d-%d", regAddr, readValue, result1, result2); |
hazheng | 13:7dcb1642ef99 | 77 | m_core.GetUSBServer().PushUnreliableMsg('D', buf); |
hazheng | 3:c8867972ffc7 | 78 | */ |