Program switching

Our team has two drivers with two different button layouts. Is there a way to switch between control schemes using the LCD?

You could do it on the joystick too. You don’t need to do it via LCD. you are looking for a state in your program to decide which button set to use on the joysticks. You don;t really need to do it until driver control starts as your joysticks are not doing anything before then.

I would start with one set and toggle it to the other on demand. Alternatively you could use the pre-auton LCD set up to set the choice as well as other means like a potentiometer, jumper, or button rubber banded into the on position. Many ways to do that initial setting.

So do this kind of thing in the driver control loop. Code is from my head, not compiled…


if (drive_control_state == state2)
{ 
      // map buttons and joysticks for driver 2's preferences.  
      // use variables versus setting the motors to limit change in the code. 
     // example here for lift heights
      if(vexRT[btn8D] ==1)
      {
          target_height = ARM_UP;
      }
     // and any other control things you do differently.....
}
else 
{
    // map  buttons and joysticks to driver 1's preferences
      if(vexRT[btn8U] ==1)
      {
          target_height = ARM_UP;
      }
}

// now make some combo of buttons to switch between the states
if (vexRT[btn7L]==1 && vexRT[btn8R]==1)
{
       drive_control_state =state2;
}
if (vexRT[btn7U]==1 && vexRT[btn8U]==1)
{
       drive_control_state =state1;
}

Using a single condition for the toggle is much, much easier, especially because I prefer using the change in state rather than the actual state of the button. You can try something like this:



#define CTL_TOGGLE (vexRT[Btn8U] || (nLcdBtns == 2))

void defaultCtl() {
  //Insert Default Control Code
}

void altCtl() {
  //Insert Alternate Control Code
}

task main() {
  bool ctlToggleLast,
    driverAlt = false;

  while(true) {
    if(driverAlt)
      altCtl();
    else
      defaultCtl();
    if(CTL_TOGGLE && !ctlToggleLast)
      driverAlt = !driverAlt;
    ctlToggleLast = CTL_TOGGLE;
  }
}

This should compile, although I’m not sure about the nLcdBtns variable. That might not be the right name, but it’s accessing the variable correctly. That uses the center button.

If you have more than 2 drivers, you can use a switch case statement and an incrementing/decrementing int. I can write a sample of that if you want.

I gave you one solution in this thread.
https://vexforum.com/t/custom-controller-schemes/35308/1

To do the same type of thing with the LCD would be similar to using it to select from two or more different autonomous runs. There are some example here on how to do that in the thread below, however, these may be a bit advanced so search the forum for threads about using the LCD.
https://vexforum.com/t/robotc-lcd-autonomous-selection/24818/1