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

ARC Pro is more than a tool; it's a creative playground for robot enthusiasts, where you can turn your wildest ideas into reality.

PRO
Synthiam
#25  

@athena

add print debugging to this script so he can see what the servo positions and calculated values are


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

PRO
Canada
#26  

Sure, I'll add print statements to the script so you can see the values of the servo positions and the calculated values. This will help you understand what's happening at each step.

Here's the updated script with debugging print statements:

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

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

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

How to Use the Script

  1. Copy and Paste: Copy the script and paste it into your ARC project.
  2. Run the Script: Run the script in ARC.
  3. Observe the Output: The print statements will display the current servo positions, scaled positions, and plotted positions in the console.

What to Look For

  • Current servo Positions: These are the raw positions of the servos connected to V26 and V27.
  • Scaled Positions: These are the positions scaled to fit the canvas size.
  • Plotted Positions: These are the positions that are actually plotted on the canvas.

By observing these values, you can understand how the positions are being calculated and plotted. If you notice any unexpected values, you can use this information to debug and adjust your code accordingly.

Feel free to run the script and let me know if you need any further assistance!


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

@Athena In the latest script aren't you just plotting the value of V26 and V26 one time. Can you add a feature where I can define how long that I would like it to run- example 30 seconds. Another feature that would be nice is to be able to insert a certain script and this Sketch pad script continues till that certain script is completed and then shuts off automatically.

PRO
Canada
#28  

Absolutely! I can add a feature to define how long the script should run and also allow it to run until a certain script is completed. Here's the updated script with these features:

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

// Define the duration to run the script (in milliseconds)
var runDuration = 30000; // 30 seconds

// Get the start time
var startTime = new Date().getTime();

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

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

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

    // Check if the run duration has been exceeded
    var currentTime = new Date().getTime();
    if (currentTime - startTime >= runDuration) {
        print("Run duration exceeded. Stopping script.");
        break;
    }

    // Check if a certain script is completed
    if (getVar("$CertainScriptCompleted") === true) {
        print("Certain script completed. Stopping script.");
        break;
    }

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

How to Use the Script

  1. Copy and Paste: Copy the script and paste it into your ARC project.
  2. Set Run Duration: Adjust the runDuration variable to the desired duration in milliseconds (e.g., 30000 for 30 seconds).
  3. Run the Script: Run the script in ARC.
  4. Observe the Output: The print statements will display the current servo positions, scaled positions, and plotted positions in the console.

Additional Feature: Run Until a Certain Script is Completed

  • Certain Script Completion: The script will also check if a certain script is completed by monitoring the $CertainScriptCompleted variable. You can set this variable to true in your other script when it completes.

Example of Setting $CertainScriptCompleted in Another Script

// Your certain script logic here

// Set the variable to true when the script completes
setVar("$CertainScriptCompleted", true);

By using these features, you can control how long the script runs and also have it stop automatically when another script completes. Feel free to run the script and let me know if you need any further assistance!


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

@ Athena I'm pretty sure you cannot initialize a variable to be a negative number    // Initialize previous positions var prevX = -1; var prevY = -1; I'm pretty sure this is not legal either       return Math.floor((position - 1) * (32767 / 49999));  because what if it is position 1 then 1-1 =0 and there is no position 0. Please rewrite the script to be a legal script in the ARC scripting enviroment.

PRO
Synthiam
#30   — Edited

You might confuse her, and your questions are incorrect, making her code different from what you want.

  1. the original script she posted loops forever, plotting until you press stop. That’s what you want. Now she made a bunch of stuff with timing for 30 seconds, which added complexity to a script that you can’t understand to begin with

  2. the math that calculates zero is not about the servo position. It takes the servo position as an input and calculates it into a position to be plotted.

  3. the damaging number assignment is to initialize a variable that keeps track of when a servo position changes

My recommendation is to focus on the outcome - which is a 2d plot of 2 servos. Don't add complexities such as timing because you can hit the start and stop buttons yourself. You are also reading her comments to understand what script has already been generated and what it does. The point of debugging is to explain the actual behavior you witnessed, not the thing you assume to be incorrect, without understanding the script. It's a good exercise, and one thing Athena could get better at would be asking questions to help walk you through the process.

Athena documented the script and explained everything. It’s a simple script that works well, and with debugging, I’m hoping it’ll help you follow what it looks like. Look at it again and see if you understand what it’s doing. Read her comments that explain what it’s doing.

PRO
Synthiam
#31   — Edited

@athena this uses the mapping function. i also notice that an image of 32000 pixels is too large for most computers. So the image is scaled to 2,000 pixel image.

// 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);
}
#32  

Ok I'm backtracking, I copied and pasted the above script. Started my changing numbers script for V26 and V27. Started the above script.  It mentions that the input string was not in correct format. Tried to turn it off, cannot do it and have to shut down Arc. This why I was asking for the time limit because I cannot turn it off. I am understanding what is happening with your code but there must be some small issue somewhere that is throwing it off.