Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Autonomous selector (http://www.chiefdelphi.com/forums/showthread.php?t=53237)

Jared Russell 02-02-2007 19:07

Re: Autonomous selector
 
Quote:

Originally Posted by sarcasticmadnes (Post 570372)
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.

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.

michniewski 05-03-2007 22:26

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.


All times are GMT -5. The time now is 23:56.

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