Autonomous selector

I was wondering if there is a way to read from the OI, before autonomous, a value. We are coding multiple autonomous functions and I need a way to select which one to run. We can’t put it on the robot because we have no inputs left. We have 1 completely unused port on the OI if that helps.
Thanks,
Garrett
Team 41

When the robot is disabled before autonomous you can read the OI switches. Set a (static) variable from one of those switches, and then you can choose your mode from that in autonomous.

It’s pretty similar to reading one off the robot.

It’s written by Kevin Watson. We used a slightly modified version of it.

void auton_selector(void)
{
static char last_sw1;
static char last_sw2;

if(AUTON_UP == 1 && AUTON_UP != last_sw1)
{
if(auton_select < MAXAUTONROUTINES)
auton_select++;
else
auton_select=99;
}
if(AUTON_DN == 1 && AUTON_DN != last_sw2 && auton_select > 0)
{
if (auton_select == 94)
auton_select=MAXAUTONROUTINES;
else
auton_select–;
}
last_sw1 = AUTON_UP; //oneshot the trigger and top buttons
last_sw2 = AUTON_DN;

User_Mode_Byte = auton_select;

}

User_Mode_Byte is the user display on the OI. Use that little button to change to it.

AUTON_UP/DOWN are the defines to which a joystick button or something similar.

We put little switches (the ones that go from 0-9) on the robot and hook them up to the dig in. Before each match, we set the autonomous mode by hand.

We used click wheels like that (except our went much higher than 9) last year. We had two, one for starting position, and one for the autonomous “play”. It worked really well for us, although we really ended up only using 3 plays of the many we had available.
You’ll be seeing something more advanced this year though if all goes to plan :wink:

We used a little toggle switch on the robot last year.

if(rc_dig_in01 == 0)
{
run_blocking_auton()
}
else
{
run_shooting_auton()
}

You used all 18 digital I/O pins?! Holy cow batman.

The code that I posted previously, written by Kevin Watson, allows you have have 254 autons, that can be seen in the user display(the number) of the OI! Beats soldering any switches… We have been using this for the last 4 years at all competitions.

We used 16 of them, that only leaves 2 open. That can only make 4 combinations, but we need 5.

6600GT thanks for the tip. I’ll be doing that this year as the selector. Thank you everyone for your help.

Use the trigger and thumb to set the autonomous mode. Pull the trigger and goto the next number. You can have the OI display what mode you have selected.

Do you have any analog inputs left? If so, you should be able to use a 5 position toggle switch with 5 different value resistors as a sort of multiplexor. Just read the analog value and determine auto mode that way… i think. im no programmer though ; )

We usedd this same technique to make rotary switches for our OI that used one analog input for various purposes and it works fine. The programming part of it is really simple as well.

Our team (MVRT) has a keypad that takes up one whole port. The keypad is coded in assembly and has its own circuit board and the lcd screen is powered by regular AA batteries. The keypad allows us to have 64 different autonomous positions and choose which alliance we are and which position we are in.

Is it legal to use batteries like that?

Does anyone have any multiple autonomous code for easy-C?

This is specifically disallowed by rule <R83>. Unless the LCD has no physical connection to the keypad and interfaces with only the dashboard port, it violates the rule of powering devices from a source other than the OI.

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.


// 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:


// handles the autonomous routine selection:
auton_selector();

& PLACE IT above the following line:

 /*---------- ROBOT FEEDBACK LEDs

… etc.

The following must be copied into user_routines.h:



// 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.