Hello Guest it is April 23, 2024, 01:32:11 AM

Author Topic: Mechanical speed ranges in Mach4  (Read 2467 times)

0 Members and 1 Guest are viewing this topic.

Mechanical speed ranges in Mach4
« on: January 13, 2020, 04:33:35 AM »
hello
is it possible to insert a command in the gcode to change the mechanical speed range at the software level?
I'll explain:
having lathe with ranges, I would do the mechanical movement.
so I thought about this sequence:
M5
M0 (here I change mechanical range)
...... (code that changes my scale)
M3 G97 S ...
Re: Mechanical speed ranges in Mach4
« Reply #1 on: January 13, 2020, 09:40:44 AM »
If I understand you correctly here is a code snippet that I use in a macro:

  if mc.mcSpindleGetCurrentRange(inst)~=1 then
    wx.wxMessageBox('Set Spindle Gearing to High Speed')
    mc.mcSpindleSetRange(inst,1)
  end

HTH

RT
Re: Mechanical speed ranges in Mach4
« Reply #2 on: January 13, 2020, 10:07:36 AM »
do I have to build every macro for every range?
example
M100 (equivalent to range 1)
M101 (equivalent to range 2)
did I get it right?
« Last Edit: January 13, 2020, 10:09:23 AM by daniba73 »
Re: Mechanical speed ranges in Mach4
« Reply #3 on: January 13, 2020, 10:09:24 AM »
You could pass the range you want as a parameter to the macro: m100 p2
Re: Mechanical speed ranges in Mach4
« Reply #4 on: January 13, 2020, 10:14:41 AM »
ok I understand now.
I try as soon as possible.
I'll let you know!
thank you!

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Mechanical speed ranges in Mach4
« Reply #5 on: January 13, 2020, 04:14:08 PM »
Typically, spindle speed ranges are in the M40-M46 range of M codes.  These M codes are just general as not all machines will have multiple speed spindles.  Some may have 2, 3, 4 or more.   The Machine Tool Builder (you) will have to implement them because of the differing methods of control and number of ranges implemented are too varied to have canned M codes for this purpose. 

Code: [Select]
function m40()
local inst = mc.mcGetInstance("Spindle range 0")
local rc
local currentRange
currentRange, rc = mc.mcSpindleGetCurrentRange(inst)
if (currentRange == 0) then
return -- nothing to do!
end
-- Do the machine dependent range change control.
--
-- End machine dependent range change control

-- Next, tell Mach what rage we are now in IF the above is successful. 
mc.mcSpindleSetRage(inst, 0)
end

if (mc.mcInEditor() == 1) then
    m40()
end

Rinse and repeat for all of your spindle speed ranges. 

Steve
Re: Mechanical speed ranges in Mach4
« Reply #6 on: January 13, 2020, 05:51:27 PM »
I don't know where I'm wrong, but it doesn't work in either of the two examples you gave me.
Re: Mechanical speed ranges in Mach4
« Reply #7 on: January 13, 2020, 06:02:52 PM »
Can't help if you don't post the macro code you are using.
Re: Mechanical speed ranges in Mach4
« Reply #8 on: January 13, 2020, 06:19:41 PM »
I just created a macro that I called "m50"
inside I copied what you wrote.
then I tried to write the m50 macro inside a gcode, but it was ignored.

later I tried to replace the internal macro m50 with the second example, but nothing changes.

I underline that I was testing it on the laptop in demo version, I didn't have time to go to the laboratory to try the lathe where I activated mach4 hobby with license.

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Mechanical speed ranges in Mach4
« Reply #9 on: January 13, 2020, 07:49:34 PM »
1) Why are you calling the macro m50?  M40-M46 are the typical M codes used for spindle speed ranges. 
2) When you create an M code macro script, use lower case names for both the file AND the function inside it. 

"m50.mcs" is correct, while "M50.mcs" is not correct for a file name.

function m50()
...
end

is correct and

function M50()
...
end

is NOT correct. 

The FIRST thing you should do is take the example someone gives you and try it like it is.  And there is no guarantee that script people throw up on the forum will work because a lot of the time the people trying to help are putting "the general idea" up to help you on your way.  The rest is an exercise for the user (you).  :)  But anyway, try it like the example was and get things working.  THEN you can start renaming the macro script and function inside it.

When working with the script in the editor, it is always a good idea to try and compile it.  Because compiling it in the editor will show you is there are any syntax errors.  It could be as simple as a misspelled function call from a typo in the example. 

So in summary, if a script is "being ignored", it is most likely because of:

1. Not using lower case names for functions and file names. 
2. Not checking for syntax errors by compiling the macro script first. 

Steve