first commit

Dependencies:   mbed MMA8451Q

Revision:
18:831c1e03d83e
Parent:
13:0091da3021df
Child:
19:65fecaa2a387
--- a/steering_methods.h	Tue Oct 26 19:10:13 2021 +0000
+++ b/steering_methods.h	Tue Oct 26 22:56:10 2021 +0000
@@ -66,7 +66,7 @@
     float err;
     if(steering_enabled == true ){
         //Read each sensor and calculate the sensor difference
-        float sensor_difference = left_distance_sensor.read() -
+        float sensor_difference = left_distance_sensor.read()1*4 -
                                   right_distance_sensor.read();
                                   
         //calculate the feedback term for the controller. distance (meters) from
@@ -79,14 +79,14 @@
         
         //Calculate the derivative of the error term for the controller.
         //  e'(t) = (error(t) - error(t-1))/dt
-        float errChange = (err - err_prev)/(TI);
+        float errChange = (err - err_prev)/(0.02);
         
         //Calculate the controller output
         //Angle in radians
         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.001){
+        if( abs(current_duty_cycle - prev_duty) >= 0.0001){
             servo_motor_pwm.write(current_duty_cycle);
             };
       }