M6 remap problem

More
29 Dec 2015 22:14 #67468 by bobobo
M6 remap problem was created by bobobo
Dear
I am working on getting my toolchanger to work... but have some trouble.

I have done a remap of M6, executing an O-word macro "toolchange.ngc".
The toolchange.ngc start by moving Z to zero and align spindle by M19 and then calls a couple of M-codes: M10, M21, M22 etc.
The M10, M22 etc are also made by remapping and O-word macros.
Each custom M word performs a move of the toolchanger by M64, M65 and M66 commands. Move carousel down, Rotate carousel to pocket P, etc.

Each individual of the custom M words works great in mdi. Also M19 works great in mdi.

But my problem is that when I run "M6 T2" nothing moves. Print-messages that I put into the code is displayed, but nothing moves nor io are working. Not even the first line in toolchange.ngc: G53 G0 Z0 is performed, but the print-messages 10-20 lines later are displayed.
Even print-messages that are put after M66 that is waiting for signals from sensors that will be activated first after a move has been done, are displayed.

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

More
29 Dec 2015 22:50 #67471 by bobobo
Replied by bobobo on topic M6 remap problem
And here are some code:
ini-file
...
[RS274NGC]

# File containing interpreter variables
PARAMETER_FILE = Leadwell_hm2-servo.var
# 5450 used to remember carousel position, pocket number facing to spindle.
# 5451 used to remember tool in spindle after power cycle. 

SUBROUTINE_PATH = ./

#See python-stdglue for prolog and epilog handlers
REMAP=M6   modalgroup=6 prolog=change_prolog ngc=toolchange epilog=change_epilog
REMAP=M10  modalgroup=6 argspec=p ngc=m10
REMAP=M11  modalgroup=6 argspec=p ngc=m11
REMAP=M12  modalgroup=6 argspec=p ngc=m12
REMAP=M21  modalgroup=6 ngc=m21
REMAP=M22  modalgroup=6 ngc=m22
REMAP=M23  modalgroup=6 ngc=m23
REMAP=M24  modalgroup=6 ngc=m24
REMAP=M25  modalgroup=6 ngc=m25
REMAP=M26  modalgroup=6 ngc=m26

#RS274NGC_STARTUP_CODE = G17 G21 G40 G49 G64 P0.001 G80 G90 G94 G97 G98 M61 Q[#5451]

[PYTHON]
TOPLEVEL=./toplevel.py
PATH_APPEND= ./
#PATH_APPEND= ./python-stdglue/
...

toolchange.ngc
o<toolchange> sub
(print, o<toolchange>)
G53 G0 Z0
M19 P0 Q10 ;align the spindle
(print, spindle aligned)
; only unload the tool if there is a tool in the spindle 

O100 IF [#<tool_in_spindle> GT 0]
(print, remove tool)
    M10 P[#<tool_in_spindle>] 
;Align carousel
    M21 
;Carousel right
    M26 
;Tool unclamp
    M24 
;Carousel down
    #5451 = 0  
;Set persistent variable to remember tool in spindle after power cycle
O100 ENDIF

O200 IF [#<selected_tool> GT 0]
(print, insert tool)
    M10 P#<selected_pocket> ;set the carousel to move to the right pocket
    M24 ;Carousel down
    M21 ;Carousel right
    M26 ;Tool unclamp
    M23 ;Carousel up
    M25 ;Tool clamp
    #5451 = #<selected_tool> ;Set persistent variable to remember tool in spindle after power cycle
O200 ENDIF 

(print, return tool magazine)
M22 ;Carousel left
M23 ;Lift carousel up (If no tool selected, else already up)

o<toolchange> endsub [1]

M2

M10.ngc
o<m10> sub

; Move tool carousel best direction to pocket P
; Parameter #5450 is used to track the current tool pocket (persistently)

#<steps> = [#5450 - #<p>]
(print, o<M10> P#<p>, steps=#<steps>)
o1000 if [#<steps> GT 10]
    #<steps>=[#<steps> - 20]
o1000 endif
o1001 if [#<steps> LT -10]
    #<steps>=[#<steps> + 20]
o1001 endif


o1003 if [#<steps> GT 0]

    M12 P[#<steps>]
o1003 elseif [#<steps> LT 0]
    #<steps>=[#<steps> * -1]
    M11 P[#<steps>]
o1003 endif

o<m10> endsub [1]

M2

M12.ngc
o<m12> sub

; Move tool carousel CCW Parameter P number of steps
; Without parameter one step CCW.
; Parameter #5450 is used to track the current tool pocket (persistently)
(print, o<M12> P#<p>)
O100 if [EXISTS[#<p>]]
   #<Steps_to_move> = #<p>
O100 else
   #<Steps_to_move>=1
O100 endif

M64 P4 ; Set backward dir to motor
G4 P0.5 (wait for 0.5 seconds before proceeding)
M64 P3 ; Run motor

O110 do
   M66 P8 L2 Q3 ; wait for negative edge on rotation index
   O120 if [#5399 LT 0]
      (abort, failed to get rotation index)
   O120 endif
   #5450 = [[[#5450-2] MOD 20]+1]    ;Pocket is no.1-20
   #<Steps_to_move> = [#<Steps_to_move>-1]
O110 while [#<Steps_to_move> GT 0]
M65 P3 ; Stop motor
M65 P4 ; Reset direction
o<m12> endsub [1]

M2

Sometimes but not always is the last printout "return tool magazine" shown, but nothing has been moving.
I have tried M6 T2 both in mdi and in a short g-code file.
The following user(s) said Thank You: akb1212, CNCCustoms

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

More
30 Dec 2015 10:59 #67501 by bobobo
Replied by bobobo on topic M6 remap problem
I got it working now.

I was missing those lines in hal:
# create signals for tool loading loopback
net tool-prep-loop iocontrol.0.tool-prepare => iocontrol.0.tool-prepared
net tool-change-loop iocontrol.0.tool-change => iocontrol.0.tool-changed

I thought that was handled in the prolog/epilog, but apparantly not when I read manual more carefully.

But I still find it a bit strange how the interpreter can read so long ahead and write the debug messages without waiting for the sensor replies to M66, how is timeouts handled then... because if a timeout happens the interpreter should execute other code than if the timeout doesnt happens

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

More
04 Jan 2018 20:18 #104031 by CNCCustoms
Replied by CNCCustoms on topic M6 remap problem
Hi.. I'm trying g to do a similar thing. How did you connect the carousel signals in your hal file?

Would you mind sharing?

Thank you.

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

More
21 Jan 2018 11:47 #104776 by andypugh
Replied by andypugh on topic M6 remap problem

But I still find it a bit strange how the interpreter can read so long ahead and write the debug messages without waiting for the sensor replies to M66, how is timeouts handled then... because if a timeout happens the interpreter should execute other code than if the timeout doesnt happens


The interpreter stops at "queue busters" such as a tool change or wait-for-input. As you have noticed, it has to.

But: The graphical preview runs through all the code once too, to create the preview, and errors can be triggered at that point too.
(Code that depends on inputs will generally not display properly in the preview either)

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

Time to create page: 0.135 seconds
Powered by Kunena Forum