View Single Post
  #2   Spotlight this post!  
Unread 05-03-2007, 22:26
michniewski michniewski is offline
Registered User
FRC #1353
 
Join Date: Jan 2007
Location: Canada
Posts: 6
michniewski is an unknown quantity at this point
Post Re: Autonomous selector

I have an even more modified version of the autonomous selector code: this one is even simpler, and uses the exact same logic / has the same features. The only difference is that it is much cleaner. Here it is:


Note: this can be posted in user_routines.c or a separate file as we have.
Code:
// auton_selector()
//
// Select Autonomous Routine #
//
// - hundreds of autonomous plays can be chosen
// - use up/down switches defined by AUTON_UP etc in user_routines.h
// - shown on OI lcd
int auton_select = DEFAULT_AUTON_NUM;
void auton_selector(void)
{
	static char sw_up_prev;
	static char sw_dn_prev;

	// if up switch is pressed
	// increment autonomous routine number, 
	// if less than the max
	if(AUTON_UP == 1 && AUTON_UP != sw_up_prev && auton_select < MAX_AUTON_ROUTINES)
		auton_select++;

	// if pressed down switch,
	// decrement auton_select 
	// if higher than lowest routine number
	if(AUTON_DN == 1 && AUTON_DN != sw_dn_prev && auton_select > LOWEST_AUTON_NUM)
		auton_select--;

	sw_up_prev = AUTON_UP; // oneshot the trigger and top buttons
	sw_dn_prev = AUTON_DN;

	User_Mode_byte = auton_select;

	return;

}
Additionally, there is added commenting, which can be removed to make the code smaller, if thats what you want. It's only a few lines anyways.

Put the following into Default_Routine() in user_routines.c:
Code:
// handles the autonomous routine selection:
auton_selector();
& PLACE IT above the following line:
Code:
 /*---------- ROBOT FEEDBACK LEDs
... etc.

The following must be copied into user_routines.h:
Code:
// Autonomous Selection Defines:
#define		AUTON_UP				p4_sw_aux1		// autonomous select UP switch
#define		AUTON_DN				p4_sw_aux2		// autonomous select DOWN switch
#define		MAX_AUTON_ROUTINES		10				// max number of autonomous routines to scroll thru
#define		LOWEST_AUTON_NUM		1				// lowest auton number (keep it at one (1) )
#define		DEFAULT_AUTON_NUM		1				// the default autonomous routine

// Function Prototypes
void auton_selector(void);
Thats all! Have fun, and good luck.
__________________
- Michael Michniewski
Team 1353, The Spartans



Greater Toronto Regional
- look for the Spartan mascot