Left_Drive_Value = p1_y; //Get left drive (we're a skid-steer) Right_Drive_Value = p2_y; //Get right drive (we're a skid-steer) //If our sticks show the opposite direction from the previous loop, reset count_2 to zero. This will allow the brake to stop us to 127, then allow count_2 to ramp up. if (((Left_Drive_Value < 127) && (Right_Drive_Value < 127) && (Old_Right_Drive_Value > 127) && (Old_Left_Drive_Value > 127)) || ((Left_Drive_Value > 127) && (Right_Drive_Value > 127) && (Old_Right_Drive_Value > 127) && (Old_Left_Drive_Value > 127))) count_2 = 0; //While there is a difference greater than 50, moderate the decel if (((Old_Right_Drive_Value - Right_Drive_Value) > 50) && ((Old_Left_Drive_Value - Left_Drive_Value) > 50) && (Left_Drive_Value < 127) && (Right_Drive_Value < 127) && (count == 3)) { Old_Left_Drive_Value = 127 - count_2; Old_Right_Drive_Value = 127 - count_2; count_2 = count_2 + 1; if (count_2 > 127) count_2 = 127; Limit Count 2 count = 0; //Count allows us to only go into the if/then every 3 loops. Without this, the pic loops too quickly and doesn't ever see a radical shift of the joysticks } //While there is a difference greater than 50, moderate the accel else if (((Old_Right_Drive_Value - Right_Drive_Value) < -50) && ((Old_Left_Drive_Value - Left_Drive_Value) < -50) && (Left_Drive_Value > 127) && (Right_Drive_Value > 127) && (count == 3)) { Old_Left_Drive_Value = 127 + count_2; Old_Right_Drive_Value = 127 + count_2; count_2 = count_2 + 1; if (count_2 > 127) count_2 = 127; count = 0; //Count allows us to only go into the if/then every 3 loops. Without this, the pic loops too quickly and doesn't ever see a radical shift of the joysticks //printf("We got to 6\r\n"); } else if (count == 3) //If we've gone three loops but the values don't show we need to moderate accel / decel, then reset the old drive values. { Old_Left_Drive_Value = Left_Drive_Value; Old_Right_Drive_Value = Right_Drive_Value; count = 0; //Count allows us to only go into the if/then every 3 loops. Without this, the pic loops too quickly and doesn't ever see a radical shift of the joysticks count_2 = 0; } if (Old_Left_Drive_Value > 255) //Insure we stay within range. Old_Left_Drive_Value = 255; else if (Old_Left_Drive_Value < 0) Old_Left_Drive_Value = 0; if (Old_Right_Drive_Value > 255) //Insure we stay within range. Old_Right_Drive_Value = 255; else if (Old_Right_Drive_Value < 0) Old_Right_Drive_Value = 0; Left_Drive = Old_Left_Drive_Value; Right_Drive = Old_Right_Drive_Value;