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'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.
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..
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.
Yes I believe this is what I was looking for. Will dig into it.
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
Add the Sketch Pad Skill:
Project -> Add Skill -> Scripting -> Sketch Pad
.Set Up the Canvas:
Write the JavaScript Code:
controlCommand()
function to draw on the Sketch Pad. Here's a sample script to get you started:Explanation
plotPoint
function usescontrolCommand
to draw a pixel at the specified (x, y) coordinates.servoX
andservoY
variables represent the positions of D1 and D2, respectively.Running the Script
Add the Script Skill:
Project -> Add Skill -> Scripting -> Script
.Copy and Paste the Code:
Run the Script:
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.
@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.
@athena - the specific instruction for a JavaScript ARC script is this...
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:
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.Explanation
plotPoint
to plot a pixel on the canvas.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.
@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.
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.
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
![User-inserted image](/uploads/user/DDC93F315FBAA9AF1E656C8D27294F58/kuh03vab.jpeg)
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.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.
@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.
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?
How to Debug Code
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.
Why Only You Can Debug Your Code
Steps to Debug Your Issue
D1
andD2
and any other relevant variables.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.
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?
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.
@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.
@athena
add print debugging to this script so he can see what the servo positions and calculated values are
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:
How to Use the Script
What to Look For
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.
@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.
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:
How to Use the Script
runDuration
variable to the desired duration in milliseconds (e.g., 30000 for 30 seconds).Additional Feature: Run Until a Certain Script is Completed
$CertainScriptCompleted
variable. You can set this variable totrue
in your other script when it completes.Example of Setting
$CertainScriptCompleted
in Another ScriptBy 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.
@ 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.
You might confuse her, and your questions are incorrect, making her code different from what you want.
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
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.
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.
@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.
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.
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.
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
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.
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.
Error Handling: Add error handling to catch any unexpected issues that might be causing the script to fail.
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.
Key Points
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.Print Statements: The print statements will help you understand the flow of the script and the values of the variables at each step.
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
Start ARC: Open ARC and load your project.
Add the Script: Add the script to the Script skill in your project.
Run the Script: Run the script and observe the output in the console. Look for any error messages or unexpected behavior.
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.
Ah finally, don't know what was done differently but it worked.
![User-inserted image](/uploads/user/DDC93F315FBAA9AF1E656C8D27294F58/wwvvnsyu.jpeg)
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.I will keep an eye on debugging and spend some time seeing how it all works, it is very important. Thanks
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.
No equation. Builtin shapes of windows api.