3Here's an example of what my terminal windows looks like after I get after telling the robot to turn, then go straight. This isn't actually code - it's what prints out into the terminal window. First, it does the turn, and the gyro value reflects that:
Code:
Autonomous State = Turn
Loop Number = 1
Gyro Value = 75
Left Motor = 127, Right Motor = 230
Autonomous State = Turn
Loop Number = 2
Gyro Value = 75
Left Motor = 127, Right Motor = 230
Autonomous State = Turn
Loop Number = 3
Gyro Value = 75
Left Motor = 127, Right Motor = 230
Autonomous State = Turn
Loop Number = 4
Gyro Value = 75
Left Motor = 127, Right Motor = 230
This continues until the robot has turned 90 degrees, as determined by the gear tooth sensors (and I can confirm by watching it that that works):
Code:
Autonomous State = Turn
Loop Number = 32
Gyro Value = 75
Left Motor = 127, Right Motor = 230
Autonomous State = Turn
Loop Number = 33
Gyro Value = 75
Left Motor = 127, Right Motor = 230
Autonomous State = Turn
Loop Number = 34
Gyro Value = 75
Left Motor = 127, Right Motor = 230
TURN DONE
Now that the turn is done, I go into another function that tells the robot to go straight, using the gyro to make corrections to the motor speeds. In that function, the printouts say:
Code:
Autonomous State = Straight
Loop Number = 35
Gyro Value = 75
Left Motor = 230, Right Motor = 230
Autonomous State = Straight
Loop Number = 36
Gyro Value = 75
Left Motor = 230, Right Motor = 190
Autonomous State = Straight
Loop Number = 37
Gyro Value = 75
Left Motor = 230, Right Motor = 160
Autonomous State = Straight
Loop Number = 38
Gyro Value = 75
Left Motor = 230, Right Motor = 140
Autonomous State = Straight
Loop Number = 39
Gyro Value = 75
Left Motor = 230, Right Motor = 127
Autonomous State = Straight
Loop Number = 40
Gyro Value = 75
Left Motor = 230, Right Motor = 127
Autonomous State = Straight
Loop Number = 41
Gyro Value = 75
Left Motor = 230, Right Motor = 127
That continues for about forty loops, when the gyro finally notices that we aren't turning anymore:
Code:
Autonomous State = Straight
Loop Number = 75
Gyro Value = 80
Left Motor = 230, Right Motor = 127
Autonomous State = Straight
Loop Number = 76
Gyro Value = 95
Left Motor = 230, Right Motor = 150
Autonomous State = Straight
Loop Number = 77
Gyro Value = 115
Left Motor = 230, Right Motor = 180
Autonomous State = Straight
Loop Number = 78
Gyro Value = 127
Left Motor = 230, Right Motor = 230
Now, the robot thinks it's going straight and stops correcting the motors. Of course, it's actually way off course, since it "corrected" for 30 tics in which the gyro reported a left turn that wasn't actually happening.
Note that I was putting that into my own words since I didn't save the terminal printouts and can't get new ones right now. The gyro value actually varied between 72 and 78 during the turn.
I can slow down the printouts, but I don't see how that would help. Yes, all of the printouts are delayed. In fact, we get a red light of death if we run autonomous mode for too long with those printouts on (serial buffer overflows). But all of the prinouts should be affected by the same delay. The fact remains that, for forty tics after the turn stops, the gyro reports that we are still turning.
The only way the printouts could be the problem is if they were somehow slowing down the ADC but not the rest of the code. I'll try slowing down the printouts to once every ten loops tomorrow (we're taking today off), but I doubt it will help.
I think the problem is related to us exceeding the gyro's 80 dps range during the turn, but like I said, we don't want to buy the 300 dps version only to find out that it has the same lag.
What exactly happens when you exceed the gyro's range? Will it simply report its maximum range and then go back down when you stop turning? Or will it get "stuck" at its maximum range for about a second?
And no, we aren't using any other loops in our code except the master 26.2ms loop. We used to use a while loop to do atuonomous, but we fixed that. There are a few floating point operations, but nothing too complicated.