Time to revisit coolant mapping of M-codes in Linuxcnc

More
18 Oct 2024 18:56 #312540 by smc.collins
At some point the problem is going to be so annoying someone's going to do it, mostly looks like a lot of boiler plate.

I'm thinking using the m7 Pxxxxx format makes the most sense. I'll look into all the options and see if i can resolve on of them

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

More
18 Oct 2024 19:48 #312546 by Aciera
I cannot test this right now but looking at this makes me wonder if it could actually be this easy to add 'M7' and 'M8' to the list of remap-able Mcodes (considering that according to the documentation 'M9' should not be a remap-able Mcode somebody already seems to have done or at least tried to do something like this)  :

 
Attachments:

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

More
18 Oct 2024 19:50 #312547 by Aciera

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

More
18 Oct 2024 20:08 - 19 Oct 2024 07:45 #312549 by Aciera
Found the relevant commit, looks like the change would need to be done here (also)
'src/emc/rs274ngc/rs274ngc_interp.hh':

github.com/LinuxCNC/linuxcnc/commit/d731...f8b87d773bc7868288b2

I'll try tomorrow.

[edit]

- Seems this section of the code has been moved to the one in interp_remap.cc I posted above
- And yes this seems to work just fine, although it does not allow a call to the built in M code as for the other built in Mcode remaps.
Last edit: 19 Oct 2024 07:45 by Aciera.

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

More
19 Oct 2024 10:29 - 19 Oct 2024 10:32 #312588 by Aciera
After a bit more effort it seems to work now with recursive calls as well. I modified 'configs/sim/axis/remap/extend-builtins/extend-builtins.ini ' in current master as an example for remapping the built in 'M7', 'M8' and 'M9' to be callable with an optional P word and recursively calling the built in Mcodes.

 

The patch looks like this:

diff --git a/configs/sim/axis/remap/extend-builtins/extend-builtins.ini b/configs/sim/axis/remap/extend-builtins/extend-builtins.ini
index 9f6cee2749..09d3c67ce8 100644
--- a/configs/sim/axis/remap/extend-builtins/extend-builtins.ini
+++ b/configs/sim/axis/remap/extend-builtins/extend-builtins.ini
@@ -68,6 +68,9 @@ REMAP= M0 modalgroup=4 ngc=extend_m0
 REMAP= M1 modalgroup=4 ngc=extend_m1
 REMAP= M60 modalgroup=4 ngc=extend_m60
 
+REMAP = M7  modalgroup=8 argspec=p ngc=extend_m7
+REMAP = M8  modalgroup=8 argspec=p ngc=extend_m8
+REMAP = M9  modalgroup=8 argspec=p ngc=extend_m9
 # this is important - read common_nc_subs/reset_state.ngc
 ON_ABORT_COMMAND= O <reset_state> call
 
diff --git a/src/emc/rs274ngc/interp_convert.cc b/src/emc/rs274ngc/interp_convert.cc
index 4864cc5407..fba0d66d6b 100644
--- a/src/emc/rs274ngc/interp_convert.cc
+++ b/src/emc/rs274ngc/interp_convert.cc
@@ -4068,7 +4068,9 @@ int Interp::convert_m(block_pointer block,       //!< pointer to a block of RS27
       CHP(restore_settings(&_setup, _setup.call_level));
   }
 
-  if (is_user_defined_m_code(block, settings, 8) && ONCE_M(8)) {
+  if (is_user_defined_m_code(block, settings, 8) &&
+      STEP_REMAPPED_IN_BLOCK(block, STEP_M_8) &&
+      ONCE_M(8))  {
      return convert_remapped_code(block, settings, STEP_M_8, 'm',
                    block->m_modes[8]);
   } else if ((block->m_modes[8] == 7) && ONCE_M(8)){
diff --git a/src/emc/rs274ngc/interp_remap.cc b/src/emc/rs274ngc/interp_remap.cc
index 947fac5cfc..3e4069e0e8 100644
--- a/src/emc/rs274ngc/interp_remap.cc
+++ b/src/emc/rs274ngc/interp_remap.cc
@@ -42,6 +42,8 @@ bool Interp::is_m_code_remappable(int m_code)
             m_code == 0 ||
             m_code == 1 ||
             m_code == 6 ||
+            m_code == 7 ||
+            m_code == 8 ||
             m_code == 9 ||
             m_code == 60 ||
             m_code == 61 ||
diff --git a/src/emc/rs274ngc/rs274ngc_pre.cc b/src/emc/rs274ngc/rs274ngc_pre.cc
index 492a72876b..87efe1f718 100644
--- a/src/emc/rs274ngc/rs274ngc_pre.cc
+++ b/src/emc/rs274ngc/rs274ngc_pre.cc
@@ -693,9 +693,18 @@ int Interp::find_remappings(block_pointer block, setup_pointer settings)
     block->remappings.insert(STEP_M_7);
 
     // User defined M-Codes in group 8
-    if (is_user_defined_m_code(block, settings, 8))
-    block->remappings.insert(STEP_M_8);
-
+    if (is_user_defined_m_code(block, settings, 8)) {
+        if (((block->m_modes[8] == 7) && remap_in_progress("M7")) ||
+        ((block->m_modes[8] == 8) && remap_in_progress("M8")) ||
+        ((block->m_modes[8] == 9) && remap_in_progress("M9"))){
+        // recursive behavior
+        CONTROLLING_BLOCK(*settings).builtin_used = true;
+        } else {
+        // non-recursive (ie the built in) behavior
+        block->remappings.insert(STEP_M_8);
+        }
+    }
+    
     // User defined M-Codes in group 9
     if (is_user_defined_m_code(block, settings, 9))
     block->remappings.insert(STEP_M_9);

This has been lightly tested. Maybe somebody finds this useful.
Attachments:
Last edit: 19 Oct 2024 10:32 by Aciera.
The following user(s) said Thank You: smc.collins

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

More
21 Oct 2024 11:54 #312734 by smc.collins

I cannot test this right now but looking at this makes me wonder if it could actually be this easy to add 'M7' and 'M8' to the list of remap-able Mcodes (considering that according to the documentation 'M9' should not be a remap-able Mcode somebody already seems to have done or at least tried to do something like this)  :

 

remapping is certainly a valid option for sure. 

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

More
21 Oct 2024 12:35 #312739 by Aciera

remapping is certainly a valid option for sure.

Then you may want to try the patch I posted above. If you want dedicated halpins, rather than use motion.digital-out-xx pins, you could create a python hal component that creates the pins as you want them and then use a python remap that writes directly to the python comp instead of the ngc remap setting the motion.digital-out-xx pins.

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

More
24 Oct 2024 01:44 #313020 by smc.collins
Badass man, submit a pull request

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

More
30 Oct 2024 14:22 #313487 by smc.collins
I'll have to dig into Python, I've never worked with it directly. 


Yes, my goal would be mappable io pins via mx px gcode convention.


I already wrote a coolant control hal component, might be time to start adding to it

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

Time to create page: 0.191 seconds
Powered by Kunena Forum