Buttons not always inputting to the right motors?

Hi, we are having a problem with our code. When we press a button (say for intake) it only happens some of the time. Other times, when we press a button, the rollers will move.

For example: one time, when we pressed any of the shoulder buttons, only the intake would move. Other times, when we’d press the only the rollers would move.

Here is the code, so you can see that they are mapped to different buttons: (on mobile so sorry for bad formatting)

    void opcontrol()
{
	while(1){
		if(tankDrive == true){
			drive->getModel()->tank(controller.getAnalog(ControllerAnalog::leftY), controller.getAnalog(ControllerAnalog::rightY));
			//up-down movement of joysticks read to different directions of movement.
		}
		else{
				drive->getModel()->arcade(controller.getAnalog(ControllerAnalog::leftY), controller.getAnalog(ControllerAnalog::leftX));
				//arcade control - only one joystick controls which way the robot is moving
			}
	if(intakeButton.isPressed()){
		 intake.moveVelocity(650); //Test

	}
	else if(outtakeButton.isPressed()){
		 intake.moveVelocity(-650); //More testing here, too

	}
	else if(rollersInButton.isPressed()){
		rollers.moveVelocity(650);
	}
	else if(rollersOutButton.isPressed()){
		rollers.moveVelocity(-650);
	}
	else {
		 intake.moveVelocity(0);
		 rollers.moveVelocity(0);

	}
	pros::delay(10); //edit delay as we see fit.
}

}


The button declarations:

//Button inputs

okapi::ControllerButton intakeButton(okapi::ControllerDigital::L1, false);
okapi::ControllerButton outtakeButton(okapi::ControllerDigital::L2, false);
okapi::ControllerButton rollersInButton(okapi::ControllerDigital::R1, false);
okapi::ControllerButton rollersOutButton(okapi::ControllerDigital::R2, false);

For your buttons try changing it to pressing instead of pressed. Pressed is generally not used for driver control unless it’s a Marcos of sorts

1 Like

Are you hoping to be able to move both rollers and intakes at the same time? At the moment, you have it so the two are linked and so only one or the other can be run at any time - the rollers are an else if to the intake - that is to say they can only be run if the intake is not. If you want to be able to run them both at the same time, you probably need something like:

   if(intakeButton.isPressed()){
		 intake.moveVelocity(650); //Test

	}
	else if(outtakeButton.isPressed()){
		 intake.moveVelocity(-650); //More testing here, too

	}
        else {
		 intake.moveVelocity(0);
	}


	if(rollersInButton.isPressed()){
		rollers.moveVelocity(650);
	}
	else if(rollersOutButton.isPressed()){
		rollers.moveVelocity(-650);
	}
	else {
		 rollers.moveVelocity(0);
	}

I’ve not used PROS so not sure on the Pressed/Pressing thing, but in VEXcode it would be pressing.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.