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