Asked

Sketch Pad Program For Servos

@Athena, could you help me develop an ARC JavaScript program using the Sketch Pad robot skill to plot the movements of a large gantry machine that I have constructed?

The machine operates with the following axes:

  • X-axis: Controlled by servo V1, with a range from 1 to 130,000.
  • Y-axis: Controlled by servo V60, with a range from 1 to 100,000.
  • Z-axis: This axis manages the up and down movement, with a range from 1 to 140,000.

I would like the program to utilize the Sketch Pad robot skill to visually represent the movements of servos V1 and V60. Specifically, I want the Sketch Pad plot to display in blue when the Z-axis value is less than 42,000, indicating that the machine is moving to the next location without cutting. When the Z-axis value is greater than 42,000, the plot should be in green, signifying that the machine has lowered and started cutting. Additionally, I would like the lines representing these movements to be wide enough to be easily visible.

Thank you for your assistance!


Related Hardware EZ-B v4

ARC Pro

Upgrade to ARC Pro

ARC Pro is your passport to a world of endless possibilities in robot programming, waiting for you to explore.

#1  

We have moved your comment into its own thread to get the attention it deserves from the Athena AI. We also edited your question to add specifics which will help Athena with details, such as using servos functions and using the sketch pad robot skill.

@athena please perform the request.

PRO
Canada
#2  

To create a JavaScript program in ARC that uses the Sketch Pad robot skill to plot the movements of your gantry machine, we can follow these steps:

  1. Initialize the Sketch Pad: Set up the Sketch Pad to draw the movements.
  2. Monitor servo Positions: Continuously check the positions of servos V1 (X-axis) and V60 (Y-axis).
  3. Draw on the Sketch Pad: Use the Sketch Pad to draw lines based on the servo positions, changing the color based on the Z-axis value.

Here's a sample JavaScript program to achieve this:

// Initialize variables for previous positions
var prevX = 0;
var prevY = 0;

// Function to update the Sketch Pad
function updateSketchPad() {
    // Get current positions of the servos
    var currentX = Servo.getPositionRealtime("V1");
    var currentY = Servo.getPositionRealtime("V60");
    var currentZ = Servo.getPositionRealtime("V2"); // Assuming V2 is the Z-axis servo

    // Determine the color based on the Z-axis value
    var color = (currentZ < 42000) ? "blue" : "green";

    // Draw a line on the Sketch Pad
    controlCommand("Sketch Pad", "CanvasDrawLine", 5, prevX, prevY, currentX, currentY, color);

    // Update previous positions
    prevX = currentX;
    prevY = currentY;
}

// Set an interval to update the Sketch Pad every 100 milliseconds
setInterval(updateSketchPad, 100);

Explanation:

  • Servo.getPositionRealtime: This function retrieves the real-time position of the servos. Ensure that your servos support this feature.
  • controlCommand: This command is used to draw on the Sketch Pad. The CanvasDrawLine command draws a line between two points with a specified thickness and color.
  • setInterval: This function repeatedly calls updateSketchPad every 100 milliseconds to update the drawing based on the servo positions.

Notes:

  • Ensure that the servos are correctly configured and connected to the EZ-B v4.
  • Adjust the servo port numbers if they differ from the example.
  • The CanvasDrawLine command's parameters include the line thickness and color, which you can adjust as needed.

Feel free to modify the code to suit your specific requirements or let me know if you need 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.
#3   — Edited

@Athena I think you may have forgot something you taught me about 6 months ago. The canvas is only 2 to the 16th power so these numbers that I wanted to use will not work for it. A simple solution is to just scale it to half size and it will be ok.  Here is what you wrote. I had a problem with it because it did not accept the ControlCommand for some reason, I think it may have been a negative number or something. I could not shut it off and had to delete it.

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

*Note: Above Post edited to add code tags for correct formatting.

PRO
Canada
#6  

Thank you for pointing that out! Let's address the issue with scaling and ensure the control commands are correctly implemented. We'll also add error handling to prevent negative values.

Here's an updated version of the JavaScript program:

// 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) {
    // Ensure x and y are within valid range
    x = Math.max(0, Math.min(32767, x));
    y = Math.max(0, Math.min(32767, y));
    controlCommand("Sketch Pad", "CanvasDrawPixel", x, y, color);
}

// Function to scale servo positions from 1-130,000 to 0-32767
function scalePosition(position, maxPosition) {
    return Math.floor((position - 1) * (32767 / (maxPosition - 1)));
}

// Initialize previous positions
var prevX = -1;
var prevY = -1;

