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

With Synthiam ARC Pro, you're not just programming a robot; you're shaping the future of automation, one innovative idea at a time.

PRO
Canada
#9  

I apologize for the oversight.Lets clarify the ARC JavaScript commands that will be used and their purposes:

ARC JavaScript Commands

  1. Servo.getPosition(port, [ezbIndex])

    • Purpose: Retrieves the current position of the specified servo port.
    • Usage: Servo.getPosition(V26) will get the current position of the servo connected to port V26.
  2. controlCommand(controlName, command, [parameters])

    • Purpose: Sends a command to a specified control (e.g., Sketch Pad).
    • Usage: controlCommand(Sketch Pad, CanvasDrawPixel, x, y, color) will draw a pixel at the specified (x, y) coordinates with the given color on the Sketch Pad.
  3. sleep(timeMs)

    • Purpose: Pauses the execution of the script for the specified time in milliseconds.
    • Usage: sleep(100) will pause the script for 100 milliseconds.
  4. getVar(variableName, [defaultValue])

    • Purpose: Retrieves the value from ARC's public global variable storage.
    • Usage: getVar($V26) will get the value of the global variable $V26.

Updated Script

Here's the updated script using the correct ARC JavaScript commands:

// Set the canvas size to 50000x50000
controlCommand("Sketch Pad", "CanvasSize", 50000, 50000);

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

// 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");

    // Check if the positions have changed
    if (currentX !== prevX || currentY !== prevY) {
        // Plot the new position
        plotPoint(currentX, currentY, "red");

        // Update previous positions
        prevX = currentX;
        prevY = currentY;
    }

    // Small delay to prevent excessive CPU usage
    sleep(100);
}

Explanation

  1. Set the Canvas Size:

    • controlCommand("Sketch Pad", "CanvasSize", 50000, 50000);
    • This sets the canvas size to 50000x50000 to match your grid.
  2. Plot a Point:

    • function plotPoint(x, y, color) { controlCommand("Sketch Pad", "CanvasDrawPixel", x, y, color); }
    • This function plots a pixel on the canvas at the specified (x, y) coordinates with the given color.
  3. Initialize Previous Positions:

    • var prevX = -1; var prevY = -1;
    • These variables store the previous positions to detect changes.
  4. Main Loop:

    • while (true) { ... }
    • This loop continuously checks the positions of V26 and V27.
  5. Get Current Positions:

    • var currentX = Servo.getPosition("V26");
    • var currentY = Servo.getPosition("V27");
    • These commands retrieve the current positions of the servos connected to V26 and V27.
  6. Check for Position Changes:

    • if (currentX !== prevX || currentY !== prevY) { ... }
    • This condition checks if the positions have changed.
  7. Plot New Position:

    • plotPoint(currentX, currentY, "red");
    • This plots the new position on the canvas.
  8. Update Previous Positions:

    • prevX = currentX; prevY = currentY;
    • These commands update the previous positions to the current ones.
  9. Small Delay:

    • sleep(100);
    • This adds a small delay to prevent excessive CPU usage.

This script should now correctly track and plot the positions of V26 and V27 on the Sketch Pad. If you have any further questions or need additional assistance, feel free to ask!


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.
PRO
Synthiam
#10  

@athena Why did you put the servo port in quotes?

PRO
Canada
#11  

You are correct;servo ports should not be enclosed in quotes when used in ARC JavaScript commands.Lets correct that and ensure the script is accurate.

Corrected Script

// Set the canvas size to 50000x50000
controlCommand("Sketch Pad", "CanvasSize", 50000, 50000);

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

// 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);

    // Check if the positions have changed
    if (currentX !== prevX || currentY !== prevY) {
        // Plot the new position
        plotPoint(currentX, currentY, "red");

        // Update previous positions
        prevX = currentX;
        prevY = currentY;
    }

    // Small delay to prevent excessive CPU usage
    sleep(100);
}

