Pneumatic programming help in auton vs driving

Hello:

I had these line defined :
digital_out Claw = digital_out(Brain.ThreeWirePort.A);

That said, if I put codes in auton area:

image

Everything works OK. The cylinder moved in, waited 3 seconds and out waited 3 sec few times during auton as expected.

I then put these lines in driver control:

Screenshot 2021-11-29 090058

Driver control works fine. But… auton won’t work anymore. Just the 3 sec + 3 sec + 3 sec wait and wait. If I take out driver control codes, auton codes work again. Why is there a conflict? Any help will be greatly appreciated.

Thank you.

Can you send the full functions where you define the movements (these would typically would be usercontrol and your autonomous function. also try defining your pneumatics like so:

pneumatics Claw = pneumatics(Brain.ThreeWirePort.A);

and just for future reference / forum edict include your code by using “```” before and after your code.

3 Likes

User control:

"’
// define a task that will handle monitoring inputs from Controller1
int rc_auto_loop_function_Controller1() {
// process the controller input every 20 milliseconds
// update the motors based on the input values
while(true) {
if(RemoteControlCodeEnabled) {
// calculate the drivetrain motor velocities from the controller joystick axies
// left = Axis3
// right = Axis2
int drivetrainLeftSideSpeed = Controller1.Axis3.position();
int drivetrainRightSideSpeed = Controller1.Axis2.position();

  // check if the value is inside of the deadband range
  if (drivetrainLeftSideSpeed < 5 && drivetrainLeftSideSpeed > -5) {
    // check if the left motor has already been stopped
    if (DrivetrainLNeedsToBeStopped_Controller1) {
      // stop the left drive motor
      LeftDriveSmart.stop();
      // tell the code that the left motor has been stopped
      DrivetrainLNeedsToBeStopped_Controller1 = false;
    }
  } else {
    // reset the toggle so that the deadband code knows to stop the left motor nexttime the input is in the deadband range
    DrivetrainLNeedsToBeStopped_Controller1 = true;
  }
  // check if the value is inside of the deadband range
  if (drivetrainRightSideSpeed < 5 && drivetrainRightSideSpeed > -5) {
    // check if the right motor has already been stopped
    if (DrivetrainRNeedsToBeStopped_Controller1) {
      // stop the right drive motor
      RightDriveSmart.stop();
      // tell the code that the right motor has been stopped
      DrivetrainRNeedsToBeStopped_Controller1 = false;
    }
  } else {
    // reset the toggle so that the deadband code knows to stop the right motor next time the input is in the deadband range
    DrivetrainRNeedsToBeStopped_Controller1 = true;
  }
  
  // only tell the left drive motor to spin if the values are not in the deadband range
  if (DrivetrainLNeedsToBeStopped_Controller1) {
    LeftDriveSmart.setVelocity(drivetrainLeftSideSpeed, percent);
    LeftDriveSmart.spin(forward);
  }
  // only tell the right drive motor to spin if the values are not in the deadband range
  if (DrivetrainRNeedsToBeStopped_Controller1) {
    RightDriveSmart.setVelocity(drivetrainRightSideSpeed, percent);
    RightDriveSmart.spin(forward);
  }
  // check the ButtonR1/ButtonR2 status to control Arm_Group
  if (Controller1.ButtonR1.pressing()) {
    Arm_Group.spin(forward);
    Controller1RightShoulderControlMotorsStopped = false;
  } else if (Controller1.ButtonR2.pressing()) {
    Arm_Group.spin(reverse);
    Controller1RightShoulderControlMotorsStopped = false;
  } else if (!Controller1RightShoulderControlMotorsStopped) {
    Arm_Group.stop();
    // set the toggle so that we don't constantly tell the motor to stop when the buttons are released
    Controller1RightShoulderControlMotorsStopped = true;
  }
  // check the ButtonUp/ButtonDown status to control Drag
  if (Controller1.ButtonUp.pressing()) {
    Drag.setVelocity(25, percent);
    Drag.spin(forward);
    Controller1UpDownButtonsControlMotorsStopped = false;
  } else if (Controller1.ButtonDown.pressing()) {
    Drag.setVelocity(25, percent);
    Drag.spin(reverse);
    Controller1UpDownButtonsControlMotorsStopped = false;
  } else if (!Controller1UpDownButtonsControlMotorsStopped) {
    Drag.stop();
    // set the toggle so that we don't constantly tell the motor to stop when the buttons are released
    Controller1UpDownButtonsControlMotorsStopped = true;
  }
  // check the ButtonX/ButtonB status to control Lift
  if (Controller1.ButtonX.pressing()) {
    Lift.spin(forward);
    Controller1XBButtonsControlMotorsStopped = false;
  } else if (Controller1.ButtonB.pressing()) {
    Lift.spin(reverse);
    Controller1XBButtonsControlMotorsStopped = false;
  } else if (!Controller1XBButtonsControlMotorsStopped) {
    Lift.stop();
    // set the toggle so that we don't constantly tell the motor to stop when the buttons are released
    Controller1XBButtonsControlMotorsStopped = true;
  }
  if (Controller1.ButtonL2.pressing()) {
        Claw.set(false);
  } 
    else {
        Claw.set(true);
    }


}
// wait before repeating the process
wait(20, msec);

}
return 0;
}
"’

1 Like

Anyone can provide any suggestions please?

I’ve reformatted your code for readability:

// define a task that will handle monitoring inputs from Controller1
int rc_auto_loop_function_Controller1() {
// process the controller input every 20 milliseconds
// update the motors based on the input values
while(true) {
if(RemoteControlCodeEnabled) {
// calculate the drivetrain motor velocities from the controller joystick axies
// left = Axis3
// right = Axis2
int drivetrainLeftSideSpeed = Controller1.Axis3.position();
int drivetrainRightSideSpeed = Controller1.Axis2.position();

  // check if the value is inside of the deadband range
  if (drivetrainLeftSideSpeed < 5 && drivetrainLeftSideSpeed > -5) {
    // check if the left motor has already been stopped
    if (DrivetrainLNeedsToBeStopped_Controller1) {
      // stop the left drive motor
      LeftDriveSmart.stop();
      // tell the code that the left motor has been stopped
      DrivetrainLNeedsToBeStopped_Controller1 = false;
    }
  } else {
    // reset the toggle so that the deadband code knows to stop the left motor nexttime the input is in the deadband range
    DrivetrainLNeedsToBeStopped_Controller1 = true;
  }
  // check if the value is inside of the deadband range
  if (drivetrainRightSideSpeed < 5 && drivetrainRightSideSpeed > -5) {
    // check if the right motor has already been stopped
    if (DrivetrainRNeedsToBeStopped_Controller1) {
      // stop the right drive motor
      RightDriveSmart.stop();
      // tell the code that the right motor has been stopped
      DrivetrainRNeedsToBeStopped_Controller1 = false;
    }
  } else {
    // reset the toggle so that the deadband code knows to stop the right motor next time the input is in the deadband range
    DrivetrainRNeedsToBeStopped_Controller1 = true;
  }
  
  // only tell the left drive motor to spin if the values are not in the deadband range
  if (DrivetrainLNeedsToBeStopped_Controller1) {
    LeftDriveSmart.setVelocity(drivetrainLeftSideSpeed, percent);
    LeftDriveSmart.spin(forward);
  }
  // only tell the right drive motor to spin if the values are not in the deadband range
  if (DrivetrainRNeedsToBeStopped_Controller1) {
    RightDriveSmart.setVelocity(drivetrainRightSideSpeed, percent);
    RightDriveSmart.spin(forward);
  }
  // check the ButtonR1/ButtonR2 status to control Arm_Group
  if (Controller1.ButtonR1.pressing()) {
    Arm_Group.spin(forward);
    Controller1RightShoulderControlMotorsStopped = false;
  } else if (Controller1.ButtonR2.pressing()) {
    Arm_Group.spin(reverse);
    Controller1RightShoulderControlMotorsStopped = false;
  } else if (!Controller1RightShoulderControlMotorsStopped) {
    Arm_Group.stop();
    // set the toggle so that we don't constantly tell the motor to stop when the buttons are released
    Controller1RightShoulderControlMotorsStopped = true;
  }
  // check the ButtonUp/ButtonDown status to control Drag
  if (Controller1.ButtonUp.pressing()) {
    Drag.setVelocity(25, percent);
    Drag.spin(forward);
    Controller1UpDownButtonsControlMotorsStopped = false;
  } else if (Controller1.ButtonDown.pressing()) {
    Drag.setVelocity(25, percent);
    Drag.spin(reverse);
    Controller1UpDownButtonsControlMotorsStopped = false;
  } else if (!Controller1UpDownButtonsControlMotorsStopped) {
    Drag.stop();
    // set the toggle so that we don't constantly tell the motor to stop when the buttons are released
    Controller1UpDownButtonsControlMotorsStopped = true;
  }
  // check the ButtonX/ButtonB status to control Lift
  if (Controller1.ButtonX.pressing()) {
    Lift.spin(forward);
    Controller1XBButtonsControlMotorsStopped = false;
  } else if (Controller1.ButtonB.pressing()) {
    Lift.spin(reverse);
    Controller1XBButtonsControlMotorsStopped = false;
  } else if (!Controller1XBButtonsControlMotorsStopped) {
    Lift.stop();
    // set the toggle so that we don't constantly tell the motor to stop when the buttons are released
    Controller1XBButtonsControlMotorsStopped = true;
  }
  if (Controller1.ButtonL2.pressing()) {
        Claw.set(false);
  } 
    else {
        Claw.set(true);
    }


}
// wait before repeating the process
wait(20, msec);
}
return 0;
}

You’ve only sent a fragment of the code; a task which handles joystick inputs. If you are allowing this task to run during autonomous then it could be causing the behavior you describe. Is there a reason you are using a separate task rather than the standard usercontrol() task?

2 Likes

Sazrocks: I sent you a direct message with codes. Please advise.

Sorry, I’m going through end of semester final exams right now and don’t have time to review your project. I suggest you post it publicly so other forum members can assist you.

1 Like