Hello Guest it is March 28, 2024, 01:24:10 PM

Author Topic: Mach 4 Machtric 2.2kw VFD Modbus  (Read 22054 times)

0 Members and 1 Guest are viewing this topic.

Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #30 on: January 26, 2017, 04:33:14 PM »
Hi Zuxztah,
struggling to get it to work myself.

As it turns out if you execute:
mc.mcSpindleSetDirection(inst, 1) the CW LED operates,
mc.mcSpindleSetDirection(inst, -1)  the CCW LED operates and
mc.mcSpindleSetDirection(inst, 0)  both LEDs extinguish.

So getting the LEDs to work it just a case of executing one of the above at the right time.

What I really want is three customised macros m03, m04 and m05. I've written the macros and they work when debugging
but they do not 'overwrite' the Mach4 internal functions of the same name as I expected. I've put out a call for help on another
thread.

The CW button script will look like this:
Code: [Select]
local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
local sigState = mc.mcSignalGetState(sigh);
if (sigState == 1) then;
    local rc = mc.mcCntlGcodeExecute(inst,"m03");
else;
    local rc = mc.mcCntlGcodeExecute(inst,"m05");
end;

Once I've worked out how to call the customised m03 (or m05 as the case may be) I post back.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #31 on: January 26, 2017, 05:53:00 PM »
Hi Zuxztah,
think I may have some working code:
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #32 on: January 26, 2017, 06:05:58 PM »
Hi Zuxztah,
whoops, mistroke...

As I was saying I may have some working code for you to try...

Substitute your CW button left-up script with:

Code: [Select]
local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
local sigState = mc.mcSignalGetState(sigh);
if (sigState == 1) then;
    local rc = mc.mcCntlGcodeExecuteWait(inst,"m5");
else;
    local rc = mc.mcCntlGcodeExecuteWait(inst,"m3");
end;

Substitue your CCW button left-up script with:

Code: [Select]
local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
local sigState = mc.mcSignalGetState(sigh);
if (sigState == 1) then;
    mc.mcCntlGcodeExecuteWait(inst,"m5");
else;
    mc.mcCntlGcodeExecuteWait(inst,"m4");
end;

Now you need three macros in your Profile/Macros folder...

Named m3:

Code: [Select]
function m3();
local inst=mc.mcGetInstance();
local hcont=mc.mcRegGetHandle(inst,"modbus0/spinCntrl");
mc.mcSpindleSetDirection(inst,1);
mc.mcRegSetValue(hcont,10);
end
if (mc.mcInEditor() == 1) then
    m3()
end

Named m4:
Code: [Select]
function m4();
local inst=mc.mcGetInstance();
local hcont=mc.mcRegGetHandle(inst,"modbus0/spinCntrl");
mc.mcSpindleSetDirection(inst,-1);
mc.mcRegSetValue(hcont,10);  -- substitute 10 with whatever number is required to make your spindle run CCW
end
if (mc.mcInEditor() == 1) then
    m4()
end

Named m5:

'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #33 on: January 26, 2017, 06:11:39 PM »
Hi,
done it again...

Named m5:
Code: [Select]
function m5();
local inst=mc.mcGetInstance();
local hcont=mc.mcRegGetHandle(inst,"modbus0/spinCntrl");
mc.mcSpindleSetDirection(inst, 0);
mc.mcRegSetValue(hcont,01);
end
if (mc.mcInEditor() == 1) then
    m5()
end
.

Once you've got these installed you should be able to turn the spindle on and off from the CW or CCW buttons on the screen or
alternately from calling m3/m4/m5 from MDI or Gcode.

Have not as yet set the speed, will work on that shortly.

Craig

'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #34 on: January 27, 2017, 04:33:32 AM »
Hi Zuxztah,
last instalment of code.
This needs to go at the end (or near the end) of your PLC script:
Code: [Select]
---------------------------------------------------------
--          set Target RPM DRO
---------------------------------------------------------
RPM=mc.mcCntlGetPoundVar(inst,2132);
local OVRenable=mc.mcSpindleGetOverrideEnable(inst);
if OVRenable then;
    local OVR=mc.mcSpindleGetOverride(inst);
    RPM=RPM*OVR;
