Announcement

Collapse
No announcement yet.

SDK 7.0 Adds support for external libraries to Blocks

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

  • SDK 7.0 Adds support for external libraries to Blocks

    The release notes for the latest (https://github.com/FIRST-Tech-Challe...troller#readme) start with details on "Adds support for external libraries to OnBotJava and Blocks".

    How can this be utilized? Any examples?

  • #2
    I will have some examples available soon, but essentially, to make an external library work with Blocks, you have to annotated the class with @ExportClassToBlocks and the methods with @ExportToBlocks.
    Here's an example:

    import org.firstinspires.ftc.robotcore.external.ExportCla ssToBlocks;
    import org.firstinspires.ftc.robotcore.external.ExportToB locks;

    @ExportClassToBlocks
    public class SimpleMath {
    /**
    * Returns the sum of the two given numbers.
    */
    @ExportToBlocks(
    tooltip = "Returns the sum of two numbers.",
    parameterLabels = {"a", "b"})
    public static double sum(double a, double b) {
    return a + b;
    }
    }


    Comment


    • #3
      Here's what it looks like, properly formatted.
      Screen Shot 2021-10-02 at 6.17.48 PM.png

      Comment


      • #4
        Here is an example that shows some the custom external blocks that are calling methods in the teamcode.

        Can someone help extend this concept so that a team's custom block would be able to drive a basic pushbot forward? I have been trying but can't quite figure out how to get the values from the main blocks program like the hardware mapping to be used in the new methods that the blocks refer to.

        You do not have permission to view this gallery.
        This gallery has 2 photos.

        Comment


        • #5
          If the java method has an argument that is a HardwareMap, it won't appear on the block, but when the block is used, the HardwareMap will be passed through correctly to the java code. There are other types that are supported like this: LinearOpMode, OpMode, Telemetry, and Gamepad.

          I hope that helps!

          Comment


          • #6
            Could you check out the attached that has errors? I'm not sure how to get the values that the Blocks programs knows about to pass to this external Java program. A working example would really help!
            Attached Files

            Comment


            • #7
              Hi - We got it working!

              Thanks to the full documentation you can read at https://github.com/WestsideRobotics/FTCmyBlocks/wiki

              Here now is an example of a Class that has a basic goForward method to drive the 4 drive motor robot forward.

              Blocks Program: Java Class:
              FTC Blocks program using goForward.jpg FTC Team Block goForward.jpg

              Important points learned:
              1. The new Class must be defined with "extends BlocksOpModeCompanion"
              2. Methods defined must be static to show up in Blocks.
              3. If the method is void, it will show with a triangle connection to connect to the next sequential block. If it has a "return", the block will show with the puzzle piece to insert into another accepting block.
              4. Needed to add motor definitions in the class. - this happens automajically in blocks, but you will need to define it in the new Java Class.
              5. Had to add "linearOpMode." in front of methods in the Java generated code to get the sleep to work.


              Our team has many so many blocks in our current programs that the response of the blocks interface lags severely since it has to emulate all the blocks. Once a Blocks function is perfected, we can convert it into a method in a custom team Java Class and then remove the function from the Blocks code.

              We can create new Blocks programs that will use Java blocks from this new single definition. We will not need to have a copy of all the Blocks functions in each blocks program as was done previously and should cut the size of the Blocks programs down significantly.

              This provides a pathway for students that are just learning blocks and give them a path to move to Java.

              Thanks!
              Team 10098

              Comment


              • #8
                That's a really cool usage of this feature! Thanks for sharing!

                Comment


                • #9
                  Just adding this FTC Wiki link, for anyone who might search/visit this thread based on its title:

                  https://github.com/FIRST-Tech-Challe...ava-and-Blocks

                  Comment

                  Working...
                  X