Explanation of ARC JavaScript Commands

  1. Servo.getPosition(port, [ezbIndex])

    • Purpose: Retrieves the current position of the specified servo port.
    • Usage: Servo.getPosition(V26) will get the current position of the servo connected to port V26.
  2. controlCommand(controlName, command, [parameters])

    • Purpose: Sends a command to a specified control (e.g., Sketch Pad).
    • Usage: controlCommand("Sketch Pad", "CanvasDrawPixel", x, y, color) will draw a pixel at the specified (x, y) coordinates with the given color on the Sketch Pad.
  3. sleep(timeMs)

    • Purpose: Pauses the execution of the script for the specified time in milliseconds.
    • Usage: sleep(100) will pause the script for 100 milliseconds.
  4. getVar(variableName, [defaultValue])

    • Purpose: Retrieves the value from ARC's public global variable storage.
    • Usage: getVar("$V26") will get the value of the global variable $V26.

Instructions to Run the Script

  1. Add the Sketch Pad Skill:

    • Go to Project - Add Skill - Scripting - Sketch Pad.
  2. Add the Script Skill:

    • Go to Project - Add Skill - Scripting - Script.
  3. Copy and Paste the Code:

    • Copy the JavaScript code above and paste it into the script editor.
  4. Run the Script:

    • Click the Start button to run the script and watch the points being plotted on the Sketch Pad.

This script should now correctly track and plot the positions of V26 and V27 on the Sketch Pad without enclosing the servo ports in quotes. If you have any further questions or need additional assistance, feel free to ask!


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.
PRO
Synthiam
#12   — Edited

@Athena it looks like the sketch canvas can't be 50000 pixels because it's an int16. So you'd have to make the image the size of an int16 and then scale the servo positions accordingly. because the servo positions are going to be between 1-50000 according to @automation man's request.

PRO
Canada
#13  

Thank you for pointing that out. Since the canvas size is limited to the range of an int16 (which is -32768 to 32767), we need to scale the servo positions accordingly. Let's assume we want to use the full positive range of int16, which is 0 to 32767.

We'll scale the servo positions from the range of 1-50000 to 0-32767. Here's the updated script with the necessary scaling:

Updated Script with Scaling

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

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

// Function to scale servo positions from 1-50000 to 0-32767
function scalePosition(position) {
    return Math.floor((position - 1) * (32767 / 49999));
}

// 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);

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

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

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

    // Small delay to prevent excessive CPU usage
    sleep(100);
}

Explanation of Changes

  1. Canvas Size:

    • controlCommand("Sketch Pad", "CanvasSize", 32767, 32767);
    • The canvas size is set to 32767x32767 to fit within the int16 range.
  2. Scaling Function:

    • function scalePosition(position) { return Math.floor((position - 1) * (32767 / 49999)); }
    • This function scales the servo positions from the range of 1-50000 to 0-32767.
  3. Scaling Positions:

    • var scaledX = scalePosition(currentX);
    • var scaledY = scalePosition(currentY);
    • The servo positions are scaled before plotting.
  4. Plotting:

    • plotPoint(scaledX, scaledY, "red");
    • The scaled positions are plotted on the canvas.

Instructions to Run the Script

  1. Add the Sketch Pad Skill:

    • Go to Project -> Add Skill -> Scripting -> Sketch Pad.
  2. Add the Script Skill:

    • Go to Project -> Add Skill -> Scripting -> Script.
  3. Copy and Paste the Code:

    • Copy the JavaScript code above and paste it into the script editor.
  4. Run the Script:

    • Click the Start button to run the script and watch the points being plotted on the Sketch Pad.

This script should now correctly track and plot the scaled positions of V26 and V27 on the Sketch Pad. If you have any further questions or need additional assistance, feel free to ask!


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.
#15   — Edited

Nicely done! I couldn't really read the info on my phone yesterday. Having it scaled with about 32k will work very well.

#16  

User-inserted image

User-inserted image

Wonder if you had to modify any of the code, mine is giving me couple issues. I did do a trial circle that was in the documentation of Sketch Pad and it drew it fine.