Asked
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
I apologize for the oversight.Lets clarify the ARC JavaScript commands that will be used and their purposes:
ARC JavaScript Commands
Servo.getPosition(port, [ezbIndex])
Servo.getPosition(V26)
will get the current position of the servo connected to port V26.controlCommand(controlName, command, [parameters])
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.sleep(timeMs)
sleep(100)
will pause the script for 100 milliseconds.getVar(variableName, [defaultValue])
getVar($V26)
will get the value of the global variable$V26
.Updated Script
Here's the updated script using the correct ARC JavaScript commands:
Explanation
Set the Canvas Size:
controlCommand("Sketch Pad", "CanvasSize", 50000, 50000);
Plot a Point:
function plotPoint(x, y, color) { controlCommand("Sketch Pad", "CanvasDrawPixel", x, y, color); }
Initialize Previous Positions:
var prevX = -1; var prevY = -1;
Main Loop:
while (true) { ... }
Get Current Positions:
var currentX = Servo.getPosition("V26");
var currentY = Servo.getPosition("V27");
Check for Position Changes:
if (currentX !== prevX || currentY !== prevY) { ... }
Plot New Position:
plotPoint(currentX, currentY, "red");
Update Previous Positions:
prevX = currentX; prevY = currentY;
Small Delay:
sleep(100);
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.
@athena Why did you put the servo port in quotes?
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
Explanation of ARC JavaScript Commands
Servo.getPosition(port, [ezbIndex])
Servo.getPosition(V26)
will get the current position of the servo connected to port V26.controlCommand(controlName, command, [parameters])
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.sleep(timeMs)
sleep(100)
will pause the script for 100 milliseconds.getVar(variableName, [defaultValue])
getVar("$V26")
will get the value of the global variable$V26
.Instructions to Run the Script
Add the Sketch Pad Skill:
Project - Add Skill - Scripting - Sketch Pad
.Add the Script Skill:
Project - Add Skill - Scripting - Script
.Copy and Paste the Code:
Run the Script:
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.
@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.
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 ofint16
, 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
Explanation of Changes
Canvas Size:
controlCommand("Sketch Pad", "CanvasSize", 32767, 32767);
int16
range.Scaling Function:
function scalePosition(position) { return Math.floor((position - 1) * (32767 / 49999)); }
Scaling Positions:
var scaledX = scalePosition(currentX);
var scaledY = scalePosition(currentY);
Plotting:
plotPoint(scaledX, scaledY, "red");
Instructions to Run the Script
Add the Sketch Pad Skill:
Project
->Add Skill
->Scripting
->Sketch Pad
.Add the Script Skill:
Project
->Add Skill
->Scripting
->Script
.Copy and Paste the Code:
Run the Script:
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.
That works good
Nicely done! I couldn't really read the info on my phone yesterday. Having it scaled with about 32k will work very well.
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.