Last minute autonomous programming!

We need help using a counting variable for programming autonomous. The counter should be incrementing but its not. It sorta looks like this:

unsigned counter = 0;


printf ( "counter value: ", counter);

Any suggestions would be very much appreciated!

your variable declaration is executed every loop, meaning it will be initialized to 0 every loop. declare it as a static unsigned, and your counter will work.

Actual code would help…

I see several problems with what you posted:

No type on counter:
unsigned int counter = 0;

No spec in the printf to actually print the value:
printf( "counter value: %d
", (int) counter);

As was pointed out, is this all in the same loop?

If it is all within the loop, to prevent the counter from being reset every iteration of the loop, declare it in the following manner:

static unsigned char counter;

I’d referain from making it a char. A char will overflow after 256 cycles. Running around 26.2hz, the main loop will make 256 cycles in around 9.8 seconds. After that, it will drop to zero and start rising again. I’d suggest you make it

static unsigned int counter;

True. It depends how fast this loop is running. If it is running constantly, then a larger type should be used.

Autonomous only lasts 15 seconds. And teleop is 2 minutes. With about only 39 iterations per second, an unsigned int is more than enough to hold the tick counter.

26.2ms/packet is actually about 38.17Hz.

Also, I believe this variable would overflow in about 6.7 seconds. I suggest you blow the extra byte of memory and go for an unsigned integer just to cover everything, as this won’t overflow until after a whole 28 minutes at the 26.2ms rate.

I suggest a switch statement to run your time based autonomous.

If you are going to Cleveland, i’d be happy to give you some ‘pointers’. :]