No parameters forwarded to M6 script?

More
16 Mar 2025 13:59 #324050 by tsaG
Hi,

I am currently writing my own tool changer script for my rack. However, my problem is that the parameters like "#<selected_tool> or #<tool_in_spindle> are not forwarded to the script. I can see that these are normally handled by the stdglue.py script. The "standard" tool changer script also doesn't work (with the same issue). If I hardcode the #<selected_tool> to 1, I get the error for the next variable (<tool_in_spindle>).

My ini looks like this:
[RS274NGC]
RS274NGC_STARTUP_CODE = F10 S300 G21 G17 G40 G49 G54 G64 P0.001 G80 G90 G91.1 G92.1 G94 G97 G98
REMAP = M6 modalgroup=6 ngc=toolchange
PARAMETER_FILE = linuxcnc.var
OWORD_NARGS = 1
NO_DOWNCASE_OWORD = 1
SUBROUTINE_PATH = subroutines
 

whereas my Hal file has the three nets connected
net tool-number              <= iocontrol.0.tool-prep-number
net tool-change-loop         iocontrol.0.tool-change => iocontrol.0.tool-changed
net tool-prep-loop           iocontrol.0.tool-prepare => iocontrol.0.tool-prepared

I attached my tool changer gcode and the error from the console.

 

Does anyone know what is wrong?



 
Attachments:

Please Log in or Create an account to join the conversation.

More
16 Mar 2025 14:21 - 16 Mar 2025 21:21 #324053 by tsaG
Replied by tsaG on topic No parameters forwarded to M6 script?
Okay, it seems like the std glue.py is not called at all (I added debug messages in between) so I had to revert back to the standard linuxcnc # number variables. However, I now get the error "bad number format (conversion failed) parsing". Unfortunately, without line indication. :(
%
(MSG, --- Start of toolchange.ngc [Persistent Version] ---)

o<toolchange> sub

    ; ---------------------------------------------------------------
    ; DEBUG: Display raw numeric values passed by the M6 prolog.
    ; Typically, #100 is the requested tool and #120 is the selected pocket.
    ; ---------------------------------------------------------------
    (MSG, Debug: Received #100 = [#100], #120 = [#120])

    ; ---------------------------------------------------------------
    ; A) Reverse Assignment:
    ;    The M6 prolog passes numeric variables:
    ;      #100 = requested tool number,
    ;      #120 = selected pocket.
    ;    We use persistent variables for the current tool and pocket:
    ;      #3991 holds the current tool in the spindle.
    ;      #3990 holds the current tool pocket.
    ;    Now we set descriptive variables as follows:
    ; ---------------------------------------------------------------
    #<selected_tool>      = #100
    #<tool_in_spindle>    = #3991
    #<selected_pocket>    = #120
    #<current_pocket>     = #3990

    ; ---------------------------------------------------------------
    ; DEBUG: Display the descriptive variable values after assignment.
    ; ---------------------------------------------------------------
    (MSG, Debug: selected_tool = [#<selected_tool>])
    (MSG, Debug: tool_in_spindle = [#<tool_in_spindle>])
    (MSG, Debug: selected_pocket = [#<selected_pocket>])
    (MSG, Debug: current_pocket = [#<current_pocket>])

    ; ---------------------------------------------------------------
    ; B) Check if tool change is needed:
    ;    If the requested tool equals the tool already in the spindle,
    ;    no change is needed.
    ; ---------------------------------------------------------------
    o<if_same_tool> if [#<selected_tool> EQ #<tool_in_spindle>]
        (MSG, Tool [#<tool_in_spindle>] is already in spindle. No change needed.)
        M99
    o<if_same_tool> endif

    ; ---------------------------------------------------------------
    ; C) Stop the spindle (no M19 orientation used)
    ; ---------------------------------------------------------------
    M5

    ; ---------------------------------------------------------------
    ; D) Rack Coordinates & Z Heights (adjust as needed)
    ;    Define rack X, Y base, Y pitch.
    ;    Define Z heights if not already defined in the INI:
    ;       #<atc_z_tool_change_height> = -49.5
    ;       #<atc_z_tool_clearance_height> = 0
    ; ---------------------------------------------------------------
    #<rack_x>             = 1123
    #<rack_y_base>        = 164
    #<rack_y_pitch>       = 50
    #<atc_z_tool_change_height>    = -49.5   ; if not defined in INI
    #<atc_z_tool_clearance_height> = 0       ; if not defined in INI

    ; Move Z to clearance height.
    G53 G0 Z[#<atc_z_tool_clearance_height>]

    ; ---------------------------------------------------------------
    ; E) Drop Off Old Tool:
    ;    If a tool is currently in the spindle, drop it off in the current pocket.
    ; ---------------------------------------------------------------
    o<if_drop_old_tool> if [#<tool_in_spindle> GT 0]
        ; Calculate Y coordinate for the current pocket.
        #<old_pocket_y> = [#<rack_y_base> + ([#<current_pocket>] - 1) * #<rack_y_pitch>]
        G53 G0 X[#<rack_x>] Y[#<old_pocket_y>]
        G53 G0 Z[#<atc_z_tool_change_height>]
        (MSG, Unclamping old tool [#<tool_in_spindle>] with M64 P2)
        M64 P2
        G4 P1  ; dwell 1 second
        G53 G0 Z[#<atc_z_tool_clearance_height>]
        ; Optionally: update a pocket table (#4001..#4024) if needed.
    o<if_drop_old_tool> endif

    ; ---------------------------------------------------------------
    ; F) Pick Up New Tool:
    ;    Move to the selected pocket and clamp the new tool.
    ; ---------------------------------------------------------------
    o<if_pickup_new_tool> if [#<selected_tool> GT 0]
        ; Calculate Y coordinate for the selected pocket.
        #<new_pocket_y> = [#<rack_y_base> + ([#<selected_pocket>] - 1) * #<rack_y_pitch>]
        G53 G0 X[#<rack_x>] Y[#<new_pocket_y>]
        G53 G0 Z[#<atc_z_tool_change_height>]
        (MSG, Clamping new tool [#<selected_tool>] with M65 P2)
        M65 P2
        G4 P1  ; dwell 1 second
        G53 G0 Z[#<atc_z_tool_clearance_height>]
        ; Optionally: mark that pocket empty in your pocket table.
    o<if_pickup_new_tool> endif

    ; ---------------------------------------------------------------
    ; G) Update the Spindle:
    ;    Set the new tool as the one in the spindle.
    ; ---------------------------------------------------------------
    #<tool_in_spindle> = #<selected_tool>

    ; ---------------------------------------------------------------
    ; H) Inform LinuxCNC:
    ;    Set new tool active (M61) and load tool offset (G43).
    ; ---------------------------------------------------------------
    M61 Q[#<selected_tool>]
    G43 H[#<selected_tool>]

    ; ---------------------------------------------------------------
    ; I) Update Persistent Variables:
    ;    #3991 now holds the new tool.
    ;    #3990 is updated to the selected pocket.
    ; ---------------------------------------------------------------
    #3991 = #<selected_tool>
    #3990 = #<selected_pocket>

    (MSG, The spindle now has tool [#<selected_tool>])

    ; ---------------------------------------------------------------
    ; J) Return to caller.
    ; ---------------------------------------------------------------
    M99

o<toolchange> endsub

M2

(MSG, --- End of toolchange.ngc ---)
%
Last edit: 16 Mar 2025 21:21 by tsaG.

Please Log in or Create an account to join the conversation.

More
20 Mar 2025 21:47 #324381 by tsaG
Replied by tsaG on topic No parameters forwarded to M6 script?
Okay, I found the issue why the PB remapping was not used. The python had to be activated in the ini as follows.
[PYTHON]
PATH_PREPEND = python
TOPLEVEL = python/toplevel.py


 

Please Log in or Create an account to join the conversation.

More
22 Mar 2025 13:01 #324545 by Lcvette
Replied by Lcvette on topic No parameters forwarded to M6 script?
great! glad you got it working. always refer to the sim configs if you get stuck, everything has been done there to test functionality.!

Please Log in or Create an account to join the conversation.

Moderators: KCJLcvette
Time to create page: 0.129 seconds
Powered by Kunena Forum