Announcement

Collapse
No announcement yet.

Replace Seconds With Counts and Add Telemetry HELP

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

  • Replace Seconds With Counts and Add Telemetry HELP

    package org.firstinspires.ftc.robotcontroller.external.sam ples;

    import com.qualcomm.robotcore.eventloop.opmode.LinearOpMo de;
    import com.qualcomm.robotcore.hardware.DcMotor;
    import com.qualcomm.robotcore.hardware.DcMotorController;

    import static org.firstinspires.ftc.robotcontroller.external.sam ples.PushbotAutoDriveByEncoder_Linear.DRIVE_SPEED;

    /**
    * Created by melko on 11/11/2016.
    */

    public class backupaut extends LinearOpMode {
    DcMotor rightMotor;
    DcMotor leftMotor;
    final static int ENCODER_CPR = 1120; //Encoder counts per revolution
    final static double GEAR_RATIO = 2; //Gear rates
    final static double WHEEL_DIAMETER = 4;
    final static int DISTANCE = 74; //Distance in inches to drive

    final static double CIRCUMFERENCE = Math.PI * WHEEL_DIAMETER;

    public void m_move(double leftpower, double rightpower, int seconds) throws InterruptedException {


    rightMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENC ODER);
    leftMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCO DER);

    leftMotor.setPower(leftpower);
    rightMotor.setPower(rightpower);


    sleep(seconds);
    }

    @Override
    public void runOpMode() throws InterruptedException {
    leftMotor = hardwareMap.dcMotor.get("leftDriveM");
    rightMotor = hardwareMap.dcMotor.get("rightDriveM");
    leftMotor.setDirection(DcMotor.Direction.REVERSE);


    rightMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ ENCODER);
    leftMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_E NCODER);
    /*
    * Initialize the drive system variables.
    * The init() method of the hardware class does all the work here
    */


    // Send telemetry message to signify robot waiting;

    waitForStart();
    if (true == true) {
    m_move(-.3, -.3, 2000);
    m_move(0, 0, 500);
    m_move(.3, -.3, 2200);
    }
    }

    public int m_encoders(int distance) {
    double rotation = distance / CIRCUMFERENCE;
    double counts = ENCODER_CPR * rotation * GEAR_RATIO;

    rightMotor.setTargetPosition((int) counts);
    leftMotor.setTargetPosition((int) counts);

    rightMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION );
    leftMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION) ;

    rightMotor.setPower(-.3);
    leftMotor.setPower(-.3);

    //int arrived = 0;

    while (Math.abs(rightMotor.getCurrentPosition()) < Math.abs(counts)) {
    //sweeperMotor.setPower(1);
    leftMotor.setPower(-.3);
    rightMotor.setPower(-.3);
    telemetry.addData("Motor Target", counts);
    telemetry.addData("Left Position", rightMotor.getCurrentPosition());
    telemetry.addData("Right Position", leftMotor.getCurrentPosition());
    }
    return 0;
    }

    }

    PS
    The if statement works, but doesn't go into the public int. Thus, leading to no telemetry on the phone. Help much appreciated.
    Thanks,
    Gamer232423

  • #2
    Not exactly sure what the question is, but when using RUN_TO_POSITION, the speed passed to setPower should be positive.
    If you want to go backwards, set a target lower than the getCurrentPosition (target can be negative if getCurrentPosition is 0).

    Comment

    Working...
    X