Welcome to Our Community

Some features disabled for guests. Register Today.

Tech support for Javascript Macros in CONTROL

Discussion in 'Control Software' started by sharmstr, Jan 4, 2021.

  1. Misterg

    Misterg Journeyman
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 27, 2022
    Messages:
    268
    Likes Received:
    213
  2. Misterg

    Misterg Journeyman
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 27, 2022
    Messages:
    268
    Likes Received:
    213
  3. Guenni

    Guenni New
    Builder

    Joined:
    May 26, 2023
    Messages:
    2
    Likes Received:
    1
    OK, the macro works.
    But how can i delete the button????
     
  4. Peter Van Der Walt

    Peter Van Der Walt OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 1, 2017
    Messages:
    13,998
    Likes Received:
    4,110
    By deleting the Macro. Right click on the Macro Button on the Macros tab
     
  5. Misterg

    Misterg Journeyman
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 27, 2022
    Messages:
    268
    Likes Received:
    213
    You need to completely re-start OpenbuildsControl (without running the macro) to get rid of the extra toolbar button - on a Windows machine, this means closing the main OpenbuildsControl window and also right-clicking on the small OpenbuildsControl icon in the control tray(?) and selecting 'Quit Openbuilds Control...'

    When you re-start OpenbuildsControl, the extra toolbar icon will be gone. (Make sure that the macro isn't set to run on startup, or the button will be put back again!)
     
    Peter Van Der Walt likes this.
  6. Ivo Beltchev

    Builder

    Joined:
    Apr 17, 2023
    Messages:
    29
    Likes Received:
    14
    I am trying to write a macro for smooth jogging with a joystick. The way this works (for example in software like UGS) is to keep sending tiny jog commands as quickly as Grbl can process them. This requires the new command to be queued immediately after the “ok” response is received.

    Is there a way to do this from a macro currently? I was able to achieve this by adding a line “io.sockets.emit(‘ok’, command)” right after the line that says “Got an OK so we are clear to send” in index.js. But I’m hoping there is a way to do this without modifying the software. Ideally it will also provide the command that was OKed.

    One thing I tried unsuccessfully was to hook to the jobComplete event, but that was very slow and unreliable. The overhead of wrapping every tiny jog command in its own job is way to big.
     
  7. David the swarfer

    David the swarfer OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 6, 2013
    Messages:
    3,277
    Likes Received:
    1,834
    the other way is to send a long jog command while the key/joystick is pressed and a 'stop jog' when it is released.
    This is how CONTROL does it in the jog command section.
     
  8. Ivo Beltchev

    Builder

    Joined:
    Apr 17, 2023
    Messages:
    29
    Likes Received:
    14
    Yes, but it only works for long moves along a straight line. I am trying to implement interactive analog jog that responds to joystick moves.
     
  9. sharmstr

    sharmstr OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 23, 2018
    Messages:
    2,035
    Likes Received:
    1,431
    I struggled with that as well. I finally ditched it and focused on fine tuning the jog size, speed and command frequency. You also need to take into consideration max feed and max acceleration. If you do it correctly, you dont have to worry about overwhelming grbl to the point of a run-a-way condition.

    I've been meaning to release the code but have been side tracked for months on another project. I think the only thing left to sort out is soft limits consideration.
     
  10. sharmstr

    sharmstr OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 23, 2018
    Messages:
    2,035
    Likes Received:
    1,431
    Found a old video on my IG. It was still a bit jittery, but have worked those bugs out now: https://www.instagram.com/p/Co-Q6Sbsfsn/

    Yes, its a shuttle and not a joystick but the concept and variable jog speed principals are the same.
     
    David the swarfer likes this.
  11. Ivo Beltchev

    Builder

    Joined:
    Apr 17, 2023
    Messages:
    29
    Likes Received:
    14
    It's great to see another person also trying to solve this :) I am curious to see your implementation.

    I do have 2 separate versions, and the code pick one or the other based on the host. The first is like you describe - push something on the queue every 100ms and estimate the movement amount. The second one relies on modification of the core software to capture the "ok" event, though my hope is there is some Javascript trick to do it without modification. Maybe there is a way to hook directly to the serial port somehow?

    BTW, there is a secondary issue with the first approach. Trying to stop the jog with 0x85 is not reliable if you don't wait for OK. It is described here: Jog cancellation (0x85) not working [Solved] · Issue #837 · gnea/grbl
    I "solve" this by issuing a second stop on the next jobComplete event if it comes soon enough.

    I have solved the soft limits issue on my end. Basically I am using absolute positions instead of relative. It is not super reliable as you probably also found out. The difference between absolute and relative is that with absolute positions if you get the position wrong the machine might jog backwards. But with relative positions when it glitches it will go out of bounds.

    I am almost ready to release my full project. It is a complete handheld device for jogging, probing, running jobs, etc.

    I just need to finalize the jogging code and capture few videos of everything in action.
    My code is here: GitHub - ivomirb/Controlinator-3000 at dev
    And this is the hardware component: Controlinator 3000 - EasyEDA open source hardware lab
     
  12. Niuulh

    Niuulh New
    Builder

    Joined:
    Aug 9, 2023
    Messages:
    14
    Likes Received:
    9
    Hello, @Misterg i'm trying to use the tool offset macro but i run into an error while probing new tool.
    The offset is well probed but not applied due to the error.
    Any idea ?
     

    Attached Files:

    • tlo.png
      tlo.png
      File size:
      385.7 KB
      Views:
      12
  13. Misterg

    Misterg Journeyman
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 27, 2022
    Messages:
    268
    Likes Received:
    213
    Hi - did this happen when you clicked 'Proceed' to return to the original position?

    It may be that, with the new offset applied, trying to put the tool tip back at the same height of the previous tool has exceeded the Z travel of your machine*. (What is the maximum Z travel of your machine? ).

    As a diagnostic check, could you try it again but click 'close' when you get to that screen at the end of the probing cycle (rather than 'proceed' to return to the starting point).

    If not, there is some extra debugging into in the developer console (press CTRL+SHIFT+i on Windows) - look at the 'messages' under the 'console' tab - if you can paste the 'other' messages here it may help to understand what is happening.

    *It should be possible to trap this error in the macro, but I don't think it does at the moment.
     
  14. Niuulh

    Niuulh New
    Builder

    Joined:
    Aug 9, 2023
    Messages:
    14
    Likes Received:
    9
    This happend right when the probing is finish, before i click anything.
    I have like 50mm of Z travel left bellow probing point, so it should be good
    I'll send the debug messages when i go back to it tomorrow.
     
    Misterg likes this.
  15. Niuulh

    Niuulh New
    Builder

    Joined:
    Aug 9, 2023
    Messages:
    14
    Likes Received:
    9
    Here are message from debug console.
    I run reference probing and new tool probing without touching my tool, this way z travel/offset should not be a problem.
     

    Attached Files:

  16. Misterg

    Misterg Journeyman
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 27, 2022
    Messages:
    268
    Likes Received:
    213
    None the wiser, I'm sorry - can you attach the complete serial log and the messages relating to the probe (they should all be grouped together under 'other', I think) as text files, rather than screenshots - also the machine configuration?

    Do you have homing switches installed?
     
  17. Niuulh

    Niuulh New
    Builder

    Joined:
    Aug 9, 2023
    Messages:
    14
    Likes Received:
    9
    I'm sorry i don't know where to find the logs files, can't find any text file in openbuild folder. May i ask how to find them ? Sorry about that.
    Yes i have one inductive probe on each axis, back left for XY and top for Z
     
  18. Misterg

    Misterg Journeyman
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 27, 2022
    Messages:
    268
    Likes Received:
    213
    You need to copy the text in the serial log window (ctrl + A in windows) and paste it into a text document - similarly for the messages in the console if you can.

    For the configuration, go to the 'Grbl Settings' tab and click 'Backup settings', then attach that text file.

    One more question - when you installed the macro, did you copy and paste the code or use the JSON file?

    Thanks :)
     
  19. Niuulh

    Niuulh New
    Builder

    Joined:
    Aug 9, 2023
    Messages:
    14
    Likes Received:
    9

    Attached Files:

    Misterg likes this.
  20. Misterg

    Misterg Journeyman
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 27, 2022
    Messages:
    268
    Likes Received:
    213
    Sorry, I didn't post one for that macro! :oops:

    Thanks for the files - I think I know what's causing it (it's a bug in the code). Leave it with me for a day, or so.
     
    Niuulh and Peter Van Der Walt like this.
  21. Niuulh

    Niuulh New
    Builder

    Joined:
    Aug 9, 2023
    Messages:
    14
    Likes Received:
    9
    You're the best :D
     
    Misterg likes this.
  22. Misterg

    Misterg Journeyman
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 27, 2022
    Messages:
    268
    Likes Received:
    213
    @Niuulh

    Thanks for your patience. I have corrected what I think was causing the error, but I can't replicate it on my system (either my processor is slower, or there are subtle differences between the way that GRBL_Hal and GRBL_ESP32 behave ).

    I have also added code to manage the case where there is insufficient Z+ travel to return to the original position and have set the default option to ignore the 'homed status' reported by Control (it's too much of a PITA!).

    Would you mind testing the updated macro attached to this post? I have tested it on my machine, but please proceed with caution.

    Let me know what happens. If there are still problems, please could you post the console 'Information' -> 'others' messages and the serial log again?

    (If all is OK, I'll update the post on the other thread.)

    Thanks.

    [Edit - file deleted as it didn't achieve anything - if anyone wants a copy just drop me a PM]
     
    #112 Misterg, Sep 4, 2023
    Last edited: Sep 6, 2023
    Niuulh and Peter Van Der Walt like this.
  23. Niuulh

    Niuulh New
    Builder

    Joined:
    Aug 9, 2023
    Messages:
    14
    Likes Received:
    9
    It's my pleasure if i can contribute even a little. I was used to tool offset with my previous mill and it's a pain without it so thank you so much for working on it.

    I have find a way to replicate all error i encounter, i'll go step by step.

    With macro paste as is, it got stuck everytime on G21, my mill already is in mm mode so i delete all G21 lines.
    Without G21 it got stuck everytimes on G4, so i deletes all G4 lines as well.

    Without G21 and G4 line it work like a charm if my work origin are set to my machine origin.
    As soon as i set my work origin on my part (aprox 70mm lower out of 120 travel) errors start to kick in.
    Could it be that the macro try to travel to work coords instead of machine coords ?
     

    Attached Files:

  24. Misterg

    Misterg Journeyman
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 27, 2022
    Messages:
    268
    Likes Received:
    213
    Hi, and thankyou.

    What is your G30 setting?

    Are you probing the tool length from near the surface of the work? If so, you may need to reduce the seek distance for the tool setter (window.tc_seekdistance). It looks like you have it set to 60mm (default 45mm). Work surface offset of 70mm + 60mm seek distance is > machine Z travel of 120mm.

    However, there is something bigger happening here that I don't understand...:confused:

    The macro is sending the following GCode as a single block

    Code:
           G21
                        G38.3 Z-60 F200
                        G4 P0.4
                        $J=G91 G21 Z2 F1000
    
    Your log shows error 9 at the G21 and again at the G4 when you deleted the G21. This didn't happen in your original logs - these commands went through OK, and the code here is unchanged. The G21 / G4 commands themselves aren't causing the problem, it's the controller objecting to being sent a stream of commands - I don't understand why your controller isn't queueing the commands. (The previous version of the macro did send two strings of commands without waiting for the first to complete which, I believe was causing your original error, however it didn't cause an error on my controller. This has now been fixed.)

    What controller are you using? Do you know what compatability level GRBLhal is using?

    (If anyone can help, the actual code is:

    Code:
                    var tc_probe =  `
                        G21                    ;set mm mode
                        G38.3 Z-` + tc_seekdistance + ` F` + tc_seekspeed + ` ;probe using parameters at the top of the macro
                        G4 P0.4                ;pause
                        $J=G91G21Z` + tc_retract + `F1000    ;jog up by retract paramter at the top of the macro
                        `
                    socket.off('prbResult'); // Disable old listeners
                    socket.emit('runJob', {
                        data: tc_probe,
                        isJob: false,
                        completedMsg: "",
                        fileName: ""
                    });
    
    I'm sorry, but I am at a loss to know why this is causing problems here, despite working OK on my controller (and I guess a few other people's)...
     
  25. Niuulh

    Niuulh New
    Builder

    Joined:
    Aug 9, 2023
    Messages:
    14
    Likes Received:
    9
    I did delete G4 and G21 in original too, same errors, i failed to mention it tho.
    I'm using blackbox x32, i don't know about GRBLhal compatibility.
    My G30 is set to Z-10. So distances while probing are relative to the new offset not absolute ?
    I'll try to reduce distance tomorrow and let you know.

    Don't apologies !
    For G4 and G21 it's just a report on my end just so you know, as long as it work you don't have to adjust it, it might be something wrong on my side and it does work without.
     
    #115 Niuulh, Sep 5, 2023
    Last edited: Sep 5, 2023
    Misterg likes this.
  26. David the swarfer

    David the swarfer OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 6, 2013
    Messages:
    3,277
    Likes Received:
    1,834
    getting errors for g21 and G4 are fundamental problems that should NOT be happening at all.
    I suspect you have the wrong kind of line endings in your macro. Are you using a Mac?
     
    Misterg likes this.
  27. Misterg

    Misterg Journeyman
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 27, 2022
    Messages:
    268
    Likes Received:
    213
    That should be OK, then - probing distances are relative to G30. I had another look at your logs and I don't think you were getting the error I thought you were.

    I've attached another couple of files if you wouldn't mind trying them. They are zipped* JSON files that can be imported as an openbuilds macro after they have been unpacked (import macro button). This will eliminate something funny happening to the line endings during the cut-paste process for text files.

    V1.5 may work (I have changed something silly - don't spend any time on it if it does the same as before).
    V1.6 is something speculative to try if V1.5 doesn't work.

    After that, I am really out of ideas!

    Thanks :)

    *The forum software doesn't allow JSON files to be posted directly.

    [Edit - files deleted as they didn't solve the problem :( ]
     
    #117 Misterg, Sep 5, 2023
    Last edited: Sep 6, 2023
    Niuulh likes this.
  28. Misterg

    Misterg Journeyman
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 27, 2022
    Messages:
    268
    Likes Received:
    213
    I'm not using a Mac, not sure about the OP, but hopefully directly importing the JSON files will eliminate the possibility of anything funny happening when moving text files about. (I don't get any errors at all and can't recreate the problem :confused: ).

    Will see what happens with the last 2 files...
     
    Niuulh and Peter Van Der Walt like this.
  29. Niuulh

    Niuulh New
    Builder

    Joined:
    Aug 9, 2023
    Messages:
    14
    Likes Received:
    9
    I get same errors for 1.5 and 1.6.
    I try to remove G21 and G4 on 1.6 to see if it's any different and got weird result

    Home
    set work origine to machine origine
    probe reference tool (ok)
    probe new tool (ok)
    probe new tool (ok)
    probe new tool (ok)
    set work origine on my part (-80ish)
    probe new tool (ok)
    probe new tool (error 9 on G38.3)
    probe new tool (same error)

    So error now doesn't seem related to Z, i don't get what's triggers it, i sended you all files
     

    Attached Files:

    Misterg likes this.
  30. Misterg

    Misterg Journeyman
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 27, 2022
    Messages:
    268
    Likes Received:
    213
    Nor me :(

    Possibly the last roll of the dice: I have reformatted all of the GCode strings to have explicit '\n' character as the new line - Try this carefully to see what happens. N.B. I haven't checked this version on an actual machine, so be cautious.

    I have one question for the likes of @David the swarfer or @Peter Van Der Walt :

    What is the significance of the ' isJob: ' item in the following snippet (example):

    Code:
     
                var tc_goback = "G21\nG90\nG53 G0 Z-5\nG0 X10 Y10\n";
    
            socket.emit('runJob', {
                    data: tc_goback,
                    isJob: false,
                    completedMsg: "",
                    fileName: ""
                });   
    Should it be set to 'true' / 'false' / "yes" / "no" or something else for this usage? (Currently set to false)

    Thanks.

    [edit - file removed as it didn't work]
     
    #120 Misterg, Sep 6, 2023
    Last edited: Sep 15, 2023
    Niuulh likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice