All those are great suggestions, but I think the problem is deeper than that. I noticed today that the program state light stays yellow when I download. I tried changing around a few things, such as the last function I added. I ditched the if counter>40 thing, and just printfing every time doesn't even work.
Basically, this is the last function I added since it stopped working:
Code:
void findcurrentpos(void) /*basically takes input from yaw rate sensor and integrates to find how much the direction has changed*/
{
current.theta += ((gyroin + gyroprev - 1023) * CGYRO * deltat) + 2000; /* finds our current direction cgyro converts to degrees/100, find average and multiply by time, dt converted to seconds by dt/1000*/
deltat = 0; /*modified in user_routines_fast with the internal timer*/
// if (current.theta < 2000) {current.theta += 36000;}
// current.theta -= 2000;
// if (current.theta > 360) {current.theta -= 36000;}
// gyroprev = gyroin;
}/*end findcurrentpos()*/
(CGYRO = 0.08)
And this gives me either an overflow error, or the Program State LED on the Edubot blinks red. In the Edubot reference guide a blinking red light means an infinite loop.
However, a funny thing happens when I comment out all the code in findcurrentpos(), It works! no blinking red light, no overflow error. I wonder if there is a limit for how large a math operation can be. I know on my calculator, if you multiply two very large values, you can get an overflow error. I also had another problem with a sin approximation giving an overflow error. I just replaced it with a lookup table. If there is such a limit, what is it?