View Single Post
  #3   Spotlight this post!  
Unread 30-03-2004, 16:37
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: counting in seconds for the autonomous mode??

Quote:
Originally Posted by Pattyta
does any one knows how to convert the cycles of the autonomous mode 26.2ms to like actual seconds to keep a counter in seconds???
Here's the simple solution I used to keep track of milliseconds.
Code:
#define MS *4
void User_Autonomous_Code(void)
{
	unsigned int clicks; /* 4000 clicks per second theoretical, 4007.63358779 clicks actual :-) */
	
	clicks = 0;
	
	while (autonomous_mode)   /* DO NOT CHANGE! */
	{
		if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
		{
			Getdata(&rxdata);   /* DO NOT DELETE, or you will be stuck here forever! */

			if (clicks < 16000 MS)
				clicks += 105; /* 26.2 more milliseconds have elapsed, this count will be fast by just over 0.19% */
			else
				clicks = 16000 MS; /* peg at 16 seconds */

			/* Add your own autonomous code here. */

			User_Mode_byte = clicks/400;
			Generate_Pwms(pwm13,pwm14,pwm15,pwm16);
			Putdata(&txdata);   /* DO NOT DELETE, or you will get no PWM outputs! */
		}
	}
}
I complicated things slightly by using four "clicks" per millisecond. In the normal case of autonomous operation, the unsigned int will not overflow, but I limited it to 16 seconds anyway. Defining MS as a modifier was just a convenience so the other programmer could use "real" times while deciding when the program should take action.

The User_Mode_byte on the OI counts in tenths of a second while the autonomous function is running.