Remap M6 with subroutines - help needed to sort out errors

More
08 Oct 2021 17:48 - 08 Oct 2021 18:08 #222568 by viesturs.lacis
Hello!

I am retrofitting Biesse machine and I am down to last task - setting up automatic tool change. Good news is that it is a machine from 1993, so the toolchange is simple - there are 5 separate tool holders, so basically I am dealing with rack toolchange. There is a user "bevins" in these forums, who also has retrofitted a Biesse machine and he did remap of M6 in python. I found his github repo and copied his config. But the thing is that I am pretty bad at programming in general and python is something I totally do not understand. So I tried to remap with subroutines as that should not be really hard.
Those tool posts have experienced some impact and damage as the distance between them is not identical. They are mounted along Y axis and the distance between varies by 1-2 milimeters. First one is bent in X direction as well, so I decided to have separate subroutine for each tool slot for unloading and also for loading the tool. That makes total of 10 subroutines to be called from main remap subroutine, based on current tool in spindle (for unloading) and number of requested tool for loading.
I have sorted all the inputs and outputs and wrote the subroutines, but I am getting errors on LinuxCNC startup. Here is the main subroutine:
o<tool_change> sub

M73 (auto-restore modal settings on return)

(MSG, Tool_change: loaded tool=#<_current_tool> current pocket: #<_current_pocket>;)
(MSG, Tool_change: selected tool=#<_selected_tool> selected pocket: #<_selected_pocket>;)

M64 P01 (raise spindle2 up)
G04 P01
M65 P01
M64 P02 (lower spindle1 down in case it is not down)
G04 P01
M65 P02
M66 P02 L3 (make sure that spindle1 is down)

M66 P10 L3 (make sure that all slots are down)

M64 P03 (open the cover of tool slots)
G04 P0.5
M65 P03
M66 P03 L3 (make sure that the cover is open)


(unload previous tool)
o100 if [#<_current_pocket> = 1]
M66 P05 L0 (check, if slot1 is empty)
o101 if [#5399 = 0]
o<tool1_out> call
o101 else (MSG, Pocket 1 is not empty)
o101 endif

o100 elif [#<_current_pocket> = 2]
M66 P06 L0 (check, if slot2 is empty)
o102 if [#5399 = 0]
o<tool2_out> call
o102 else (MSG, Pocket 2 is not empty)
o102 endif

o100 elif [#<_current_pocket> = 3]
M66 P07 L0 (check, if slot3 is empty)
o103 if [#5399 = 0]
o<tool3_out> call
o103 else (MSG, Pocket 3 is not empty)
o103 endif

o100 elif [#<_current_pocket> = 4]
M66 P08 L0 (check, if slot4 is empty)
o104 if [#5399 = 0]
o<tool4_out> call
o104 else (MSG, Pocket 4 is not empty)
o104 endif

o100 elif [#<_current_pocket> = 5]
M66 P09 L0 (check, if slot3 is empty)
o105 if [#5399 = 0]
o<tool5_out> call
o105 else (MSG, Pocket 3 is not empty)
o105 endif

o100 endif

(go to new tool)
o200 if [#<_selected_pocket> = 1]
M66 P14 L0 (check, if spindle1 is empty)
o201 if [#5399 = 0]
o<tool1_in> call
o201 else (MSG, Spindle is not empty)
o201 endif

o200 elif [#<_selected_pocket> = 2]
M66 P14 L0 (check, if spindle1 is empty)
o202 if [#5399 = 0]
o<tool2_in> call
o202 else (MSG, Spindle is not empty)
o202 endif

o200 elif [#<_selected_pocket> = 3]
M66 P14 L0 (check, if spindle1 is empty)
o203 if [#5399 = 0]
o<tool3_in> call
o203 else (MSG, Spindle is not empty)
o203 endif

o200 elif [#<_selected_pocket> = 4]
M66 P14 L0 (check, if spindle1 is empty)
o204 if [#5399 = 0]
o<tool4_in> call
o204 else (MSG, Spindle is not empty)
o204 endif

o200 elif [#<_selected_pocket> = 5]
M66 P14 L0 (check, if spindle1 is empty)
o205 if [#5399 = 0]
o<tool5_in> call
o205 else (MSG, Spindle is not empty)
o205 endif

o200 endif

M66 P10 L3 (make sure all slots are down before closing the cover)
M64 P04 (close the cover)
G04 P0.5
M65 P05
M66 P04 (make sure that cover is closed)

o<tool_change> endsub
M2

With this subroutine on LinuxCNC startup I am getting error (and empty preview window):
Near line 0 of /usr/share/axis/images/axis.ngc:
Zero timeout with wait type != immediate return

If I comment out all M66 commands, the error message changes to this:
Near line 0 of /usr/share/axis/images/axis.ngc:
Unknown operation

If I comment out all the conditional statements if/elseif/endif, then LinuxCNC starts up correctly.
So I have 2 questions:
1) what is wrong with my M66 commands? they are meant to ensure that particular input is true before moving on.
2) what is wrong with those conditional statements? I copied them from an example and I have no idea, what is wrong. I even tried simplified version like this:
o100 if [#5220 = 1]
o<tool1_out> call
endif

But I still got an error of unknown operation.

I would appreciate any help with understanding, what am I missing and what is not correct. Maybe someone could share a working example that I could adjust?
Last edit: 08 Oct 2021 18:08 by viesturs.lacis.

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

More
08 Oct 2021 17:52 #222569 by viesturs.lacis
aaaaargghhh I made just one small edit and suddenly those code tags are all messed up. sorry about that, I have no idea, how to fix it. every time I press edit and submit, it actually gets worse!

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

More
08 Oct 2021 18:02 #222572 by chris@cnc
Corner left the source button. Edit html code
 
Attachments:

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

More
08 Oct 2021 18:09 #222574 by viesturs.lacis
oh, thank you, did not know about that option!
hopefully now it is easier to read... I really need some suggestions as I am totally out of ideas, how to proceed

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

More
12 Oct 2021 20:41 #222970 by andypugh

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

More
13 Oct 2021 08:09 #223008 by viesturs.lacis
I have LinuxCNC 2.8.2 installed on my machine and I was having lots of error messages about my subroutines. Several times I tried to start from scratch, using sample configs.
I my last attempt I was trying to run remap/rack-toolchange and got an error on LinuxCNC startup about the g-code file, it should open by default...
Either there is something wrong with my system (I will do complete reinstall in the evening) or there is a bug in 2.8.2 version. Because yesterday I was testing the same remap/rack-toolchange sample config in fresh install with 2.8.0 and it worked just fine and I was able to adjust it for the specifics of my machine while running it in sim mode.

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

More
18 Oct 2021 13:34 #223453 by viesturs.lacis
I have managed to get the remap working, problem solved! I did it in g-code with subroutines.
Now there is one thing that I know will annoy the operator - if I leave a tool in spindle on shutdown, after restart the tool number is lost.
Is that correct behavior? Do I always have to unload tool from spindle on shutdown?

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

More
21 Oct 2021 23:36 #223853 by andypugh
I have had a bit of a play around with this.

Firstly, if you set
[EMCIO]
RANDOM_TOOLCHANGER = 1
then the tool in spindle is retained.

This migth work OK in your case, or might completely mess up the toolchanger?

Otherwise:

If you add 5400 to the .var file then LinuxCNC will write the tool number out to the .var file on shutdown.

However it will not read it back in at startup. It actively sets #5400 to zero rather than reading it from the file.

But, it's part of a possible answer.

In your case, you have a remap running, so I would suggest creating a _new_ persistent parameter and setting that to the tool number inside the remap.

I tried adding M61 Q2 (as an experiment) to RS274NGC_STARTUP_CODE but that didn't work. In fact it prevents LinuxCNC from starting up.

I can imagine a userspace Python module that sits in the HAL waiting for homing to complete, and then setting a G61 Q#5000 or, potentially, parsing the .vars file for #5400 and then issuing a G61.

FWIW Gmoccapy has internal logic to handle this.

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

Time to create page: 0.088 seconds
Powered by Kunena Forum