Go to Post One button, ten copyrights, you do the math. - StephLee [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-03-2008, 19:43
ZP8892's Avatar
ZP8892 ZP8892 is offline
Registered User
FRC #0369
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2006
Location: United States
Posts: 7
ZP8892 is an unknown quantity at this point
Send a message via AIM to ZP8892
Exclamation 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;

counter++;

printf ( "counter value: ", counter);

Any suggestions would be very much appreciated!
  #2   Spotlight this post!  
Unread 11-03-2008, 19:45
tdlrali tdlrali is offline
Registered User
FRC #0469 (Las Guerrillas)
Team Role: Programmer
 
Join Date: Sep 2006
Rookie Year: 2006
Location: MI
Posts: 377
tdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud of
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   Spotlight this post!  
Unread 11-03-2008, 19:59
scottanderson's Avatar
scottanderson scottanderson is offline
Software Architect
AKA: Scott Anderson
FRC #2608 (MiGHT)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2008
Location: Shelby Township
Posts: 20
scottanderson is an unknown quantity at this point
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?
__________________
Regards,
Scott Anderson
Team 2608 MiGHT Mentor
  #4   Spotlight this post!  
Unread 12-03-2008, 01:17
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
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   Spotlight this post!  
Unread 12-03-2008, 01:20
Guy Davidson Guy Davidson is offline
Registered User
AKA: formerly sumadin
FRC #0008 (Paly Robotics)
Team Role: Alumni
 
Join Date: Mar 2005
Rookie Year: 2005
Location: Ra'anana, Israel
Posts: 660
Guy Davidson is a splendid one to beholdGuy Davidson is a splendid one to beholdGuy Davidson is a splendid one to beholdGuy Davidson is a splendid one to beholdGuy Davidson is a splendid one to beholdGuy Davidson is a splendid one to beholdGuy Davidson is a splendid one to beholdGuy Davidson is a splendid one to behold
Send a message via ICQ to Guy Davidson Send a message via AIM to Guy Davidson Send a message via MSN to Guy Davidson
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   Spotlight this post!  
Unread 12-03-2008, 01:21
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
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   Spotlight this post!  
Unread 16-03-2008, 21:04
Loubear's Avatar
Loubear Loubear is offline
Registered User
AKA: YLou
FRC #0075 (RoboRaiders)
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2006
Location: NJ
Posts: 33
Loubear will become famous soon enoughLoubear will become famous soon enough
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   Spotlight this post!  
Unread 16-03-2008, 22:43
Qbranch Qbranch is offline
wow college goes fast.
AKA: Alex
FRC #1024 (Kil-A-Bytes)
Team Role: Alumni
 
Join Date: Apr 2006
Rookie Year: 2006
Location: Indianapolis
Posts: 1,174
Qbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond reputeQbranch has a reputation beyond repute
Re: Last minute autonomous programming!

Quote:
Originally Posted by sumadin View Post
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;
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'.

-q
__________________
Electrical Engineer Illini
1024 | Programmer '06, '07, '08 | Driver '08

Last edited by Qbranch : 17-03-2008 at 10:34.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 01:00.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi