Hello Guest it is March 28, 2024, 05:22:25 PM

Author Topic: Lua confusion simple switch spindle range  (Read 1128 times)

0 Members and 1 Guest are viewing this topic.

Offline mark4

*
  •  167 167
    • View Profile
Lua confusion simple switch spindle range
« on: January 21, 2020, 01:02:25 PM »
Hello
Lua continues to be a struggle. Every time I learn something. i need to change the spindle range from 0 to 1. The machine I am retrofitting has a high/ low gear switch. so i thought use screen load script and when the switch is activated then low gear and not activated high gear. I also wanted to have two leds on the screen to tell you which gear you are in. Thought I had it figured out. But it doesnt seem to work.
I started with this
[mc.ISIG_INPUT6] = function (state)
    if (state == 1) then
      mc.mcSpindleSetRange(inst,1)
   else
      mc.mcSpindleSetRange(inst,0)
   end
Thought it would work in one go.
Then I went to this

[mc.ISIG_INPUT6] = function (state)
    if (state == 1) then
      GearHiLow()
   
---------------------------------------------------------------
-- Gear Hi / Low
---------------------------------------------------------------
--function GearHiLow()
--   local hSig = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT6)
--   local Gear = mc.mcSignalGetState (hSig)
--   if (Gear == 1) then
--      mc.mcSpindleSetRange (inst,0)
--      mc.mcCntlSetLastError (inst,"range 0")
--   else
--      mc.mcSpindleSetRange (inst,1)
--      mc.mcCntlSetLastError (inst,"range 1")
--   end

This is the final so far and there have been a few versions.
If anybody can point me in the right direction. Thank you
Re: Lua confusion simple switch spindle range
« Reply #1 on: January 21, 2020, 01:13:42 PM »
Hi,
you are putting an entry into the SigLib{} but with the incorrect syntax.


An entry in a Lua table has the form:
[INDEX]=(table entry data and/or function),

Note especially the trailing comma, it indicates to Lua that the entry into the table has concluded.

Secondly you missed the function end statement:
function(....)
............
............function body
............
end

Try this:
Code: [Select]
[mc.ISIG_INPUT6] = function (state)
    if (state == 1) then
      mc.mcSpindleSetRange(inst,1)
   else
      mc.mcSpindleSetRange(inst,0)
   end
end,

Note specifically the function end statement and the trailing comma as required by table entry syntax.

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

Offline mark4

*
  •  167 167
    • View Profile
Re: Lua confusion simple switch spindle range
« Reply #2 on: January 21, 2020, 05:03:11 PM »
Thank you I put that in and got the results I was looking for. Except for some reason
the spindle relays do not reverse when the checkbox is checked. this machine has a
bullgear and fwd and rev need to be swapped. I am using a cslabs csmio/ip-a but it seems more like a mach4
problem. any advise
I will also start a help ticket with artsoft
Re: Lua confusion simple switch spindle range
« Reply #3 on: January 21, 2020, 08:26:24 PM »
Hi,
so in the CSMIO plugin does it have outputs corresponding to 'Set range'

The mcSpindleSetRange does not automatically produce an output, you must use an output signal like
OSIG_OUTPUT31 say, and that output has to be connected to a pin in the CSMIO plugin.

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

Offline mark4

*
  •  167 167
    • View Profile
Re: Lua confusion simple switch spindle range
« Reply #4 on: January 21, 2020, 11:04:51 PM »
Hi the plug in does not mention range so i think they are plugged into the range in mach4. The spindle changes speeds fine in range one and range two. I need to check but it seems correct. I was thinking of having two outputs turn on and using them for the screen led. like this.

[mc.ISIG_INPUT6] = function (state)
    if (state == 1) then
      mc.mcSpindleSetRange(inst,1)
    --set output here the question is do i have to get state first or can i just turn it on   
   else
      mc.mcSpindleSetRange(inst,0)
    -- I want it to stay on until the input changes state
   end
