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);