Welcome to Our Community

Some features disabled for guests. Register Today.

GRBL: Need to run gcode between two homing cycles

Discussion in 'Controller Boards' started by Ankit Kumar, Nov 19, 2022.

  1. Ankit Kumar

    Builder

    Joined:
    Jun 23, 2022
    Messages:
    16
    Likes Received:
    3
    Hi, I am using grbl to control two different axes (X and Z) and want to run a piece of gcode after the X-homing cycle but before the Z-homing cycle. I understand how to set the order of homing cycle in config.h file, but unsure how to implement g-code execution in the middle. Any help would be much appreciated.
    Also, thanks in advance!
     
  2. Brian Slee

    Brian Slee Well-Known
    Builder

    Joined:
    Apr 26, 2014
    Messages:
    191
    Likes Received:
    59
    You can edit the .nc file using a text editor. Just open the file, insert the commands you want to execute in between the homing cycles and save. If you are using a windows app like notepad check your file extension after saving to make sure it didn't save as a .txt file, you might have to go back and re-change the file name extension back to .nc using the command line because windows explorer won't let you change extensions anymore.
     
  3. Ankit Kumar

    Builder

    Joined:
    Jun 23, 2022
    Messages:
    16
    Likes Received:
    3
    Hi Brian, thanks for your help. However, I don't see any file with '.nc' extension in the grbl library (please see screenshot: Screenshot-2022-11-19-at-5-16-51-PM).
     
  4. Brian Slee

    Brian Slee Well-Known
    Builder

    Joined:
    Apr 26, 2014
    Messages:
    191
    Likes Received:
    59
    .nc is basically a text file that grbl reads and executes line by line. I am using Candle to execute my programs and it displays the file contents in a box below the operational display Candle also allows you to paste new codes into the the uploaded file but I don't think there is a way to save the changes.
     
    Ankit Kumar likes this.
  5. Ankit Kumar

    Builder

    Joined:
    Jun 23, 2022
    Messages:
    16
    Likes Received:
    3
    That's a good approach but won't work for me because I want the changes to be saved in the firmware. Thanks anyway for the suggestion!
     
  6. David the swarfer

    David the swarfer OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 6, 2013
    Messages:
    3,238
    Likes Received:
    1,815
    Homing is a fundamental stage of a machine 'coming alive' and there is no way to run Gcode between X homing and Z homing because the Gcode will not do
    safe, known, moves because homing is not yet finished.
    Therefore, the answer is "no, you cannot do this with GRBL"

    (but it might be possible with grblHAL)
     
    Ankit Kumar likes this.
  7. sharmstr

    sharmstr OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 23, 2018
    Messages:
    2,030
    Likes Received:
    1,428
    David has a very valid point. Also, you'd need to be certain that Z is in a safe position before initiating your custom homing. Unless of course you're not actually wanting to "move" and want to do something else like trigger a relay.

    But if it is something you want to do, cant you just enable single axis homing in config.h? Then use a macro to home X, run code, then home Z?

    $HX
    some gcode
    $HZ

    I've never tried it, but it starts on line 120: grbl/config.h at bfb67f0c7963fe3ce4aaf8a97f9009ea5a8db36e · gnea/grbl
     
    Peter Van Der Walt likes this.
  8. Peter Van Der Walt

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

    Joined:
    Mar 1, 2017
    Messages:
    13,751
    Likes Received:
    4,070
    What exactly is the gcode you want to run between the cycles?
     
  9. Ankit Kumar

    Builder

    Joined:
    Jun 23, 2022
    Messages:
    16
    Likes Received:
    3
    Thanks, Shawn! I didn't know that the X and Z axes could be homed separately.
     
    #9 Ankit Kumar, Nov 20, 2022
    Last edited: Nov 20, 2022
    sharmstr likes this.
  10. Ankit Kumar

    Builder

    Joined:
    Jun 23, 2022
    Messages:
    16
    Likes Received:
    3
    Hi Peter, I have assigned Z-axis to the stepper of a pump that I designed, and the X-axis is assigned to another stepper controlling a four-way valve. After homing the X-axis, I want the valve to be in a specific position (that I can control using position gcode) before I home the Z-axis.
     
  11. David the swarfer

    David the swarfer OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 6, 2013
    Messages:
    3,238
    Likes Received:
    1,815
    then you only need to set the X homing pulloff distance to the correct value.
    Then it will home and pulloff to the settting you want, then home Z
     
    sharmstr and Peter Van Der Walt like this.
  12. Ankit Kumar

    Builder

    Joined:
    Jun 23, 2022
    Messages:
    16
    Likes Received:
    3
    Thanks for your reply David; this sounds promising! However, I don't see a way to define axis-specific homing pull-off distance. The only option I see in GRBL 1.1 is $27, which seems to affect all axes.
     
  13. Peter Van Der Walt

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

    Joined:
    Mar 1, 2017
    Messages:
    13,751
    Likes Received:
    4,070
    Wouldn't it be better to run native Arduino code so you have full control over all this? AccelStepper: AccelStepper library for Arduino
     
  14. Ankit Kumar

    Builder

    Joined:
    Jun 23, 2022
    Messages:
    16
    Likes Received:
    3
    Thanks for the suggestion, Peter. I have built a gcode generator for my application and don't want to restart from ground zero. If I could figure out a way to define axis-specific pull-off distance, it'll save me a lot of trouble.
     
  15. Peter Van Der Walt

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

    Joined:
    Mar 1, 2017
    Messages:
    13,751
    Likes Received:
    4,070
    Custom firmware can still be made to respond to gcodes GitHub - tgolla/GCodeParser: The GCode parser is designed to parse GCode in order that it can then be processed.
    As it doesn't sound like its a CNC device you built, the limitations of a CNC firmware will always exist. CNC tools (firmwares, gcode, etc) are not ideally meant to control pumps and valves after all. A custom piece of simple firmware would actually be far less complicated
     
  16. Ankit Kumar

    Builder

    Joined:
    Jun 23, 2022
    Messages:
    16
    Likes Received:
    3
    I wasn't familiar with the GCode parser. I'll look into it; thanks again!!
     

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