|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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; counter++; printf ( "counter value: ", counter); Any suggestions would be very much appreciated! |
|
#2
|
|||
|
|||
|
Re: Last minute autonomous programming!
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.
|
|
#3
|
||||
|
||||
|
Re: Last minute autonomous programming!
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\n", (int) counter); As was pointed out, is this all in the same loop? |
|
#4
|
||||
|
||||
|
Re: Last minute autonomous programming!
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:
Code:
static unsigned char counter; |
|
#5
|
|||
|
|||
|
Re: Last minute autonomous programming!
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
Code:
static unsigned int counter; |
|
#6
|
||||
|
||||
|
Re: Last minute autonomous programming!
True. It depends how fast this loop is running. If it is running constantly, then a larger type should be used.
|
|
#7
|
||||
|
||||
|
Re: Last minute autonomous programming!
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.
|
|
#8
|
||||
|
||||
|
Re: Last minute autonomous programming!
Quote:
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'. -q Last edited by Qbranch : 17-03-2008 at 10:34. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Last Minute Work! | Aratarin | Chit-Chat | 0 | 18-02-2007 16:08 |
| Last Minute Programming Failures | robobrain0101 | Programming | 3 | 11-02-2007 14:30 |
| pic: last minute cheeseholing | Veselin Kolev | Robot Showcase | 8 | 22-02-2005 19:25 |
| Last-Minute changes? | Iain McLeod | General Forum | 9 | 09-04-2003 02:51 |
| Last Minute Mouse Robots | Hamster_Power58 | Rules/Strategy | 1 | 12-03-2002 14:32 |