
first commit
Diff: steering_methods.h
- Revision:
- 19:65fecaa2a387
- Parent:
- 18:831c1e03d83e
- Child:
- 20:7dcdadbd7bc0
--- a/steering_methods.h Tue Oct 26 22:56:10 2021 +0000 +++ b/steering_methods.h Thu Oct 28 00:28:29 2021 +0000 @@ -35,14 +35,25 @@ } // ------------ LANDMARK DETECTION ------------ int counter = 0; +volatile bool landmark_triggered=false; // Debugging purposes only +volatile bool restarted = false; // Debugging purposes only void landmark_counter(void){ + landmark_triggered=false; // Debugging purposes only + restarted = false; // Debugging purposes only if(counter >= 15) counter =0; turn_seg_off(seg1); if(right_landmark_sensor.read() == 1 || left_landmark_sensor.read() == 1 ) + { + landmark_triggered =true; // Debugging purpose only counter++ ; + + } if(right_landmark_sensor.read() == 1 && left_landmark_sensor.read() == 1 ) - counter = 0; + { + counter = 0; + restarted=true; // Debugging purposes only + } show_decimal(counter, seg1); } @@ -66,8 +77,8 @@ float err; if(steering_enabled == true ){ //Read each sensor and calculate the sensor difference - float sensor_difference = left_distance_sensor.read()1*4 - - right_distance_sensor.read(); + float sensor_difference = left_distance_sensor.read() - + right_distance_sensor.read()*1.4; //calculate the feedback term for the controller. distance (meters) from //track to sensor @@ -86,7 +97,7 @@ float servo_angle = (KP*err + KD*errChange*TIME_DERIVATIVE)/10; //Calculate the duty cycle for the servo motor current_duty_cycle = rad2dc(servo_angle); - if( abs(current_duty_cycle - prev_duty) >= 0.0001){ + if( abs(current_duty_cycle - prev_duty) >= 0.0000103){ servo_motor_pwm.write(current_duty_cycle); }; }