Go to Post Keep arrogant, belittling and misspelled bragging off these boards. - Mike [more]
Home
Go Back   Chief Delphi > Other > FIRST Tech Challenge
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #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
  #2   Spotlight this post!  
Unread 13-12-2015, 22:12
whereisthemonke whereisthemonke is offline
Registered User
FTC #4602
 
Join Date: Dec 2015
Location: Germany
Posts: 1
whereisthemonke is an unknown quantity at this point
Re: [FTC]: [FTC]: Autonomous-run motor with encoders does not stop

Hey, i would use the following code:

PHP Code:
public class CCAutonomous extends LinearOpMode {
        
OpticalDistanceSensor opticalDistanceSensor;
        
//Drive motors
        
DcMotor motorFrontRight,motorFrontLeftmotorBackRightmotorBackLeft;
        
int leftFrontPosleftBackPosrightFrontPosrightBackPos;

        @
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);

            
leftFrontPos motorLeftFront.getCurrentPosition();
            
leftBackPos motorLeftBack.getCurrentPosition();
            
rightFrontPos motorFrontRight.getCurrentPosition();
            
rightBackPos motorBackRight.getCurrentPosition();

            
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);

            while(
leftBackPos 2440 && leftFrontPos 2440 && rightBackPos 2440 && rightFrontPos 2440){
                
motorFrontLeft.setPower(-0.5);
                
motorFrontRight.setPower(-0.5);
                
motorBackLeft.setPower(-0.5);
                
motorBackRight.setPower(-0.5);

                
leftFrontPos motorLeftFront.getCurrentPosition();
                
leftBackPos motorLeftBack.getCurrentPosition();
                
rightFrontPos motorFrontRight.getCurrentPosition();
                
rightBackPos motorBackRight.getCurrentPosition();
            }

            
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()));
        }
    } 
Use this code instead and tell me if it worked, I will use this code too if you confirm that it worked
Reply With Quote
  #3   Spotlight this post!  
Unread 14-12-2015, 15:12
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
Re: [FTC]: [FTC]: Autonomous-run motor with encoders does not stop

We got around the original issue by setting the motor power to 0 after the Targetposition is reached. We also had an another issue with the condition performing the "and" condition on all 4 motors to check if the target position is reached. Two of the motors where always at zero position so we modified the condition to just check of the front set of wheels (which were the ones with the encoders returning the right values)
__________________
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
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 17:10.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi