Announcement

Collapse
No announcement yet.

Making an action stop in teleop

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

  • Making an action stop in teleop

    During competition last week we ran into an issue where I pressed a button twice on accident and the whole robot stopped. So I was wondering if there was a way to combat this issue.

  • #2
    You're going to have to provide a lot more information in order for us to help you. To start, please post your code to a GitHub Gist.

    Comment


    • #3
      Originally posted by 4634 Programmer View Post
      You're going to have to provide a lot more information in order for us to help you. To start, please post your code to a GitHub Gist.
      Here's the code and the issue is when we activated the gripMove method. Also I forgot to add that we thought it might be from the encoder being blocked and not being able to reach it's position
      Code:
      package org.firstinspires.ftc.teamcode;
      
      import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
      import com.qualcomm.robotcore.hardware.Servo;
      import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
      import com.qualcomm.robotcore.hardware.DcMotorSimple;
      import com.qualcomm.robotcore.hardware.DcMotor;
      
      @TeleOp (name = "TeleOp")
      public class Control extends LinearOpMode 
      {
      
          public DcMotor frontLeft; 
          public DcMotor backLeft;
          public DcMotor frontRight;
          public DcMotor backRight;
      
          public DcMotor armMotor; 
          public DcMotor cubeGrip;
      
          public DcMotor idolArm;
          public Servo clawServo;
      
          public Servo pullServo;
      
      
          public void runOpMode()
      
          {
              backRight = hardwareMap.dcMotor.get("backRightDrive");
              backLeft = hardwareMap.dcMotor.get("backLeftDrive");
              frontRight = hardwareMap.dcMotor.get("frontRightDrive");
              frontLeft = hardwareMap.dcMotor.get("frontLeftDrive");
      
              armMotor = hardwareMap.dcMotor.get("armMotor");
              cubeGrip = hardwareMap.dcMotor.get("cubeGrip");
      
              idolArm = hardwareMap.dcMotor.get("IdolArmMotor");
              clawServo = hardwareMap.servo.get("clawServo");
      
              pullServo = hardwareMap.servo.get("pullServo");
      
              cubeGrip.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
              cubeGrip.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
      
              waitForStart();
      
              while(opModeIsActive()){
      
              backLeft.setPower(gamepad1.left_stick_y);
              frontLeft.setPower(gamepad1.left_stick_y);
              backRight.setPower(-gamepad1.right_stick_y);
              frontRight.setPower(-gamepad1.right_stick_y);
      
              idolArm.setPower(gamepad2.left_stick_y);
      
              armMotor.setPower(gamepad2.right_stick_y);
      
              while (gamepad1.dpad_left)
              {
                  strafeLeft(1);
              }
      
              while(gamepad1.dpad_right)
              {
                  strafeRight(1);
              }
      
              if (gamepad2.b) { //close
      
                  gripMove(1, -1680);
      
              }
      
              if (gamepad2.a) { //open
      
                  gripMove(1, 1680);
      
              }
      
              if(gamepad2.x)
              {
                  clawServo.setPosition(0.6);
              }
      
              if(gamepad2.y)
              {
                  clawServo.setPosition(0.8);
              }
      
              if(gamepad1.left_bumper)
              {
                  PullServo(0.30);
              }
      
              }
          }
      
      
          public void strafeLeft(double power)
          {
              backLeft.setPower(-power);
              frontLeft.setPower(power);
              backRight.setPower(-power);
              frontRight.setPower(power);
          }
      
          public void strafeRight(double power)
          {
              backLeft.setPower(power);
              frontLeft.setPower(-power);
              backRight.setPower(power);
              frontRight.setPower(-power);
          }
      
      
          public void gripMove(double power, int distance)
          {
              cubeGrip.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
              cubeGrip.setMode(DcMotor.RunMode.RUN_TO_POSITION);
      
              cubeGrip.setTargetPosition(distance);
              cubeGrip.setPower(power);
      
              while(opModeIsActive() && cubeGrip.isBusy())
              {
                  telemetry.addData("Grip", "Position",
                          cubeGrip.getCurrentPosition());
                  telemetry.update();
              }
      
              cubeGrip.setPower(0);
      
              cubeGrip.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
          }
      
          public void PullServo(double position)
          {
              pullServo.setPosition(position);
          }
      
      
      
      
      
      
      
      }

      Comment


      • #4
        > Also I forgot to add that we thought it might be from the encoder being blocked and not being able to reach it's position

        That would explain your problem. The 'while' loop in gripMove will keep looping until the motor is not busy or the op mode stops. Assuming you weren't touching the joysticks, the robot will stop. You don't need the while loop in this method at all. You can just move the telemetry code inside the while(opModeIsActive() loop.

        Also, you need to be careful with 'while (gamepad1.dpad_XXX)' loops, because if you hold the dpad for more than 5 seconds, the opmode will throw a 'stuck in loop' error. I think you put these 'while dpad' loops in there to avoid setting the power twice to the drive motors during the same iteration of the while(opModeIsActive() loop. But if this is your goal, a better way is to use some variables for holding the proposed power, then call setPower once for each motor after getting all the inputs and figuring out what you want the motors to do.

        John McDonnell
        Co-Mentor, Team 5873
        https://www.facebook.com/Team5873

        Comment


        • #5
          Originally posted by 8129_Aidan View Post

          Here's the code and the issue is when we activated the gripMove method. Also I forgot to add that we thought it might be from the encoder being blocked and not being able to reach it's position
          Code:
          package org.firstinspires.ftc.teamcode;
          
          import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
          import com.qualcomm.robotcore.hardware.Servo;
          import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
          import com.qualcomm.robotcore.hardware.DcMotorSimple;
          import com.qualcomm.robotcore.hardware.DcMotor;
          
          @TeleOp (name = "TeleOp")
          public class Control extends LinearOpMode
          I would not recommend using LinearOpMode for TeleOp
          Mark Hancock
          Tigard Team Mentor

          Comment


          • #6
            It seems that your problem is fixed, but I wonder how your Tank Drive works. The way you've programmed it you press dpad to strafe. Also, while using the joysticks the motors should each other. Now, I don't know how robot looks so I could be wrong. Here's some code that will make the whole driving thing for you easier. First, you need to set both right motors to REVERSE. Also the code needs to be slightly revised. We originally found this code from dmssargent in https://ftcforum.usfirst.org/forum/f...e-code-example

            Code:
             
             double r = Math.hypot(gamepad1.left_stick_x, gamepad1.left_stick_y);  double robotAngle = Math.atan2(gamepad1.left_stick_y, gamepad1.left_stick_x) - Math.PI / 4;  double rightX = gamepad1.right_stick_x;  final double v1 = r * Math.cos(robotAngle) + rightX;  final double v2 = r * Math.sin(robotAngle) - rightX;  final double v3 = r * Math.sin(robotAngle) + rightX;  final double v4 = r * Math.cos(robotAngle) - rightX;     leftFront.setPower(v1);  rightFront.setPower(v2);  leftRear.setPower(v3)  rightRear.setPower(v4);
            I hope it works for you!

            Comment

            Working...
            X