Announcement

Collapse
No announcement yet.

waitForStart doesn't work

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

  • waitForStart doesn't work

    For our autonomous in java I tried programming on linear with the command waitForStart, reset the run time, tried to not program on linear and made a loop for init and other for start among other things and combinations but still I found the same problem.
    When running a program I have to pressed the init button and the start button at the same time, and this causes trouble with sensors, apparently when I pressed init the robot starts reading the program and when I pressed play it starts moving but not from the beginning of the program
    Don't really have more ideas to solve this problem.

    This is the code of one of my autonomous that doesn't start when is supposed to


    package org.firstinspires.ftc.teamcode.Autonomous;

    import com.qualcomm.robotcore.eventloop.opmode.Autonomous ;
    import com.qualcomm.robotcore.eventloop.opmode.LinearOpMo de;
    import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
    import com.qualcomm.robotcore.eventloop.opmode.Disabled;
    import com.qualcomm.robotcore.hardware.DcMotor;
    import com.qualcomm.robotcore.hardware.DcMotorSimple;
    import com.qualcomm.robotcore.util.ElapsedTime;

    import java.util.Date;

    import static com.qualcomm.analytics.Analytics.getDateFromTime;


    @Autonomous(name="Bluencoders", group="Linear Opmode") // Change to @Autonomous when coding for autonomous


    public class Bluencoders extends LinearOpMode {

    private ElapsedTime runtime = new ElapsedTime();

    DcMotor leftMotor = null;
    DcMotor rightMotor = null;
    private Date time = null;
    DcMotor convey = null;
    DcMotor flipper = null;


    @Override
    public void runOpMode() {
    telemetry.addData("Status", "Initialized");
    telemetry.update();


    flipper = hardwareMap.dcMotor.get("flipper");
    leftMotor = hardwareMap.dcMotor.get("leftMotor");
    rightMotor = hardwareMap.dcMotor.get("rightMotor");
    convey = hardwareMap.dcMotor.get("convey");
    time = new Date();
    int runspeed = (int) 0.3;
    int turnspeed = (int) 0.5;

    flipper.setDirection(DcMotor.Direction.REVERSE);
    flipper.setMode(DcMotor.RunMode.STOP_AND_RESET_ENC ODER);

    rightMotor.setDirection(DcMotor.Direction.REVERSE) ;


    waitForStart();


    // run until the end of the match (driver presses STOP)
    while (opModeIsActive()) {
    telemetry.addData("Status", "Run Time: " + runtime.toString());
    telemetry.update();
    telemetry.addData("Flipper Position", flipper.getCurrentPosition());

    if (new Date().getTime()-time.getTime()<2000){
    leftMotor.setPower(0);
    rightMotor.setPower(0);
    }

    else if (new Date().getTime()-time.getTime()< 4450) {
    leftMotor.setPower(runspeed);
    rightMotor.setPower(runspeed);
    flipper.setMode(DcMotor.RunMode.STOP_AND_RESET_ENC ODER);
    }


    else if (new Date().getTime()-time.getTime()<6500) {
    leftMotor.setPower(0);
    rightMotor.setPower(0);
    flipper.setTargetPosition(3360);

    flipper.setMode(DcMotor.RunMode.RUN_TO_POSITION);

    flipper.setPower(-1);
    }


    else if (new Date().getTime()-time.getTime()< 8000) {
    flipper.setPower(0);
    convey.setPower(-1);
    flipper.setMode(DcMotor.RunMode.STOP_AND_RESET_ENC ODER);
    }

    else if (new Date().getTime()-time.getTime()< 9000) {
    convey.setPower(0);
    flipper.setPower(0);
    flipper.setMode(DcMotor.RunMode.STOP_AND_RESET_ENC ODER);
    }

    else if (new Date().getTime()-time.getTime()<11000) {
    flipper.setTargetPosition(3360);

    flipper.setMode(DcMotor.RunMode.RUN_TO_POSITION);

    flipper.setPower(-1);
    convey.setPower(0);
    }

    else if (new Date().getTime()-time.getTime()< 11200) {
    leftMotor.setPower(runspeed);
    rightMotor.setPower(runspeed);
    }

    else if (new Date().getTime()-time.getTime()<12200) {
    flipper.setPower(0);
    leftMotor.setPower(turnspeed);
    rightMotor.setPower(-turnspeed); }

    else if (new Date().getTime()-time.getTime()<13000) {
    leftMotor.setPower(runspeed);
    rightMotor.setPower(runspeed); }

    else{
    leftMotor.setPower(0);
    rightMotor.setPower(0);}
    }
    }
    }
    Last edited by alcadrone; 12-20-2016, 04:26 PM.

  • #2
    You're going to need to post your code in order to get proper advice.

    Note that for autonomous you're not even allowed to press init and start at the same time. After you press init the beacons are randomized and the referees ensure that the match is ready to start. Only when they say start are you allowed to press start and only start. There might easily be a minute elapsed since you pressed init.

    Edit: Ok, now that you've added code I think I see what the problem was.

    Your use of ElapsedTime

    Code:
    private ElapsedTime runtime = new ElapsedTime();
    This is being called immediately when the class is created. In other words the timer starts ticking right away. I think you want to call reset immediately after start is pressed. This will reset the timer.

    Code:
    waitForStart();
    runtime.reset();
    That should make it work properly. You can then go back and use runtime everywhere you're trying to calculate times manually.
    Last edited by mlwilliams; 12-20-2016, 04:42 PM.

    Comment


    • #3
      Much more than a minute in many cases. Problems with other robots, field issues, venue problems, announcers getting mike happy, etc. It is often several minutes. This makes it imperative that any significant "reset" functions are called immediately after waitForStart (i.e. reset gyro z integrator).

      Comment

      Working...
      X