Announcement

Collapse
No announcement yet.

Autonomous help

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Autonomous help

    So, I have an autonomous program that kind of works, but what I haven't been able to figure out is how to get the robot to move at a certain power for a set amount of time. Here is my full code:


    package org.ftc.one_one_four_nine_six;
    import com.qualcomm.robotcore.eventloop.opmode.Disabled;
    import com.qualcomm.robotcore.eventloop.opmode.OpMode;
    import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
    import com.qualcomm.robotcore.hardware.DcMotor;
    import com.qualcomm.robotcore.hardware.ColorSensor;

    @TeleOp(name ="Blue color test", group ="Auto")
    public class Blue_NoRamp extends OpMode{

    DcMotor left_drive;
    DcMotor right_drive;
    ColorSensor color;
    //Add Servo here for button push
    public void init()
    {
    color = hardwareMap.colorSensor.get("color");
    color.enableLed(true);
    }
    public void loop()
    {
    left_drive.setPower(1);
    right_drive.setPower(1);
    try {
    Thread.sleep(500);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    telemetry.addData ("Blue",color.blue());
    if (color.blue() < 20){
    left_drive.setPower(0);
    right_drive.setPower(0);
    } else {
    left_drive.setPower(0.5);
    right_drive.setPower(0.5);}
    }

    }

    As you can see, I have a Try/Catch statement for Thread.Sleep(500) which should, (according to what I have read) make the robot go straight for half a second. It doesn't. I have tried sleep(500) but I couldn't import the correct statement. It says to import java.lang.sleep? and too many choices. I've imported this in the past to no avail. It has too many problems, such as the robot moving one motor then the other, and back and forth. Is there something that I am just missing? Also, whats a better way to check sensors while the robot is going straight? Others have said using the sleep method is bad while checking sensors. I've been stuck on this for a while and I can't grasp it. Any and all help would be appreciated.
    -JavaCrash, Programmer for 11496.

    “I am not a product of my circumstances. I am a product of my decisions.” - Stephen Covey

  • #2
    Thread.sleep won't work because you are using an OpMode not a LinearOpMode
    sleep is not available because you are using an OpMode not a LinearOpMode

    The method of programming you are attempting to use will not work because you are using an OpMode not a LinearOpMode.

    Long story short: Use a LinearOpMode if you expect linear execution.

    Comment


    • #3
      It is easy to convert, but your code is a TeleOp and not an Auton.

      You are using an iterative OpMode. You don't want to have a sleep in the loop for an iterative opmode. You can do this in a LinearOpMode without problem, but in the iterative version, you want to act on saved state for a short period of time, update state and let go of control.
      Switch to a linear opmode or remove the sleep and start a timer on entry to a new STATE. Check if its value has exceeded a target each time through the loop - this could be the condition for proceeding to the next state.

      Comment


      • #4
        Originally posted by FTC4160 View Post
        Thread.sleep won't work because you are using an OpMode not a LinearOpMode
        sleep is not available because you are using an OpMode not a LinearOpMode

        The method of programming you are attempting to use will not work because you are using an OpMode not a LinearOpMode.

        Long story short: Use a LinearOpMode if you expect linear execution.

        Okay, so how would I change it? Is it as simple as changing the public class line from "OpMode" to "LinearOpMode"
        -JavaCrash, Programmer for 11496.

        “I am not a product of my circumstances. I am a product of my decisions.” - Stephen Covey

        Comment


        • #5
          No, because you have the loop method. Look at the linear opmode examples. There are examples for linear opmode with encoders. You can use time as the transition trigger as well.

          Comment


          • #6
            Originally posted by FTC7253 View Post
            No, because you have the loop method. Look at the linear opmode examples. There are examples for linear opmode with encoders. You can use time as the transition trigger as well.
            So, like this right?

            package org.ftc.one_one_four_nine_six;
            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.hardware.ColorSensor;

            @TeleOp(name ="Blue color test", group ="Auto")
            public class Blue_NoRamp extends LinearOpMode{

            DcMotor left_drive;
            DcMotor right_drive;
            ColorSensor color;
            //Add Servo here for button push
            @Override
            public void runOpMode() throws InterruptedException {
            color = hardwareMap.colorSensor.get("color");
            color.enableLed(true);
            left_drive = hardwareMap.dcMotor.get("left");
            right_drive = hardwareMap.dcMotor.get("right");
            waitForStart();
            left_drive.setPower(1);
            right_drive.setPower(1);
            sleep(500);
            telemetry.addData ("Blue",color.blue());
            if (color.blue() < 20){
            left_drive.setPower(0);
            right_drive.setPower(0);
            } else {
            left_drive.setPower(0.5);
            right_drive.setPower(0.5);}
            }

            }
            -JavaCrash, Programmer for 11496.

            “I am not a product of my circumstances. I am a product of my decisions.” - Stephen Covey

            Comment


            • #7
              Originally posted by JavaCrash View Post
              So, like this right?
              That looks right, but its really hard to read because there isn't any indentation

              Comment


              • #8
                Yeah that's my fault. It does work. Many many thanks for the help.
                -JavaCrash, Programmer for 11496.

                “I am not a product of my circumstances. I am a product of my decisions.” - Stephen Covey

                Comment

                Working...
                X