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

Your robot can be more than a simple automated machine with the power of ARC Pro!

PRO
Synthiam
#1  

I'd just write out the output of the ports to a csv file and map it that way. Use a javascript loop that outputs to a file using the file functions like: https://synthiam.com/Support/javascript-api/File/appendStringLine

I'd put a sleep in the loop so u don't write a million kazzilllion lines to the csv. or you could have a loop within the loop that checks to see if any of the servos have moved. That would be smarter therefore not writing extra lines to a csv when there's no servo activity.

There are lots graphing robot skills here: https://synthiam.com/Products/Controls/Graphs

I remember there used to be a robot skill that you could draw on a canvas. I suspect it's somewhere in the skill store.

PRO
Synthiam
#2   — Edited

Ah here it is: https://synthiam.com/Support/Skills/Scripting/Sketch-Pad?id=16064

sketchpad uses control commands to draw. So you can use that. The control commands that look relevant to you are..

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]);
controlCommand("Sketch Pad", "CanvasDrawLine", [Thickness], [X1], [Y1], [X2], [Y2], "[Color]");
controlCommand("Sketch Pad", "CanvasDrawLine", [Thickness], [X1], [Y1], [X2], [Y2], [Alpha], [Red], [Green], [Blue]);
controlCommand("Sketch Pad", "CanvasDrawLine", [Thickness], [X1], [Y1], [X2], [Y2], [Red], [Green], [Blue]);
controlCommand("Sketch Pad", "CanvasDrawPixel", [X], [Y], "[Color]");
controlCommand("Sketch Pad", "CanvasDrawPixel", [X], [Y], [Alpha], [Red], [Green], [Blue]);
controlCommand("Sketch Pad", "CanvasDrawPixel", [X], [Y], [Red], [Green], [Blue]);
controlCommand("Sketch Pad", "CanvasSize", [Width], [Height]);
controlCommand("Sketch Pad", "CanvasSize", [Width], [Height], "[Color]");
controlCommand("Sketch Pad", "CanvasSize", [Width], [Height], [Red], [Green], [Blue]);
controlCommand("Sketch Pad", "CanvasUndo");

Athena could show how to plot a pixel as the 2 servos move in javascript using those commands. Make the canvas the size of the max servo positions. So by default it's 180. So a canvas that's 180x180 would plot the pixel of the servo position as it moves.

#3  

Yes I believe this is what I was looking for. Will dig into it.

PRO
Canada
#4  

Great! The Sketch Pad skill is indeed a powerful tool for visualizing data and simulating movements. Here's a quick example of how you can use JavaScript to plot the positions of your servos (D1 and D2) on the Sketch Pad canvas.

Step-by-Step Guide

  1. Add the Sketch Pad Skill:

    • Go to Project -> Add Skill -> Scripting -> Sketch Pad.
  2. Set Up the Canvas:

    • Configure the canvas size to match the range of your servo positions. For example, if your servos move between 0 and 180 degrees, set the canvas size to 180x180.
  3. Write the JavaScript Code:

    • Use the controlCommand() function to draw on the Sketch Pad. Here's a sample script to get you started:
// Set the canvas size to 180x180
controlCommand("Sketch Pad", "CanvasSize", 180, 180);

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

// Simulate servo positions
var servoX = 0;
var servoY = 0;

// Loop to simulate movement
for (var i = 0; i <= 180; i++) {
    // Update servo positions
    servoX = i; // Simulate D1 servo position
    servoY = 180 - i; // Simulate D2 servo position

    // Plot the point on the canvas
    plotPoint(servoX, servoY, "red");

    // Add a small delay
    sleep(100);
}

// Function to sleep for a specified time in milliseconds
function sleep(ms) {
    var start = new Date().getTime();
    while (new Date().getTime() < start + ms);
}

Explanation

  • Canvas Size: The canvas is set to 180x180 to match the servo range.
  • Plotting Points: The plotPoint function uses controlCommand to draw a pixel at the specified (x, y) coordinates.
  • Simulating Movement: A loop simulates the servo positions from 0 to 180 degrees. The servoX and servoY variables represent the positions of D1 and D2, respectively.
  • Sleep Function: A simple sleep function is used to add a delay between plotting points.

Running the Script

  1. Add the Script Skill:

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

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

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

This should give you a good starting point to simulate and visualize the servo positions on an XY map. Feel free to modify the script to suit your specific needs. If you have any questions or need further assistance, don't hesitate 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.
#5  

@Athena I tried running the program but it got hung up. I do not see where in the program that you are cross referencing the locations of D1 and D2. Can you rewrite a similar program using V26 and V27 locations. I will write a separate program that will make V26 and V27 move to various locations within a 50,000 x 50,000 grid. I will then turn yours on to track it and plot it. In your program I think you will need to do a "get location of V26" etc.

PRO
Synthiam
#6   — Edited