end;
local range=mc.mcSpindleGetCurrentRange(inst)
if RPM>mc.mcSpindleGetMaxRPM(inst,range) then RPM=mc.mcSpindleGetMaxRPM(inst,0) end;
if RPM<mc.mcSpindleGetMinRPM(inst,range) then RPM=mc.mcSpindleGetMinRPM(inst,0) end;
local freq=RPM/6;
local hfreq=mc.mcRegGetHandle(inst,"modbus0/freq");
mc.mcRegSetValue(hfreq,freq);
scr.SetProperty('dro(128)','Value',tostring(RPM));

Note that I have a DRO (dro(128)) that I display the target RPM. Also I used pound variable 2132 to get the current commanded speed,
there is an API function but it didn't work for me.

Just as a matter of interest do you use the 'Always on Top' feature of the Diagnostics/Regfile expand modbus0? Its the pin icon, click it
and you can view your two Modbus registers as you fiddle with the buttons/MDI/Speed_OverRide. Really handy.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #35 on: January 27, 2017, 04:40:09 AM »
Hi,
see an error, try this instead:
Code: [Select]
RPM=mc.mcCntlGetPoundVar(inst,2132);
local OVRenable=mc.mcSpindleGetOverrideEnable(inst);
if OVRenable then;
    local OVR=mc.mcSpindleGetOverride(inst);
    RPM=RPM*OVR;
end;
local range=mc.mcSpindleGetCurrentRange(inst)
if RPM>mc.mcSpindleGetMaxRPM(inst,range) then RPM=mc.mcSpindleGetMaxRPM(inst,range) end;
if RPM<mc.mcSpindleGetMinRPM(inst,range) then RPM=mc.mcSpindleGetMinRPM(inst,range) end;
local freq=RPM/6;
local hfreq=mc.mcRegGetHandle(inst,"modbus0/freq");
mc.mcRegSetValue(hfreq,freq);
scr.SetProperty('dro(128)','Value',tostring(RPM));

Didn't have 'range' set correctly in the second mcSpindleGetMaxRPM(inst,range) or mcSpindleGetMinRPM(inst,range)  statements.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #36 on: January 27, 2017, 04:46:37 AM »
Hi Zuxztah,
might be able to take  :( off your original post and swap it for  :)

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #37 on: January 28, 2017, 06:43:19 AM »
Hello! super big thanks for all this effort! I don't know how to thank you enough! this looks very promising :)  I'm currently adding all those scripts :) trying to figure out how to add macros to the macro folder, I know the directory but not what extension the file should have? or if its possible to edit it trough mach software itself?

I guess the file shouldn't have an extension name like .txt

The directory C:\Mach4Hobby\Profiles\Mach4ESS\Macros only have one file, mcLua.mcc and it's not possible to edit the file trough mach (Edit/Debug scripts.) due to the extension name.

The Edit/Debug scripts function do only allow .mcs .lua .wx.lua formats.

at the moment when I press Spindle CW / Stop and Spindle CCW / Stop the program binds up and needs to be restarted probably due to the missing macros (m3-m4-m5) ill see if I manage to sort it out :) hopefully before you read this post XD


(I do actually have the Reg file diagnostics window always on top) to determine if the modbus values changes while pressing the buttons



« Last Edit: January 28, 2017, 06:52:12 AM by Zuxztah »
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #38 on: January 28, 2017, 07:39:22 AM »
Hi! managed to add m3. m4. m5 macros, but no response in the Register Diagnostics? I think the "code" may be wrong in the part of finding the right register/path?

at the moment the code is:

Code: [Select]
local hcont=mc.mcRegGetHandle(inst,"modbus0/spinCntrl");
what if the path is wrong? if maybe the code should look something like this:

Code: [Select]
local hcont=mc.mcRegGetHandle(inst,"modbus0/modbus0/spinCntrl");
it's all just a wild guess, but it feels like the script/code isn't finding the right path?

first of, the registry path: modbus0 (named Modbus Function) (the expandable register) and then the function modbus0/SpinCntrl: gets equal to modbus0/modbus0/SpinCntrl:0

if we hade a custom registry we would have to put the path for iRegs0 and then the function?

Example: iRegs0/Test1 in the Scripting manual

the pictures explain what I mean, it's probably not working because of the name I chose to use with my modbus setup? (modbus0)

Pictures: https://postimg.org/gallery/1zsvad7ha/

Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #39 on: January 28, 2017, 02:08:10 PM »
Hi Zuxztah,
looking at your screenshot I would say you are correct. You must use the register path as you named them. Why did you name them that way?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'