end,
the thing that has me most concerned is the spindle does not change direction. regardless of what reverse i have checked. since this function is just switching the fwd and rev relays to rev and fwd. it is really a mach4 function
and it does not work. I was hoping you or somebody knew about it. as i hate to be the first lol.
Thank you for your help
Re: Lua confusion simple switch spindle range
« Reply #5 on: January 22, 2020, 01:18:28 AM »
Hi,

Quote
since this function is just switching the fwd and rev relays to rev and fwd. it is really a mach4 function
and it does not work

No, that is not quite correct. Mach4 has output signals SpindleOn, SpindleFwd, and SpindleRev.
Whenever your Gcode has a m3, m4 or m5 one or more of the signals will change.

But note, the are SIGNALS only, they don't do anything. If you want them to turn your spindle on and off they must, with
the motion control plugin, be connected to output pins of your motion controller. A signal becomes an input or output ONLY
when the signal is connected to a pin.


Quote
--set output here the question is do i have to get state first or can i just turn it on   



No, you can just turn it on, you will have to get its handle. For example:

Code: [Select]
local ouputHandle=mc.mcSignalGetHandle(inst,mc.OSIG_OUPUT30)
mc.mcSignalSetState(outputHandle,1)


Quote
- I want it to stay on until the input changes state

Thats the whole point of using the SigLib{} table, the entry [mc.ISIG_INPUT6] will ONLY EVER be executed when it changes state,
if it does not change the the outputs will remain in their current state UNTIL the entry is executed by a change of Input#6.


Craig


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

Offline mark4

*
  •  167 167
    • View Profile
Re: Lua confusion simple switch spindle range
« Reply #6 on: January 22, 2020, 07:37:34 AM »
Hello
No, that is not quite correct. Mach4 has output signals SpindleOn, SpindleFwd, and SpindleRev.
Whenever your Gcode has a m3, m4 or m5 one or more of the signals will change.

But note, the are SIGNALS only, they don't do anything. If you want them to turn your spindle on and off they must, with
the motion control plugin, be connected to output pins of your motion controller. A signal becomes an input or output ONLY
when the signal is connected to a pin.

I am with you and the fwd signal and rev signal are working they go through the controller to a relay then to the vfd. so my issue is the reverse checkmark in control config/ spindle. no matter what i do with the checkmark the motor does not reverse. I thought since it is the signal that changes its change will be in mach. Are you saying it could be the plug in that handles the reverse checkmark?
In the plug in that is not mentioned at all. but i am thinking an email to poland might be in order.

Thank you for your help and that information on sig lib
Mark

Offline mark4

*
  •  167 167
    • View Profile
Re: Lua confusion simple switch spindle range
« Reply #7 on: January 22, 2020, 10:14:59 PM »
Hello I just checked the machine.ini from mach4 and it has reverse in the spindle. However i also checked the csmioconfig.xml and it does not have reverse.  So even thought i sent allot of emails I need to finish this machine and what am i to do? It just came to me.
I have a switch that changes the range from 0 to 1 and it changes the motor speed accordingly i just cannot reverse the motor rotation. what if i add a double pole double throw relay and reverse the relays going to the vfd.
then program input 6 to turn this relay on when reverse is required. That will solve a problem that likely wont get solved quickly and i can finish my machine.
This is my last hurdle testing remains then the 4sale sign goes up.
thank you
Mark
Re: Lua confusion simple switch spindle range
« Reply #8 on: January 23, 2020, 02:08:36 AM »
Hi,
it is my observation that the CSMIO plugins are patchy, this is a classic example. Mach4 has a defined signal but the CSMIO plugin does not.

There is a workaround. In Mach have the signals OSIG_SPINDLEON, OSIG_SPINDLEFWD and OSIG_SPINDLEREV be copied to three
regular outputs like OSIG_OUTPUT15, OSIG_OUTPUT16 and OSIG_OUTPUT17. Then connect those three outputs to three pin
on your controller.

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