i = 0
turned = 0
while turned == 0:
if GyroInertial.heading(DEGREES) > 269:
if GyroInertial.heading(DEGREES) <= 270:
turned = 0
The code is supposed to detect if the heading is in the specific range. It usually works as expected, however occasionally it will print “in range” despite not physically nor the heading value being in range. I assume when heading overflows from 0 to 360 it incorrectly detects it as being in range. Is there a possible fix or workaround?
More likely is that you never clear the screen. So you get the robot in range, turn it elsewhere, look at the screen, and it still says “in range” from before, but that’s just because it hasn’t been cleared.
Thank you for replying, however I’m aware that it does not clean. The concern is when it prints “in range” initially when it’s nowhere near the range heading. Also it sets turning to 0 which acts as a debounce in order for it to stop detecting when it already detects it once.
You should not get the same results with and without calibration. If you do not allow the gyro to calibrate at the beginning of your run, it should drift at a constant rate in one direction. This should not happen if the gyro is calibrated. I suggest printing the gyro’s heading to the screen and analyzing.