Announcement

Collapse
No announcement yet.

autonomous with neverest 40 AND pitsco motors

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

  • autonomous with neverest 40 AND pitsco motors

    Rookie Team here:

    We have successful code for making the pitsco motors drive with encoders. We ordered some new Neverrest motors, but are having trouble getting them to do what we want. We want our neverest motors to rotate forward 90 degrees, stop and then rotate back to its original position. Right now, the neveRest will just rotate continuously in one direction.

    thanks for any help!!

    package org.firstinspires.ftc.teamcode;

    import com.qualcomm.robotcore.eventloop.opmode.Disabled;
    import com.qualcomm.robotcore.eventloop.opmode.LinearOpMo de;
    import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
    import com.qualcomm.robotcore.hardware.DcMotor;
    import com.qualcomm.robotcore.util.Range;

    import org.firstinspires.ftc.robotcontroller.external.sam ples.HardwarePushbot;

    @TeleOp(name="TriBotTeleOp")
    @Disabled
    public class TriBotTeleOp extends LinearOpMode {
    DcMotor motorLeft;
    DcMotor motorRight;
    DcMotor motorSlapshot;
    boolean shot = false;
    @Override
    public void runOpMode() {
    double left;
    double right;
    double max;
    motorLeft = hardwareMap.dcMotor.get("motorLeft");
    motorRight = hardwareMap.dcMotor.get("motorRight");
    motorSlapshot = hardwareMap.dcMotor.get("motorSlapshot");
    motorLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCO DER);
    motorRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENC ODER);
    motorSlapshot.setMode(DcMotor.RunMode.STOP_AND_RES ET_ENCODER);
    motorSlapshot.setMode(DcMotor.RunMode.RUN_WITHOUT_ ENCODER);
    telemetry.addData("Say", "I'm waiting for you to PRESS THE BIG TRIANGLE!!!");
    telemetry.update();
    waitForStart();
    while (opModeIsActive()) {
    left = -gamepad1.left_stick_y + gamepad1.right_stick_x;
    right = -gamepad1.left_stick_y - gamepad1.right_stick_x;
    max = Math.max(Math.abs(left), Math.abs(right));
    if (max > 1.0) {
    left /= max;
    right /= max;
    }
    if (gamepad2.right_bumper) {
    Shoot();
    }
    if (gamepad2.left_bumper) {
    Retract();
    }
    motorLeft.setPower(left);
    motorRight.setPower(right);
    idle();
    }
    }
    public void TurnTicks(double power, int distance, DcMotor motor){
    motor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCOD ER);
    motor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
    motor.setTargetPosition(distance);
    motor.setPower(power);
    while(motor.isBusy()&&opModeIsActive()){
    // wait for motor to reach position
    }
    motor.setPower(0);
    motor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCOD ER);
    }
    public void SetPower(double left, double right){
    motorLeft.setPower(left);
    motorRight.setPower(right);

    }
    public void StopDriving(){
    SetPower(0,0);
    }
    public void Shoot(){
    motorSlapshot.setPower(0);
    int startPosition = motorSlapshot.getCurrentPosition();
    motorSlapshot.setPower(1);
    while (motorSlapshot.getCurrentPosition()>startPosition-140) {
    // Waiting...
    }
    motorSlapshot.setPower(0);
    }
    public void Retract(){
    motorSlapshot.setPower(0);
    int startPosition = motorSlapshot.getCurrentPosition();
    motorSlapshot.setPower(-1);
    while(motorSlapshot.getCurrentPosition()<startPosi tion+140){
    // Waiting...
    }
    motorSlapshot.setPower(0);
    }
    }

  • #2
    You want your slapshot motor to run with encoders when using getCurrentPosition(); and without encoders when just running it.

    Comment


    • #3
      So do we want:
      motor.Slapshot.setMode(DcMotor.RunMode.RUN_USING_E NCODER)
      motorSlapshot.setPower(0);
      int startPosition = motorSlapshot.getCurrentPosition();
      motorSlapshot.setPower(-1);
      while(motorSlapshot.getCurrentPosition()<startPosi tion+140){
      // Waiting...
      }

      Comment


      • #4
        So do we want:

        motor.Slapshot.setMode(DcMotor.RunMode.RUN_USING_E NCODER)
        motorSlapshot.setPower(0);
        int startPosition = motorSlapshot.getCurrentPosition();
        motorSlapshot.setPower(-1);
        while(motorSlapshot.getCurrentPosition()<startPosi tion+140){
        // Waiting...
        }

        Comment

        Working...
        X