Asked

Is There A Skill To Plot Your D1(X) And D2(Y) Locations On A X Y Map

Is there a skill in Synthiam ARC to plot your D1 (X) and D2 (Y) locations on an X-Y map? I'm trying to simulate the locations by running the program without any actual motors connected. Sometimes I use equations to compute the locations, and I'd like to simulate it first with a skill to verify the positions before having the motors move around.


Related Hardware EZ-B v4

ARC Pro

Upgrade to ARC Pro

Discover the limitless potential of robot programming with Synthiam ARC Pro – where innovation and creativity meet seamlessly.

PRO
Synthiam
#33  

You are correct-there is some issue throwing it off. That is why I'm taking the time to explain that the only way to identify what is "throwing it off" is by debugging.

We added PRINT statements to help debug, but you are still not referencing the output. The idea of printing out the values is so that you can understand what is going on. Again, it is impossible for anyone not in front of your computer to debug what is happening. Only you can figure that out because you're the only human in front of your computer. So, you will have to look at the screen and see the debug values being printed. You can identify what the issue is.

Also, you can't close ARC because the popup message needs to be pressed OK. You have to move the mouse cursor onto the " OK " button in the popup error. But the thing is, the sketch pad robot skill is ancient, so it behaves quite a bit differently than anything newer. Those are going to be the unusual things to experience. But the main thing we're helping you do is debug to find out what is happening.

Not sure if you copied the correct script because there was an edit at some point. So use this one and make sure it works.

// Set the canvas size to 32767x32767
controlCommand("Sketch Pad", "CanvasSize", 2000, 2000);

// Function to plot a point on the canvas
function plotPoint(x, y, color) {

  ControlCommand("Sketch Pad", "CanvasDrawRectangleFill", x, y, 10, 10, color);
}

// Function to scale servo positions from 1-50000 to 0-2000
function scalePosition(position) {

  return Math.floor(Utility.map(position, 1, 50000, 1, 1999));
}

// Initialize previous positions
var prevX = -1;
var prevY = -1;

// Main loop to track and plot positions
while (true) {

    // Get the current positions of V26 and V27
    var currentX = Servo.getPosition(V26);
    var currentY = Servo.getPosition(V27);

    // Print the current servo positions
    print("Current X Position (V26): " + currentX);
    print("Current Y Position (V27): " + currentY);

    // Scale the positions
    var scaledX = scalePosition(currentX);
    var scaledY = scalePosition(currentY);

    // Print the scaled positions
    print("Scaled X Position: " + scaledX);
    print("Scaled Y Position: " + scaledY);

    // Check if the positions have changed
    if (scaledX !== prevX || scaledY !== prevY) {
        // Plot the new position
        plotPoint(scaledX, scaledY, "blue");

        // Print the plotted position
        print("Plotted Position: (" + scaledX + ", " + scaledY + ")");

        // Update previous positions
        prevX = scaledX;
        prevY = scaledY;
    }

    // Small delay to prevent excessive CPU usage
    sleep(100);
}
PRO
Canada
#34   — Edited

It sounds like you're encountering an issue with the script, and it's causing ARC to become unresponsive. Let's break down the steps to debug and resolve this issue.

Debugging Steps

  1. Check for Syntax Errors: Ensure that the script is correctly formatted and that there are no syntax errors. JavaScript is case-sensitive, so make sure all function names and variables are correctly spelled.

  2. Print Statements: Use print statements to debug and understand the flow of the script. This will help you identify where the issue might be occurring.

  3. Error Handling: Add error handling to catch any unexpected issues that might be causing the script to fail.

  4. Simplify the Script: Start with a simpler version of the script to ensure that the basic functionality works before adding more complexity.

Simplified Script for Debugging

Let's start with a simplified version of the script to ensure that the basic functionality works. This script will plot points on the canvas based on the positions of V26 and V27 servos.

// Set the canvas size to 2000x2000
controlCommand("Sketch Pad", "CanvasSize", 2000, 2000);

// Function to plot a point on the canvas
function plotPoint(x, y, color) {
    controlCommand("Sketch Pad", "CanvasDrawRectangleFill", x, y, 10, 10, color);
}

