ARC Pro

Upgrade to ARC Pro

Subscribe to ARC Pro, and your robot will become a canvas for your imagination, limited only by your creativity.

PRO
Canada
#2  

Certainly! In Blockly, functions (referred to as "procedures" in some Blockly implementations) allow you to create reusable blocks of code. You can define a function to perform a specific task, and then you can call that function from different places in your program. This helps to organize your code and avoid repetition.

Here's a step-by-step guide on how to use functions in Blockly within Synthiam ARC:

  1. Creating a Function:

    • In the Blockly workspace, look for the "Functions" category.
    • Drag the "Create a Function" block onto the workspace.
    • Give your function a name, for example, myfunc.
    • You can also add parameters to your function if needed by clicking the blue gear icon on the function block and dragging parameter blocks into the function's workspace.
  2. Defining the Function:

    • Inside the function block, add the blocks that define what the function should do.
    • For example, you might add blocks to check sensor readings or move a servo to a certain position.
  3. Returning a Value:

    • If you want your function to return a value (for example, a boolean indicating success or failure), use the "return" block inside your function definition.
    • Drag the "return" block into your function and attach the value you want to return.
  4. Calling the Function:

    • To use the function in your program, drag the "Call Function" block (which will have the name of your function, such as myfunc) into the desired place in your Blockly script.
    • If your function has parameters, provide the necessary arguments when you call the function.
  5. Using the Return Value:

    • When you call a function that returns a value, you can use that value in your script.
    • For example, you might use an "if" block to check the return value and perform different actions based on the result.

Here's an example scenario using Blockly in Synthiam ARC:

Scenario: You want to create a function that checks if the robot's battery level is below a certain threshold and returns true if the battery is low.

  1. Create a function named checkBattery.
  2. Inside checkBattery, use the blocks to get the battery level and compare it to the threshold.
  3. If the battery level is below the threshold, return true; otherwise, return false.
  4. In your main script, call checkBattery.
  5. Use an "if" block to check if checkBattery returns true and, if so, perform an action like sending a warning message or navigating the robot to a charging station.

Remember, the exact blocks and categories may vary depending on the version of Blockly and the specific implementation in Synthiam ARC. If you need more detailed instructions or if there are specific blocks you're looking for, please let me know, and I can provide more tailored guidance.


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
#3  

Looked into the site and I may just do that. I find that ARC is nice because it can bounce back and forth between Blockly and Javascript to see what code has been generated which is what I should done before even this question, but forgot.

#4  

Saw a 5 min video on functions on YouTube and fully understand it. I think this will come in handy for the overseeing question that I asked Athena about. This is like a mini program that can be called upon to check the scenario. It would be nice if this mini program could be individually copied and pasted on the side of an existing Blockly program. Maybe it's already been done just don't know how to do it.