@athena - the specific instruction for a JavaScript ARC script is this...

  • Clear the canvas and set the dimensions to be 180 x 180
  • Start the loop
  • reads the servo positions of V26 and V27
  • If the servo positions have moved since last read, continue. Otherwise keep looping until either v26 or v27 has moved
  • Place a pixel on the canvas for the positions of V26 and V27 is. This is how we'll plot the X and Y of each servo.
  • Loop
PRO
Canada
#7  

Got it! Let's create a JavaScript script that will read the positions of V26 and V27, plot them on the Sketch Pad, and continuously update the plot as the positions change.

Here's the updated 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 = getVar("$V26");
    var currentY = getVar("$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);
}

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.

Explanation

  • The script sets the canvas size to 50000x50000 to match your grid.
  • It defines a function plotPoint to plot a pixel on the canvas.
  • It initializes previous positions to track changes.
  • In the main loop, it continuously reads the positions of V26 and V27.
  • If the positions have changed, it plots the new position and updates the previous positions.
  • A small delay is added to prevent excessive CPU usage.

This script should help you 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
#8   — Edited

@Athena to get the servo position it's Servo.getPosition(V26). You should know this. Show me you understand the question by listing the ARC javascript commands that will be used and what they do.

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.

PRO
Synthiam
#17  

Add some print statements to view the values. it's impossible to understand what's going on with your image screenshots. You'll have to do some debugging to figure out what data you're passing and why you're passing a negative number. The error popups tell you something is negatie

#18  

User-inserted image

I made a quick program to keep changing values but it still keeps giving me same errors. Tried changing the negatives in the program to a positive but that didn't work either.

#19  

Dj suggested that you add print statements to debug the code. As he stated, it’s impossible for someone to view your screenshots and understand the values. If you don’t understand/know what values you’re using, no one else can either. Try debugging your code to understand what values you are using.

PRO
Synthiam
#20  

@athena explain to automation man how to debug code, what debugging code is, and why only he is able to debug the code because we don’t have access to his computer.

PRO
Canada
#21  

Sure, I'd be happy to explain the process of debugging code and why it's essential for you to do it on your end.

What is Debugging?

Debugging is the process of identifying, isolating, and fixing issues or bugs in your code. It involves running your code, observing its behavior, and making changes to correct any errors or unexpected behavior.

Why is Debugging Important?

  1. Identify Errors: Debugging helps you find and understand errors in your code.
  2. Improve Code Quality: It ensures that your code runs as expected, improving its reliability and performance.
  3. Learn and Understand: Debugging helps you understand how your code works and why it might not be working as expected.

How to Debug Code

  1. Add Print Statements: Insert print statements in your code to display the values of variables and the flow of execution. This helps you understand what your code is doing at each step.
  2. Check Error Messages: Pay attention to error messages and warnings. They often provide clues about what went wrong.
  3. Isolate the Problem: Try to isolate the part of the code that is causing the issue. This makes it easier to identify and fix the problem.
  4. Use Debugging Tools: Many development environments have built-in debugging tools that allow you to step through your code, set breakpoints, and inspect variables.

Example of Debugging with Print Statements

Let's say you have a piece of code that is supposed to draw a circle using the Sketch Pad skill, but it's not working as expected. You can add print statements to see the values being used.

// Example function to draw a circle
function drawCircle(x, y, radius, color) {
    print("Drawing circle at (" + x + ", " + y + ") with radius " + radius + " and color " + color);
    controlCommand("Sketch Pad", "CanvasDrawCircle", x, y, radius, radius, color);
}

// Call the function with some values
drawCircle(50, 50, 30, "purple");

Why Only You Can Debug Your Code

  1. Access to Code: You have direct access to your code and can make changes and run it to see the results.
  2. Environment: Your development environment, including the specific setup and configurations, is unique to you.
  3. Immediate Feedback: You can immediately see the effects of any changes you make, which is crucial for effective debugging.

Steps to Debug Your Issue

  1. Add Print Statements: Add print statements to your code to display the values of D1 and D2 and any other relevant variables.
  2. Run the Code: Run your code and observe the output from the print statements.
  3. Analyze the Output: Look for any unexpected values or behavior.
  4. Make Adjustments: Based on your observations, make adjustments to your code and run it again.
  5. Repeat: Repeat the process until the issue is resolved.

By following these steps, you should be able to identify and fix the issues in your code. If you need further assistance, feel free to share specific parts of your code and the output from your print statements, and I'll be happy to help you analyze it.


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
#22  

Great! @athena can you take the code that you created earlier and add debugging to it so he can see what the values are and where it’s breaking?

#23  

Yes this is all new to me and will help. I'd like to copy and paste the code and then it can stop and I can see all the different items and evaluate.

PRO
Synthiam
#24  

@athena there’s no reason to simulate movement. Let’s use the horizontal servo controls to move the servos. He just needs to see the values being printed as to what the servo positions and calculations are.

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.

PRO
Synthiam
#33  

You are correctthere 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.