switching modes

in STL we only had one autonomous mode so we could only set up on the left side of the field. i have written more programs but i don’t know or understand how to write the code to switch between different modes. i have written 4 mode (includes right and left). i would prefer to be able to switch modes from the OI but am open to doing it anyway possible. i need something i know will work since we accedently left the robot controller on the robot so i have no way of testing it before our next regional.

thankyou so much
allison

Well, I believe the OI can’t send data inputs to the RC during autonomous. However, if you put 2 switches on your RC and plug them into the “Digital Inputs”… simply make one code, with all 4 modes on it. Make one switch the side switch (i.e. when on run Left side, when off run Right side code) and the other switch can choose between 2 modes… if you want to do 4 modes like you said, you can do more digital inputs with switches to choose. Then just in your code make IF loops to pick the code. Tell me if this makes sense, I’m kind’ve tired so I don’t know if I make any sense.

You can in fact use the OI [edit] apparently im wrong about the rest of what i said i trust 10inthecrunch’s explanation better than my own :slight_smile: [/edit]

We use switches this year on our OI. The robot and OI are in full communication when you set them out on the field (just PWM and relay outputs are squelched), and inputs are only set to neutral when you go into autonomous. So, to do this: figure out which digital inputs you want to use, and in your program, capture the previous values of those inputs (the program makes one more sweep with neutral values, so you need the good ones from before that).

Basically just set up variables for the previous values and set them at the bottom of User_Routines, and in your Main function, create a variable that amalgamates those variables. Now you have one variable you can use for a switch statement in your autonomous code.

PM or IM me if you have trouble getting it to work, its a little difficult to explain in a static post :).

Last year we used a switch wired into the RC to tell whether we would turn left or right. I am not sure about whether or not we used one program, or had it switch between two programs. I was not the programmer last year, but I may have heard from our previous programmer that it switched between two different programs.

And it turns out that Main.c is messed up. when Auton is set, it does one run of Process_Data_From_Master_uP() before doing Auton. I’ll post a fix if anyone wants it.

Yeah, I had noticed that. I actually fixed it in our code. Personally, I feel that the framework they gave us was badly designed, but whatever. :slight_smile:

Better than nothing.

Here’s what we’re talking about:


void main (void)
{
#ifdef UNCHANGEABLE_DEFINITION_AREA
  IFI_Initialization ();        /* DO NOT CHANGE! */
#endif

  User_Initialization();        /* You edit this in user_routines.c */

  statusflag.NEW_SPI_DATA = 0;  /* DO NOT CHANGE! */ 

  while (1)   /* This loop will repeat indefinitely. */
  {
#ifdef _SIMULATOR
    statusflag.NEW_SPI_DATA = 1;
#endif

    if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
    {                                 /* I'm slow!  I only execute every 26.2ms because */
                                      /* that's how fast the Master uP gives me data. */
      if (autonomous_mode)            /* DO NOT CHANGE! */
        User_Autonomous_Code();    //You edit this in user_routines_fast.c
      
**      Process_Data_From_Master_uP();  //Used to be before the if**
    }
    Process_Data_From_Local_IO();     /* You edit this in user_routines_fast.c */
                                      /* I'm fast!  I execute during every loop.*/
  } /* while (1) */
}  /* END of Main */