Announcement

Collapse
No announcement yet.

changing buttons on the game pad

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

  • changing buttons on the game pad

    Is there a way to change:

    public float left_trigger = 0f;

    to :

    public boolean left_trigger = false

    the file gamepad.java will not allow us to make changes?

  • #2
    The left trigger is an analogue value (0.0-1.0), not a boolean one. If you wish to use it as a condition in a code, you should compare it to another value.

    For example,
    Code:
    if( gamepad1.left_trigger > 0.5 ){
      // do something because the left trigger was pressed more than halfway down
    }

    Comment


    • #3
      We were trying to figure out a way to control each servo independently by using the left bumper and trigger for the left.claw and the right side for the right claw but we simply cant get it to work.

      Comment


      • #4
        If I'm understanding your intent this is all you need:

        Code:
        if (gamepad1.left_bumper) leftClaw.setPosition(gamepad1.left_trigger);
        if (gamepad1.right_bumper) rightClaw.setPosition(gamepad1.right_trigger);
        If you're pressing the left bumper then the left claw servo will be set to the current position of the left trigger. When you let go of the bumper the servo will stay at its current position and squeezing the left trigger will do nothing.

        All of the above would work identically on the right side.

        Comment


        • #5
          What we are trying to figure out is how to manipulate the current code :

          // Use gamepad left & right Bumpers to open and close the claw
          if (gamepad2.right_bumper)
          clawOffset += CLAW_SPEED;
          else if (gamepad2.left_bumper)
          clawOffset -= CLAW_SPEED;

          To control two separate servos. We would like the left bummer to move the left servo to a position (.8) when pressed, then have the left trigger move the left servo back to its original position. The code has the triggers as float values, not booleans and we haven't figured out how to change that.

          Comment


          • #6
            As I said before, you need to compare the value to a number. Comparison operators return boolean values.

            Code:
            boolean isLeftTriggerPressed = gamepad2.left_trigger > 0.5;

            Comment


            • #7
              Originally posted by thensley View Post
              What we are trying to figure out is how to manipulate the current code :

              Code:
              // Use gamepad left & right Bumpers to open and close the claw
                      if (gamepad2.right_bumper)
                          clawOffset += CLAW_SPEED;
                      else if (gamepad2.left_bumper)
                          clawOffset -= CLAW_SPEED;
              To control two separate servos. We would like the left bummer to move the left servo to a position (.8) when pressed, then have the left trigger move the left servo back to its original position. The code has the triggers as float values, not booleans and we haven't figured out how to change that.
              To convert a float into a boolean you need to compare it with something. That comparison will return a boolean...

              Code:
              if (gamepad1.left_bumper)
                leftClaw.setPosition(0.8)
              else if (gamepad.left_trigger > 0.5)
                leftClaw.setPosition(0.0)

              Comment

              Working...
              X