Remap M6: Is this philosophy possible?

  • zz912
  • zz912's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
07 Apr 2023 16:52 #268532 by zz912
Replied by zz912 on topic Remap M6: Is this philosophy possible?
With this I consider my question closed and I would like to thank you.

Based on your help I can tell my Remap philosophy IS possible.
I want the python code to at least touch LCNC outside of HAL.
So I will have a HAL component named "remap-python" or "atc-python" or "control-python".
My python code will only control such components. The output pins of these components will be connected to the rest of the HAL components. At the same time, these components can serve as a 'steering' component, as you wrote.

I would like to ask you if it is possible to run the python code after loading LCNC?
I would need to diagnose my CNC and only then allow work on this machine.
I use Gmoccapy.

 

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

  • zz912
  • zz912's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
12 Apr 2023 15:36 #268902 by zz912
Replied by zz912 on topic Remap M6: Is this philosophy possible?
Hello,

I am trying to remake my Remap from O-word to python only.

At first I only had:
REMAP = M6 modalgroup=6 python=remap_m6

It doesn't work for me, so I split it up again
REMAP = M6 modalgroup=6 prolog=change_prolog python=remap_m6 epilog=change_epilog

But it still doesn't work.
Question #1 Do I have to use epilog and prolog if I only want python?

Here is my code:
#!/usr/bin/env python3
import hal, time
import linuxcnc
import sys
import emccanon
from interpreter import *
from emccanon import MESSAGE
#throw_exceptions = 1



def change_prolog(self, **words):
    try:
        if self.selected_pocket < 0:
            self.set_errormsg("M6: žádný nástroj není zvolen")
            return INTERP_ERROR
        if self.cutter_comp_side:
            self.set_errormsg("Nemůže proběhnout výměna nástrojů se zapnutou korekcí")
            return INTERP_ERROR
        s = linuxcnc.stat() # create a connection to the status channel
        s.poll() # get current values
        if s.actual_position[2] > 0.1:
            self.set_errormsg("Nejdříve sjeď osou Z dolů")
            return INTERP_ERROR
        if not (s.homed.count(1) == s.joints):
            self.set_errormsg("Zreferuj nejdříve stroj")
            return INTERP_ERROR
        otacky = hal.get_value("hm2_7i96.0.encoder.00.velocity")
        if (otacky > 0.1 or otacky < -0.1):
            self.set_errormsg("Vřeteno se stále točí")
            return INTERP_ERROR
        self.params["tool_in_spindle"] = self.current_tool
        self.params["selected_tool"] = self.selected_tool
        self.params["current_pocket"] = self.current_pocket
        self.params["selected_pocket"] = self.selected_pocket
    except Exception as e:
        self.set_errormsg("M6/change prolog: %s" % (e))
        return INTERP_ERROR


def remap_m6(self, **words):
    try:
        self.execute("G53 G0 Z0")  #najeti do polohy pro zacatek vymeny
        self.execute("G49")  #zruseni korekcí nástroje
        self.execute("M19 R90 Q20")  #natočení vřetene
        hal.set_p("atc.0.py-z-limit-atc","True")  #zvetseni soft limitu
        time.sleep(30)
        self.execute("G53 G1 Z195 f2000")  #vyjeti vretenem nahoru
        #cekani-kontrola najeti horniho snimace ATC)
        self.execute("f50")  #nastaveni minimalni rychlosti
        
       
        hal.set_p("atc.0.py-carousel-en","1")  #spuštění otáčení karuselu
        
        #čekání dokud se karusel nedotočí
        carousel_enable = hal.get_value("carousel.0.ready")
        while (carousel_enable == 0):
            time.sleep(0.1)
            carousel_enable = hal.get_value("carousel.0.ready")
      
        self.execute("G53 G1 Z0 f2000")  #najeti do polohy pro vymenu
        hal.set_p("atc.0.py-z-limit-atc","False")  #puvodni soft limit
        self.execute("G43") #zapnuti korekce nástroje
        self.execute("M5") #vypnutí polohování vřetene             
        self.execute("f50") #nastaveni minimalni rychlosti        
        
        return INTERP_OK


        
    except Exception as e:
        self.set_errormsg("M6/change: %s" % (e))
        
        #hal.set_p("atc.0.py-z-limit-atc","0")  #puvodni soft limit
        
        return INTERP_ERROR
        