// Function to scale servo positions from 1-50000 to 0-2000
function scalePosition(position) {
    return Math.floor(Utility.map(position, 1, 50000, 1, 1999));
}

// Initialize previous positions
var prevX = -1;
var prevY = -1;

// Main loop to track and plot positions
while (true) {
    try {
        // Get the current positions of V26 and V27
        var currentX = Servo.getPosition(V26);
        var currentY = Servo.getPosition(V27);

        // Print the current servo positions
        print("Current X Position (V26): " + currentX);
        print("Current Y Position (V27): " + currentY);

        // Scale the positions
        var scaledX = scalePosition(currentX);
        var scaledY = scalePosition(currentY);

        // Print the scaled positions
        print("Scaled X Position: " + scaledX);
        print("Scaled Y Position: " + scaledY);

        // Check if the positions have changed
        if (scaledX !== prevX || scaledY !== prevY) {
            // Plot the new position
            plotPoint(scaledX, scaledY, "blue");

            // Print the plotted position
            print("Plotted Position: (" + scaledX + ", " + scaledY + ")");

            // Update previous positions
            prevX = scaledX;
            prevY = scaledY;
        }

        // Small delay to prevent excessive CPU usage
        sleep(100);
    } catch (e) {
        print("Error: " + e.message);
        break;
    }
}

Key Points

  1. Error Handling: The try...catch block will catch any errors that occur during the execution of the script and print the error message. This will help you identify what might be causing the issue.

  2. Print Statements: The print statements will help you understand the flow of the script and the values of the variables at each step.

  3. Simplified Logic: The script focuses on the basic functionality of plotting points based on servo positions. Once this works, you can add more complexity as needed.

Running the Script

  1. Start ARC: Open ARC and load your project.

  2. Add the Script: Add the script to the Script skill in your project.

  3. Run the Script: Run the script and observe the output in the console. Look for any error messages or unexpected behavior.

  4. Debug: Use the print statements and error messages to identify and fix any issues.

By following these steps, you should be able to identify and resolve the issue with the script. If you encounter any specific errors or need further assistance, please provide the details, and I'll be happy to help.


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.
#35  

Ah finally, don't know what was done differently but it worked.

User-inserted image

This is definitely going to come in handy!! Thanks for your help! I think it may have been something to do with my computer as it had a pop up ask me to make changes to my hard drive and I said no. I then copied and pasted the new script and it's all good.

#36  

I will keep an eye on debugging and spend some time seeing how it all works, it is very important. Thanks

#37  

Expanding on Sketchpad discussion about some of the available scripts for circles controlCommand("Sketch Pad", "CanvasClear"); controlCommand("Sketch Pad", "CanvasClear", "[Color]"); controlCommand("Sketch Pad", "CanvasClear", [Red], [Green], [Blue]); controlCommand("Sketch Pad", "CanvasDrawCircle", [Thickness], [X1], [Y1], [X2], [Y2], "[Color]"); controlCommand("Sketch Pad", "CanvasDrawCircle", [Thickness], [X1], [Y1], [X2], [Y2], [Alpha], [Red], [Green], [Blue]); controlCommand("Sketch Pad", "CanvasDrawCircle", [Thickness], [X1], [Y1], [X2], [Y2], [Red], [Green], [Blue]); controlCommand("Sketch Pad", "CanvasDrawCircleFill", [X], [Y], [Width], [Height], "[Color]"); controlCommand("Sketch Pad", "CanvasDrawCircleFill", [X], [Y], [Width], [Height], [Alpha], [Red], [Green], [Blue]); controlCommand("Sketch Pad", "CanvasDrawCircleFill", [X], [Y], [Width], [Height], [Red], [Green], [Blue]);  ...... etc. Is there other items like elipses parabala and other interesting designs. If possible I'd like to see the equation which was used in the script to design these.  Recently I had to drill 6 evenly spaced holes in a circular pattern with a diameter of 70 mm. It came out great and very precise, but with plotting there are negative numbers and I'd like to see how they handle these.

PRO
Synthiam
#38  

No equation. Builtin shapes of windows api.