Announcement

Collapse
No announcement yet.

Help With Programming

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help With Programming

    We are running into the issue of have enough right and left sticks on the gamepad to drive our motors. We tried to run the motor via a trigger, but it is very jittery and slow. So we then though we could do the following:

    boolean bPrevState = false;
    boolean bCurrState = false;

    bCurrState = gamepad2.x;

    if ((bCurrState == false) && (bPrevState == bCurrState || bPrevState ==true )){

    lgrip = gamepad2.left_stick_y;
    rgrip = gamepad2.right_stick_y;
    robot.rightGrip.setPower(rgrip);
    robot.leftGrip.setPower(-lgrip);

    bPrevState = false;

    }

    else if ((bCurrState == true) && (bCurrState != bPrevState)) {

    // button is transitioning to a pressed state. So Toggle between gripper control and winch

    winchup = -gamepad2.right_stick_y;
    robot.winch.setPower(winchup);
    robot.winch.setPower(winchdown);
    bPrevState = true;

    }


    We thought this would set our controls so that a press of the x button on gamepad 2 would change the motor that the left and right stick control. However, we can only run the winch motor if the x button is being held down, and again the motor then runs very jittery. We are rookies, and none of us really have programming experience, just trying to modify the sample code. This is the pushbotteleop tank_iterative, if that helps. Any help would be much appreciated. Thank you.

  • #2
    You really should use buttons for at least one of these. This solution is unnecessarily complicated. To program with a button, you should be doing something like this:

    if (gamepad2.a) {
    motor.setPower(1);
    } else {
    motor.setPower(0)
    }

    Comment


    • #3
      Originally posted by willtri4 View Post
      You really should use buttons for at least one of these. This solution is unnecessarily complicated. To program with a button, you should be doing something like this:

      if (gamepad2.a) {
      motor.setPower(1);
      } else {
      motor.setPower(0)
      }
      thank you for your feedback, we will definitely go with that if we can not figure out something that is inutitive to start and stop. i appreciate your feedback.

      Comment


      • #4
        boolean runWinch = false;
        boolean runGripper = true;

        if (gamepad2.a){

        runWinch = true;
        runGripper = false;
        }

        if (gamepad2.b) {
        runWinch = false;
        runGripper = true;

        }

        if (runWinch == true && runGripper == false){

        winchup = gamepad2.left_stick_y;
        // winchdown =gamepad2.left_stick_y;
        robot.winch.setPower(winchup);
        // robot.winch.setPower(winchdown);

        }

        if (runGripper==true && runWinch == false) {
        lgrip = gamepad2.left_stick_y;
        rgrip = gamepad2.right_stick_y;
        robot.rightGrip.setPower(rgrip);
        robot.leftGrip.setPower(-lgrip);
        }
        this seems to work a bit better, but we have to hold the "a" button in order to run the winch. is there a way to change the boolean value and have it remain even when you release the button? thank you.

        Comment


        • #5
          You have to 'cache' the button's state and toggle a second variable. Your original code's issue was that your "cache" variables were inside the loop method and therefore being set to false all the time.

          Comment


          • #6
            If you describe the specific features of your robot, we may be able to provide more specific advice as to how to implement your controls. Generally, things that have a binary state (on vs off, or position 1 vs position 2) or move to a variable speed or position but hold their state until commanded otherwise tend to work well on buttons, and things that need to vary continuously but have a return to 'zero' (in either speed or position, like motor speed/drivetrain) tend to work better on the joysticks. You have at least twelve button-like functions and two pairs of xy joystick functions to work with.

            Comment

            Working...
            X