def change_epilog(self, **words):
    try:
        if not self.value_returned:
            r = self.blocks[self.remap_level].executing_remap
            self.set_errormsg("the %s remap procedure %s did not return a value"
                             % (r.name,r.remap_ngc if r.remap_ngc else r.remap_py))
            yield INTERP_ERROR

        if self.blocks[self.remap_level].builtin_used:
            #print "---------- M6 builtin recursion, nothing to do"
            yield INTERP_OK
        else:
            if self.return_value > 0.0:
                # commit change
                self.selected_pocket =  int(self.params["selected_pocket"])
                emccanon.CHANGE_TOOL(self.selected_pocket)
                self.current_pocket = self.selected_pocket
                self.selected_pocket = -1
                self.selected_tool = -1
                # cause a sync()
                self.set_tool_parameters()
                self.toolchange_flag = True
                yield INTERP_EXECUTE_FINISH
            else:
                # yield to print any messages from the NGC program
                yield INTERP_EXECUTE_FINISH
                self.set_errormsg("M6 aborted (return code %.1f)" % (self.return_value))
                yield INTERP_ERROR
    except Exception as e:
        self.set_errormsg("M6/change epilog: %s" % (e))
        yield INTERP_ERROR

This code behaves very strangely. When I enter the M6 T5 command in MDI, linuxCNC freezes for about 5 seconds, then the LCNC behaves as if the M6 T5 command is executed, then it is necessary to wait about 30 seconds, and suddenly, out of nowhere, the code starts running.

I also have the problem that the command does not work for me:
hal.set_p("atc.0.py-carousel-en","1") 

Can I ask somebody for help?

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

  • zz912
  • zz912's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
12 Apr 2023 19:36 #268926 by zz912
Replied by zz912 on topic Remap M6: Is this philosophy possible?
I solved problems before, but I have new problem.
#!/usr/bin/env python3
import hal, time
import linuxcnc
import emccanon
from interpreter import *
from emccanon import MESSAGE
from util import lineno
throw_exceptions = 1



def remap_m6(self, **words):
    try:
        if self.selected_pocket < 0:
            self.set_errormsg("M6: žádný nástroj není zvolen")
            yield INTERP_ERROR
        if self.cutter_comp_side:
            self.set_errormsg("Nemůže proběhnout výměna nástrojů se zapnutou korekcí")
            yield INTERP_ERROR
        s = linuxcnc.stat() # create a connection to the status channel
        s.poll() # get current values
        if s.actual_position[2] > 0.1:
            self.set_errormsg("Nejdříve sjeď osou Z dolů")
            yield INTERP_ERROR
        if not (s.homed.count(1) == s.joints):
            self.set_errormsg("Zreferuj nejdříve stroj")
            yield INTERP_ERROR
        #otacky = hal.get_value("hm2_7i96.0.encoder.00.velocity")
        #if (otacky > 0.1 or otacky < -0.1):
        #    self.set_errormsg("Vřeteno se stále točí")
        #    yield INTERP_ERROR
        self.params["tool_in_spindle"] = self.current_tool
        self.params["selected_tool"] = self.selected_tool
        self.params["current_pocket"] = self.current_pocket
        self.params["selected_pocket"] = self.selected_pocket



        self.execute("G53 G0 Z0",lineno())  #najeti do polohy pro zacatek vymeny
        self.execute("G49",lineno())  #zruseni korekcí nástroje
        #self.execute("M19 R90 Q20",lineno())  #natočení vřetene
        
        hal.set_p("atc.0.py-z-limit-atc","True")  #zvetseni soft limitu
        hal.set_p("ini.z.max_limit","200")
        
        # Wait for results
        #yield INTERP_EXECUTE_FINISH
        
        self.execute("G53 G1 Z-195 f2000",lineno())  #vyjeti vretenem nahoru
        #cekani-kontrola najeti horniho snimace ATC)
        self.execute("f50",lineno())  #nastaveni minimalni rychlosti
        
        """
        hal.set_p("atc.0.py-carousel-en","1")  #spuštění otáčení karuselu
        
        #čekání dokud se karusel nedotočí
        carousel_enable = hal.get_value("carousel.0.ready")
        while (carousel_enable == 0):
            time.sleep(0.1)
            carousel_enable = hal.get_value("carousel.0.ready")
        """
        self.execute("G53 G1 Z0 f2000",lineno())  #najeti do polohy pro vymenu
        
        # Wait for results
        yield INTERP_EXECUTE_FINISH
        
        hal.set_p("atc.0.py-z-limit-atc","False")  #puvodni soft limit
        hal.set_p("ini.z.max_limit","10")
        time.sleep(0.1)
        
        self.execute("G43",lineno()) #zapnuti korekce nástroje
        self.execute("M5",lineno()) #vypnutí polohování vřetene             
        self.execute("f50",lineno()) #nastaveni minimalni rychlosti        
        
        yield INTERP_OK


        
    except Exception as e:
        self.set_errormsg("M6/change: %s" % (e))
        
        #hal.set_p("atc.0.py-z-limit-atc","0")  #puvodni soft limit
        
        yield INTERP_ERROR


The problem is that if I don't use yield INTERP_EXECUTE_FINISH, my python code doesn't work properly.

If I use the yield INTERP_EXECUTE_FINISH, the python code works correctly for me, but it ends with a signal 11 error, see the image.
 
 
Attachments:

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

Time to create page: 0.061 seconds
Powered by Kunena Forum