Question about having 2 channels to control 1 motor

Our Toss-Up robot for this year has two “stages” of intake. The first stage is a pair of side rolllers. The second stage is a conveyor on the top (which we may move to the bottom).

Right now, we have Ch5 powering both parts of the intake. However, if we continuously run the conveyor with a BuckyBall, it will push the ball against our stop and bend it, possibly causing our lift to fail.

At our competition, I attempted to set up an “override” so that we can either power the rollers by themselves, the conveyor by itself, or both together. I set it up so that if you attempt to power them both together it “locks” the individual control. Here’s the code for it:


bool lock;

if (vexRT[Btn6U]) { //Intake and Conveyor together have priority, Ch6
			//Outtake
			motor[leftIntake] = 127;
			motor[rightIntake] = -127;
			motor[conveyor] = -127;
			lock = true; //Override individual
		}
		else if (vexRT[Btn6D]) {
			//Intake
			motor[leftIntake] = -127;
			motor[rightIntake] =  127;
			motor[conveyor] = 127;
			lock = true; //Override individual
		}
		else {
			//Stop
			motor[leftIntake] = 0;
			motor[rightIntake] = 0;
			motor[conveyor] = 0;
			lock = false; //No Override
		}

		if (vexRT[Btn8R] && !lock /*Rollers only work if Ch6 is not activated*/) {
                        //Intake rollers
			motor[leftIntake] = 127;
			motor[rightIntake] = -127;
		}
		else if (vexRT[Btn8D] && !lock) {
			motor[leftIntake] = -127;
			motor[rightIntake] = 127;
		}

		if (vexRT[Btn7L] && !lock) { //Same as above
			motor[conveyor] = -127;
		}
		else if (vexRT[Btn7D] && !lock) {
			motor[conveyor] = 127;
		}

The part for the intake rollers worked fine. Ch8 did not affect them when Ch6 was powered. However, the part for the conveyor did nothing. It worked fine with Ch6, but Ch8 didn’t do anything at all.

I learned quickly that I couldn’t have an “else” statement on the 2nd and 3rd blocks that stopped the motors. I completely removed the else statements, causing the behavior above. Should I still have an else paired with each of the ifs? If so, what should I put in it? Is there anything else I can do?

I would like to clarify a few things before we start digging into the code. What order should the robot check for things? For example:

  • If button 6 Up or 6 Down is pressed, control both the slide rollers and the intake together
  • Else, if button 6 Up or 6 Down is not pressed, control the slide rollers and intake separately.

Is this correct? If so, we can convert this directly into psuedocode that will help us simplify the problem:

Note that this is rough psuedocode (not actual ROBOTC code) but will help you visualize the layout of your program in ‘plain English’. If this looks correct, you can start plugging in the different parts of the code; luckily, you have most of it already built (checking for different button presses and having the robot react accordingly).

First, we’ll take a look at the condition of the if statement:

We know how to check for button 6 up and button 6 down, so we can plug those both in directly:

Since we are looking for either of the two buttons to be pressed in order to execute the if statement’s code, we can use the logical OR (||) operator:

Finally, we know we are looking for an ‘is pressed’ condition, which means the buttons will return a value of 1 when pressed; we don’t have to do anything with a ‘NOT’ operator in this case.

Now that we know how to convert the first one from psuedocode to regular ROBOTC code, the ‘else if’ statement is fairly easy; note, however, that we are looking for the condition where both button 6 up AND button 6 down are NOT pressed:

From here, it’s a simple matter of putting in the rest of the commands (which you already have) to check and control the intake depending on what buttons are pressed:

Since we are no longer using the boolean variable, it can be removed from the program and the if/else statements. I have also added a couple of comments to help with some other issues you may run into (the motors not turning off when the 7 or 8 buttons are released). Let us know if you have any other questions, we are always happy to help!

On a side note: you can learn more about using the buttons on the VEXNet controller, multiconditional statements, and the operators used in the conditional statements by taking a look at the ‘Remote Control -> Buttons’ sections of the VEX Cortex Video Trainer, which we provide online free of charge.