car using PID from centre line
Dependencies: FRDM-TFC mbed CBuffer XBEE mbed_angular_speed motor2 MMA8451Q
Fork of KL25Z_Camera_Test by
Diff: main.cpp
- Revision:
- 34:3de7a19ccea3
- Parent:
- 32:6829684f8c4d
- Child:
- 35:e23354abf352
--- a/main.cpp Wed Jan 11 19:59:03 2017 +0000 +++ b/main.cpp Thu Jan 12 12:51:24 2017 +0000 @@ -97,7 +97,7 @@ void initVariables() { // Initialise three PID controllers for the servo and each wheel. - initPID(&servo_pid, 2.2f, 0.6f, 0.f); + initPID(&servo_pid, 0.f, 0.f, 0.f); initPID(&left_motor_pid, 0.01f, 0.f, 0.f); initPID(&right_motor_pid, 0.01f, 0.f, 0.f); @@ -152,7 +152,7 @@ rightSeen = false; //Starting in the middle index, step left, inspecting the the edge of the track - for(i = 63; i > 0; i--) { + for(i = 63; i > 2; i--) { curr_left = (uint8_t)(cam_data[i] >> 4) & 0xFF; diff = prev - curr_left; //Check incorporates a combination of looking at the difference in intensities @@ -167,7 +167,7 @@ prev = -1; //As before, start in the middle but this time step rightwards in the image - for(i = 64; i < 128; i++) { + for(i = 64; i < 126; i++) { curr_right = (uint8_t)(cam_data[i] >> 4) & 0xFF; int diff = prev - curr_right; if(abs(diff) >= CAM_DIFF && curr_right <= CAM_THRESHOLD && prev != -1) { @@ -183,6 +183,7 @@ sendString("lost edges"); ALIGN_SERVO; //Straighten wheels so we go straight through the crossroads servo_pid.integral = 0; + l=0;r=128; } //Calculate how left/right from the centre line we are