View Single Post
  #1   Spotlight this post!  
Unread 08-12-2015, 18:42
FRC Team CC FRC Team CC is offline
Registered User
FRC #6560 (Charging Champions)
 
Join Date: Sep 2014
Rookie Year: 2012
Location: Southern California
Posts: 102
FRC Team CC is an unknown quantity at this point
[FTC]: [FTC]: Autonomous-run motor with encoders does not stop

We are trying write an autonomous program to drive the robot a specified distance. we have connected encoders to our 4 drive motors and here is the code we have so far :
Code:
public class CCAutonomous extends LinearOpMode {
    OpticalDistanceSensor opticalDistanceSensor;
    //Drive motors
    DcMotor motorFrontRight,motorFrontLeft, motorBackRight, motorBackLeft;

    @Override
    public void runOpMode() throws InterruptedException {

       // opticalDistanceSensor = hardwareMap.opticalDistanceSensor.get("sensor_ods");

        motorFrontRight = hardwareMap.dcMotor.get("front_right");
        motorFrontLeft = hardwareMap.dcMotor.get("front_left");
        motorBackRight = hardwareMap.dcMotor.get("back_right");
        motorBackLeft = hardwareMap.dcMotor.get("back_left");

        motorFrontLeft.setDirection(DcMotor.Direction.REVERSE);
        motorBackLeft.setDirection(DcMotor.Direction.REVERSE);
        motorFrontRight.setMode(DcMotorController.RunMode.RUN_USING_ENCODERS);
        motorFrontLeft.setMode(DcMotorController.RunMode.RUN_USING_ENCODERS);
        motorBackRight.setMode(DcMotorController.RunMode.RUN_USING_ENCODERS);
        motorBackLeft.setMode(DcMotorController.RunMode.RUN_USING_ENCODERS);
        waitForStart();
        // Reset enoders to zero
        motorFrontLeft.setMode(DcMotorController.RunMode.RESET_ENCODERS);
        motorFrontRight.setMode(DcMotorController.RunMode.RESET_ENCODERS);
        motorBackLeft.setMode(DcMotorController.RunMode.RESET_ENCODERS);
        motorBackRight.setMode(DcMotorController.RunMode.RESET_ENCODERS);
        waitOneFullHardwareCycle(); // We use these in attempt to gain stability.


        motorFrontLeft.setTargetPosition(2440);
        motorFrontRight.setTargetPosition(2440);
        motorBackLeft.setTargetPosition(2440);
        motorBackRight.setTargetPosition(2440);

        motorFrontRight.setMode(DcMotorController.RunMode.RUN_TO_POSITION);
        motorFrontLeft.setMode(DcMotorController.RunMode.RUN_TO_POSITION);
        motorBackRight.setMode(DcMotorController.RunMode.RUN_TO_POSITION);
        motorBackLeft.setMode(DcMotorController.RunMode.RUN_TO_POSITION);
        motorFrontLeft.setPower(-0.5);
        motorFrontRight.setPower(-0.5);
        motorBackLeft.setPower(-0.5);
        motorBackRight.setPower(-0.5);

        telemetry.addData("2 ", "motorFrontLeft:  " + String.format("%d", motorFrontLeft.getTargetPosition()));
        telemetry.addData("3 ", "motorFrontRight:  " + String.format("%d", motorFrontRight.getTargetPosition()));
        telemetry.addData("4 ", "motorBackLeft:  " + String.format("%d", motorBackLeft.getTargetPosition()));
        telemetry.addData("5 ", "motorBackRight:  " + String.format("%d", motorBackRight.getTargetPosition()));
    }
}
With the power set to -0.5, the robot keeps moving and does not stop. How do we stop the robot after moving specified distance.

thanks
Charging Champions
Team 8660
__________________
The Charging Champions
FTC Team #8660
Facebook Page: https://www.facebook.com/chargingchampions
Follow us on Twitter: @FtcTeamCC
Google Plus: https://plus.google.com/112552147224383900922/posts
Youtube channel: https://www.youtube.com/channel/UCop...G3zsvQKCXF4ESQ
Blog: http://chargingchampionsblog.blogspot.com/
Reply With Quote