Announcement

Collapse
No announcement yet.

Setting motor Velocity in Blocks crashes at runtime

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

  • Setting motor Velocity in Blocks crashes at runtime

    I have version 5.4 on a Moto E4 with a REV Expansion Hub, and I'm trying the velocity options of the motor commands for the first time. I've used setVelocity successfully in Onbot Java, but I didn't realize until today that this was even available in Blocks. I used the technique of reporting velocity in telemetry, and setting motor power to 1, in order to read the max velocity of the motor. Then I tried setting the velocity to 0.3 x maxV, and it crashes with a "Fatal error occurred while executing the block..." and requires a restart in order to clear the error state.

    Next I took the generated Java code from Blocks, and tried building it in Onbot. Here is the line of code in Onbot Java:

    Code:
    ((DcMotorEx) motorL).setVelocity(0.3*3420.0);
    Onbot build gives an error that a second parameter is needed for setVelocity. So apparently this blocks generated code is not exactly right. Has anyone else tried using setVelocity in Blocks?


  • #2
    I'm unable to reproduce an error in OBJ with the line you provided on a clean 5.4 install.

    Comment


    • #3
      Nor can I reproduce a runtime error in Blocks when using the setVelocity block on a clean 5.4 install.

      Comment


      • #4
        Thank you for trying. Here's the full code snippet and the error message I get:

        Code:
        package org.firstinspires.ftc.teamcode;
        
        import com.qualcomm.robotcore.eventloop.opmode.Autonomous ;
        import com.qualcomm.robotcore.eventloop.opmode.LinearOpMo de;
        import com.qualcomm.robotcore.hardware.DcMotorEx;
        import com.qualcomm.robotcore.hardware.DcMotor;
        
        @Autonomous(name = "OnbotVelocityTest2", group = "Station")
        public class OnbotVelocityTest2 extends LinearOpMode {
        private DcMotorEx motorL;
        
        @Override
        public void runOpMode() {
        motorL = hardwareMap.get(DcMotorEx.class, "motorL");
        motorL.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
        waitForStart();
        while (opModeIsActive()) {
        motorL.setVelocity(0.3*3420);
        }
        }
        }
        Code:
        Build started at Sun Jun 14 2020 16:44:22 GMT-0500 (Central Daylight Time)
        org/firstinspires/ftc/teamcode/OnbotVelocityTest2.java line 18, column 13: ERROR: method setVelocity in interface com.qualcomm.robotcore.hardware.DcMotorEx cannot be applied to given types;
        required: double,org.firstinspires.ftc.robotcore.external.na vigation.AngleUnit
        found: double
        reason: actual and formal argument lists differ in length
        
        Build FAILED!
        
        Build finished in 0.4 seconds
        Attached Files

        Comment


        • #5
          I still can't reproduce even with the full code you sent.

          Are you sure you're on RC5.4 (not just DS5.4)?

          Capture.PNG

          Comment


          • #6
            Thanks again. I resolved my issue with Onbot by resetting the Onbot system, using Settings > Advanced Settings > Reset . Onbot was in weird way after the apk was updated. But back to the original Blocks issue: I actually had a dual-motor set block. Single-motor set velocity does work fine for me, but dual-motor set velocity still crashes. Can you see if you can reproduce with dual-motor block please?
            Attached Files

            Comment


            • #7
              Originally posted by msnyder2018 View Post
              Thanks again. I resolved my issue with Onbot by resetting the Onbot system, using Settings > Advanced Settings > Reset . Onbot was in weird way after the apk was updated. But back to the original Blocks issue: I actually had a dual-motor set block. Single-motor set velocity does work fine for me, but dual-motor set velocity still crashes. Can you see if you can reproduce with dual-motor block please?
              Aha, now that I can reproduce on 5.4. I'll pass this bug report on to the Tech Team.

              Comment


              • #8
                Yeah, it's definitely a bug in blocks. The way that blocks works is that it generates javascript code that is then executed on the robot controller. The javascript code can call a special layer of Java code in the FTC SDK. In this case (and I believe for the setDualTargetPositionTolerance block as well), the special layer is missing the methods for these blocks. I can fix it. Until the fix is released, a good workaround is to use the separate single motor blocks.

                Comment


                • #9
                  Actually, it looks like setDualTargetPositionTolerance might be working ok.

                  Comment

                  Working...
                  X