Announcement

Collapse
No announcement yet.

TeleOp doesn't immediately start

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

  • TeleOp doesn't immediately start

    For some reason, it takes a while for the gamepad controls to work and it works when the dashboard display comes up with the line numbers (0,1,2,3 ...). Does anyone know why this happens?

    Code:
    /*
     * Lockdown Framework Library
     * Copyright (c) 2015 Lockdown Team 8564 (lockdown8564.weebly.com)
     *
     * Permission is hereby granted, free of charge, to any person obtaining a copy
     * of this software and associated documentation files (the "Software"), to deal
     * in the Software without restriction, including without limitation the rights
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     * copies of the Software, and to permit persons to whom the Software is
     * furnished to do so, subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be included in all
     * copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     * SOFTWARE.
     */
    
    package ftc8564opMode;
    
    import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
    import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
    import ftc8564lib.Robot;
    
    @TeleOp(name="LockdownTeleOp", group="TeleOp")
    public class LockdownTeleOp extends LinearOpMode {
    
        Robot robot;
    
        @Override
        public void runOpMode() throws InterruptedException {
            robot = new Robot(this);
            robot.driveBase.constantSpeed();
            waitForStart();
            while (opModeIsActive()) {
                // Drive Train command
                robot.driveBase.tankDrive(gamepad1.left_stick_y, gamepad1.right_stick_y);
                robot.PulleySystem.setPower(gamepad2.left_stick_y);
            } // end of if gamepad1.back not pressed
    
        }
    }

  • #2
    Originally posted by FTC8564 View Post
    For some reason, it takes a while for the gamepad controls to work and it works when the dashboard display comes up with the line numbers (0,1,2,3 ...). Does anyone know why this happens?

    Code:
    /*
     * Lockdown Framework Library
     * Copyright (c) 2015 Lockdown Team 8564 (lockdown8564.weebly.com)
     *
     * Permission is hereby granted, free of charge, to any person obtaining a copy
     * of this software and associated documentation files (the "Software"), to deal
     * in the Software without restriction, including without limitation the rights
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     * copies of the Software, and to permit persons to whom the Software is
     * furnished to do so, subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be included in all
     * copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     * SOFTWARE.
     */
    
    package ftc8564opMode;
    
    import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
    import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
    import ftc8564lib.Robot;
    
    @TeleOp(name="LockdownTeleOp", group="TeleOp")
    public class LockdownTeleOp extends LinearOpMode {
    
        Robot robot;
    
        @Override
        public void runOpMode() throws InterruptedException {
            robot = new Robot(this);
            robot.driveBase.constantSpeed();
            waitForStart();
            while (opModeIsActive()) {
                // Drive Train command
                robot.driveBase.tankDrive(gamepad1.left_stick_y, gamepad1.right_stick_y);
                robot.PulleySystem.setPower(gamepad2.left_stick_y);
            } // end of if gamepad1.back not pressed
    
        }
    }
    Should you be calling an init() method in the Robot object to setup all your motors etc?

    Also, the telemetry must be coming from driveBase or pullySystem, and we can't see that code.

    Comment


    • #3
      The init should be within the driveBase class and pulleySystem class. I can post the robot object and the respective classes.

      Robot
      Code:
      package ftc8564lib;
      
      import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
      import hallib.*;
      
      public class Robot {
      
          private static HalDashboard dashboard = null;
          public DriveBase driveBase = null;
          public PulleySystem PulleySystem = null;
      
          public Robot(LinearOpMode opMode) throws InterruptedException {
              driveBase = new DriveBase(opMode);
              PulleySystem = new PulleySystem(opMode);
              dashboard = new HalDashboard(opMode.telemetry);
          }
      
          public static HalDashboard getDashboard() {
              return dashboard;
          }
      
      }
      DriveBase init
      Code:
      public DriveBase(LinearOpMode opMode) throws InterruptedException {
              this.opMode = opMode;
              rightMotor = opMode.hardwareMap.dcMotor.get("rightMotor");
              rightMotor.setDirection(DcMotor.Direction.REVERSE);
              leftMotor = opMode.hardwareMap.dcMotor.get("leftMotor");
              leftMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
              rightMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
              leftMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
              rightMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
              gyroSensor = (ModernRoboticsI2cGyro)opMode.hardwareMap.gyroSensor.get("gyro");
              mRunTime.reset();
              gyroSensor.calibrate();
              while(gyroSensor.isCalibrating()) {
                 Thread.sleep(50);
                  opMode.idle();
              }
              //Sets up PID Drive: kP, kI, kD, kF, Tolerance, Settling Time
              pidControl = new PIDControl(0.03,0,0.011,0,2.0,0.2,this);
              pidControlTurn = new PIDControl(0.05,0,0,0,2.0,0.2,this);
              odsLeft = opMode.hardwareMap.opticalDistanceSensor.get("odsLeft");
              odsRight = opMode.hardwareMap.opticalDistanceSensor.get("odsRight");
          }
      PulleySystem init
      Code:
      public PulleySystem(LinearOpMode opMode) {
              leftPulley = opMode.hardwareMap.dcMotor.get("leftPulley");
              rightPulley = opMode.hardwareMap.dcMotor.get("rightPulley");
          }

      Comment


      • #4
        I don't include any telemetry in any of the subsystem classes at all so I'm a bit lost as to where the telemetry would be coming from

        Comment


        • #5
          You're using a class called HalDashboard which appears to be some 3rd party thing that many people here might not be familiar with. It takes telemetry as a parameter to the constructor so clearly it wants to send telemetry output.

          Comment


          • #6
            HalDashboard is apparently from the TRC package; see https://github.com/trc492/FtcSamples...Dashboard.java . The constructor for the HalDashboard object includes this snippet, which shows where the line number prefix comes from:

            Code:
                    for (int i = 0; i < display.length; i++)
                    {
                        display[i] = telemetry.addData(String.format(displayKeyFormat, i), "");
                    }
                    telemetry.update();
            it takes a while for the gamepad controls to work
            How long is the delay after the Start button is pushed before the game pad's control's start to work?
            John McDonnell
            Co-Mentor, Team 5873
            https://www.facebook.com/Team5873

            Comment


            • #7
              Originally posted by JohnMcDonnell View Post
              HalDashboard is apparently from the TRC package; see https://github.com/trc492/FtcSamples...Dashboard.java . The constructor for the HalDashboard object includes this snippet, which shows where the line number prefix comes from:

              Code:
                      for (int i = 0; i < display.length; i++)
                      {
                          display[i] = telemetry.addData(String.format(displayKeyFormat, i), "");
                      }
                      telemetry.update();


              How long is the delay after the Start button is pushed before the game pad's control's start to work?
              It usually is around 5 sec but sometimes I just press a bunch of the buttons and I see the telemetry on the DS.

              Comment


              • #8
                Originally posted by FTC8564 View Post
                It usually is around 5 sec but sometimes I just press a bunch of the buttons and I see the telemetry on the DS.
                Your driveBase initialization is doing a gyro calibration, which can take several seconds.
                So your Robot won't actually start running until the cal is complete.

                Code:
                       leftMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);   <<< Not having any effect since it's followed by a reset encoder
                        rightMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER); <<< Not having any effect since it's followed by a reset encoder
                        leftMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
                        rightMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
                        gyroSensor = (ModernRoboticsI2cGyro)opMode.hardwareMap.gyroSensor.get("gyro");
                        mRunTime.reset();
                        gyroSensor.calibrate();
                        while(gyroSensor.isCalibrating()) {
                           Thread.sleep(50);
                            opMode.idle();
                        }
                I suggest putting a telemetry statement before the cal is started (eg: "Calibrating Gyro... Do NOT move robot"), and then another message after it's done.

                Comment


                • #9
                  Like PhilBot said, you have a gyro calibration loop in the DriveBase constructor, so nothing will respond while you are calibrating. Is that the delay you are describing? However, DriveBase is instantiated in the Robot constructor and Robot is instantiated before waitForStart(). So there is nothing unusual here. I don't expect the gamepads will be functional before waitForStart() has returned anyway. So I doubt that is what you are complaining about. Would you describe what behavior you are expecting and what is the actual behavior you are seeing?

                  Comment


                  • #10
                    Originally posted by mikets View Post
                    Like PhilBot said, you have a gyro calibration loop in the DriveBase constructor, so nothing will respond while you are calibrating. Is that the delay you are describing? However, DriveBase is instantiated in the Robot constructor and Robot is instantiated before waitForStart(). So there is nothing unusual here. I don't expect the gamepads will be functional before waitForStart() has returned anyway. So I doubt that is what you are complaining about. Would you describe what behavior you are expecting and what is the actual behavior you are seeing?
                    However, with linearOpmode, the the Driver station can transition from init to start before the RC has actually completed the init process.
                    So, it may "look" like the robot should be running, (since you hit the start button) but the RC code may still be calibrating.

                    This happens if you press init and then quickly follow with start.
                    With the added diagnostic messages "calibrating" and then "Calibrated" it's clear to see when you really can expect the robot to run.

                    Comment


                    • #11
                      Ah ok. Thanks for your help! Since I don't intend to use gyro in TeleOp, would I pass in a boolean to see whether or not I should calibrate?

                      Comment


                      • #12
                        Originally posted by FTC8564 View Post
                        Ah ok. Thanks for your help! Since I don't intend to use gyro in TeleOp, would I pass in a boolean to see whether or not I should calibrate?
                        Yes, if you don't need the gyro, then there is no need to calibrate the gyro. Skipping it at least will tell you if it is indeed the culprit.

                        Comment

                        Working...
                        X