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:
- 69:34e97694f0ef
- Parent:
- 67:1b5c8add3d01
- Parent:
- 68:b15cab740371
- Child:
- 70:311d32a596db
--- a/main.cpp Thu Apr 13 17:57:31 2017 +0000 +++ b/main.cpp Thu Apr 13 18:02:22 2017 +0000 @@ -43,7 +43,7 @@ motor_init(); servo_init(); - bool isRegRead = false; + //bool isRegRead = false; ardu_utft_init(); @@ -58,31 +58,26 @@ //imu_manager_begin_tick(); //wait(0.5); - //timer.reset(); + /* DeltaTime Calculation timer.start(); float timeWas = timer.read(); - + */ servo_set_angle(0.0f); float speedRatio = 1.0f; float lastAngle = 0.0f; float cornerRatio = 1.0f; - DebugCounter counter(10, PTE5); + //DebugCounter counter(10, PTE5); while (1) { + /* DeltaTime Calculation float deltaTime = timeWas; timeWas = timer.read(); deltaTime = timeWas - deltaTime; - - //g_core.Update(deltaTime); + */ - //if(!isRegRead && g_core.GetUSBServer().GetStatus() == SER_STAT_RUNNING && timer.read() > 2.5f && ardu_cam_is_capture_finished()) - //{ - //ardu_cam_print_debug(); - // isRegRead = true; - //} //ardu_cam_display_img_utft(); image_processing(); @@ -94,7 +89,7 @@ servo_set_angle(0.0f); motor_set_right_speed(-1.0f); motor_set_left_speed(-1.0f); - wait(0.5f); + wait(0.4f); motor_set_right_speed(0.0f); motor_set_left_speed(0.0f); return 0; @@ -134,12 +129,7 @@ { totalAngleDegrees = totalAngleDegrees * -1.0f; } - /* - if(totalAngleDegreesAbs >= 1.0f && totalAngleDegreesAbs <= 4.0) - { - continue; - } - */ + servo_set_angle(totalAngleDegrees); @@ -190,9 +180,44 @@ motor_set_left_speed(speedRatio * cornerRatio * 1.0f); } + lastAngle = totalAngleDegrees; + } +} + +/* +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); +*/ + + //g_core.Update(deltaTime); - lastAngle = totalAngleDegrees; - + //if(!isRegRead && g_core.GetUSBServer().GetStatus() == SER_STAT_RUNNING && timer.read() > 2.5f && ardu_cam_is_capture_finished()) + //{ + //ardu_cam_print_debug(); + // isRegRead = true; + //} + //LOGI("FPS: %f", 1 / deltaTime); //imu_manager_init(); @@ -211,7 +236,7 @@ //LOGI("P: %5.3f, %5.3f, %5.3f ", PositionV->x, PositionV->y, PositionV->z); - counter.Update(); + //counter.Update(); /* //////// Steer Vehicle / Adjust Speed for Differential ////////// @@ -258,32 +283,4 @@ motor_set_speeds(0.13f, 0.13f); } */ - //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); -*/ \ No newline at end of file + //wait(0.01); \ No newline at end of file