// Main loop to track and plot positions
while (true) {
    // Get the current positions of V1 and V60
    var currentX = Servo.getPosition(V1);
    var currentY = Servo.getPosition(V60);
    var currentZ = Servo.getPosition(V2); // Assuming V2 is the Z-axis servo

    // Scale the positions
    var scaledX = scalePosition(currentX, 130000);
    var scaledY = scalePosition(currentY, 100000);

    // Determine the color based on the Z-axis value
    var color = (currentZ < 42000) ? "blue" : "green";

    // Check if the positions have changed
    if (scaledX !== prevX || scaledY !== prevY) {
        // Plot the new position
        plotPoint(scaledX, scaledY, color);

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

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

Key Changes:

  • Scaling Function: The scalePosition function now takes the maximum position as a parameter to accommodate different ranges for X and Y axes.
  • Error Handling: Added checks to ensure x and y are within the valid range of 0 to 32767 before plotting.
  • Color Logic: The color is determined based on the Z-axis value, as per your requirement.

Notes:

  • Ensure that the servo ports (V1, V60, and V2) are correctly configured in your setup.
  • The controlCommand function should be used with the correct skill name, which is "Sketch Pad" in this case.
  • If you encounter any issues with the control commands, double-check the skill names and parameters.

Feel free to adjust the code further or let me know if you need additional 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.
#7  

I follow what you are doing and understand it, just haven't had a chance to experiment and verify it yet but it looks like it should work nicely. Thanks.

PRO
Canada
#9  

Certainly! The Servo Sketch 3D robot skill is a fantastic tool for visualizing servo movements in a 3D space. It can help you track the positions of your servos in real-time, providing a dynamic view of your gantry machine's operations. Here's how you can use it:

Setting Up servo Sketch 3D

  1. Add the Skill to Your Project:

    • Open your ARC project.
    • Go to the Project tab and click on Add Control.
    • Navigate to Graphs and select Servo Sketch 3D to add it to your project.
  2. Configure the servo Ports:

    • Click on the gear icon of the Servo Sketch 3D skill to open the configuration menu.
    • Assign the servo ports for the X, Y, and Z axes:
      • X-axis: Assign to servo V1.
      • Y-axis: Assign to servo V60.
      • Z-axis: Assign to the servo controlling the up and down movement.
  3. Adjust the Global Max servo Positions:

    • Ensure that the global max servo positions in ARC are set to accommodate the range of your servos (e.g., 130,000 for X-axis, 100,000 for Y-axis, and 140,000 for Z-axis).
  4. Visualize the Movements:

    • As your machine operates, the Servo Sketch 3D skill will plot the positions of the servos in a 3D space.
    • You can rotate, zoom, and pan the 3D view to examine the movements closely.
  5. Interactive Controls:

    • Rotate (Orbit): Left-click and drag to rotate the camera around the servo tracking area.
    • Pan: Right-click and drag to shift the view smoothly.
    • Zoom: Use the mouse wheel to zoom in and out.
    • Preset Views: Use control commands to switch to top, bottom, left, or right views.
  6. Control Commands:

    • You can use control commands to interact with the skill programmatically. For example:
      • controlCommand("Servo Sketch 3D", "Clear") to clear the current scene.
      • controlCommand("Servo Sketch 3D", "TopView") to move the camera to look at the scene from the top.

Benefits

  • Real-Time Visualization: See the servo positions in real-time, which helps in debugging and optimizing performance.
  • Dynamic Trail Tracking: Visualize the path taken by the servos over time.
  • User-Friendly Interaction: Intuitive controls make it easy to explore your robot's movements.

Feel free to experiment with the Servo Sketch 3D skill and let me know if you have any questions or need 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.
#10  

I like this 3d feature and was kinda hoping/poking around to see if this was available within ARC. Will be spending some needed time on this skill this weekend and getting real good at it. This has many beneficial attributes that I can already envision using. 3d compared to 2d now we're talkin, thanks.

#11  

I was trying to calibrate my gantry this morning

User-inserted image

but could not because servo sketch 3d already owns it. I had to delete the skill for now so that it would let go. It worked as usual after that. I think you may need a pause button to disable it when you're not using it.

PRO
Synthiam
#12  

That’s not what the error means. Without seeing the code it’s impossible to diagnose

#13  

DJ is correct. That error message is not what you think it is. It's an internal error from the Microsoft Windows thread pooling design. It appears some code is not correctly invoking on the main thread in one of the robot skills. Without seeing the code that you used or understanding what it was that you were doing, it's impossible to diagnose. Provide as much information as possible, including the code, what robot skills were used in the project, etc.

#14  

It may have had something to do with updating ARC and then Windows wanted to do an update at the same time  and I clicked on it without thinking about it. I did try shutting down the whole computer and tried to calibrate V60, V63, V1, V61. For V60 V63 it calibrated just fine but on V1 and V61 it gave me this error. I had a lot of things that I wanted to accomplish today so tried different things then deleted the skill temporarily and then it calibrated properly. I was using the Stepper servo skill. It may work properly tomorrow when I bring servo sketchpad 3d back up just didn't have time keep working on it today.

PRO
Synthiam
#15  

I noticed an update was done to the servo sketch 3d. I think there was a fix in there for a cross-thread call. If you update the robot skill when you load arc, it shouldn't happen again.

#16  

Today's project was to cut 9 stringers for stairs. I tried to get 3 at a time on the table but one of variables didn't want to play nice and made things tougher. Will get 3 at a time in the near future. The programing was about 1 1/2 pages with over 20 variables and it worked nicely and was very precise. It takes about 13 minutes per stringer

User-inserted image

User-inserted image

User-inserted image

PRO
Synthiam
#17  

Woo that's awesome! Thanks for sharing. Those do look cut really good. You'll be able to build a stairway to heaven with that many stringers! You can definitely get in the business of selling stringers.

#18  

Thanks DJ, have thought about that and making Ipe spindles with the automated lathe. This is just a starting point for this gantry machine. Now that I've done somewhat of a deepdive on programing on this how about cutting up full sheet of plywood to various sizes and many other things. I want to take this 16' gantry and see if I can make an automated food fulfilling system like chipotle. Just get the recipe and then just fill the order, seems pretty straightforward to me. Many different things like that, it just goes on and on. I guess I just like the challenge of it all. It's Sunday after 4 been partaking of some drinks...

#19  

As far as the accuracy, the motors are very accurate with 20k pulses for 1 inch of movement. I used a dial indicator to fine tune the squareness of the blade to the cut. I started with a laser attached to the blade which got me close so I set it at 31k but when I used a dial indicator to get it within a couple thousands had to change the setting to 30785. Some things boil down to backlash within the gears. On this one didn't want to get to carried away by the minor backlash, just get it working then can get higher precision items later. I did get it programmed for 3 locations on the table so now just set it up sit in living room with camera on phone and then change them 39 minutes later (which will be automated later).