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

Unlock the true power of automation and robotics by becoming a proud subscriber of Synthiam 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.