re: question about gyro chip
Greg provided an excellent explanation, but I'll throw in my two cents worth anyway.
One way to get a good look at how the filter works is to use Excel to make a graph. Here's a step-by-step guide if you need it.
Put the number 128 in the cells A1, B1 and A2. Put the number 23 in cell C1. In Cell B2 put the following equation (without the quotes): "=B1+(A2-B1)*$C$1/200" then copy this equation and paste it for 30 or 40 rows down the B column starting at B3. Ignore the numbers that it calculates for now. The numbers you put in column A represent the Angle Rate Sensor input and the numbers in column B are the filtered signal that's being used by the code. Try this: put the number 150 in cells A3 through A20, then put the number 120 in cells A21 through the end (however far you copied column B to). Select A1 through the last row in column B (e.g. A1:B40) and hit the chart button. Select a line chart in the chart wizard and keep hitting the next / finish buttons until it draws a chart. If the y axis starts at 0, double click the y axis and change the min and max values to 110 and 160. Change the value in C1 and see how this effects the filtered values.
As for the numbers in the for - next loops, There were indeed established by trial and error. When "Balance Mode" is initiated, the code takes over control of the drive motors (you'll notice that the code ignores the joystick input within this routine) and starts driving at a steady rate in one direction while monitoring the Angle Rate Sensor. When a threshold value is reached on the sensor (also determined by trial and error) the robot automatically changes direction by sending a fixed value to the drive motors each time through the loop. Then it changes direction again, this time at a slower speed for a different number of loops. Separate code had to be written for the starting up the ramp in forward or reverse because the drive motors react differently in the two directions.
Hope this sheds a little more light. Feel free to contact me if you want more details.
__________________
Jeff Burch
TechnoKats #45
|