Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: thespindoctor on December 11, 2016, 09:53:59 AM

Title: Can soft limits be automatically on at start up?
Post by: thespindoctor on December 11, 2016, 09:53:59 AM
My machine is working great with limit override and soft limits!  ;D It is wonderful to be able to go at rapids to the limits and it always stops now with no limit switches being hit.  The only issue is that I have is that I have to activate soft limits by going to another screen to hit the button to turn on soft limits.  It would be better to have soft limits on when the Mach4 boots then turn off soft limits if not needed.  I see no reason to ever run the machine with soft limits off?  Is there a way to set soft limits on at boot. 

Thanks
Keith
Title: Re: Can soft limits be automatically on at start up?
Post by: DazTheGas on December 11, 2016, 10:10:46 AM
Check out the mcSoftLimitSetState command in the API Docs.

DazTheGas
Title: Re: Can soft limits be automatically on at start up?
Post by: thespindoctor on December 11, 2016, 02:32:49 PM
Thanks!
Title: Re: Can soft limits be automatically on at start up?
Post by: thespindoctor on December 12, 2016, 06:47:08 PM
This is my first attempt to program in Lua in the PLC script.  Trying to turn on softlimits   Here is the code that says syntax error.
I have no idea what I am doing...  I put the code under the PLC First Run section which should be correct?  Got to start somewhere...

Thanks!
-------------------------------------------------------
--  PLC First Run
-------------------------------------------------------
if (testcount == 1) then --Set Keyboard input startup state
    local iReg = mc.mcIoGetHandle (inst, "Keyboard/Enable")
    mc.mcIoSetState(iReg, 1) --Set register to 1 to ensure KeyboardInputsToggle function will do a disable.
    KeyboardInputsToggle()

----------- turn on soft limits by kfc 12/2016

    int TurnOn=MC_ON;

    int axis=Z_AXIS;
    mcSoftLimitSetState(inst, axis, TurnOn);

    int axis = Y_AXIS;
    mcSoftLimitSetState(inst, axis, TurnOn);

    int axis = X_AXIS;
    mcSoftLimitSetState(inst, axis, TurnOn);
-- ----------------------------------------------
Title: Re: Can soft limits be automatically on at start up?
Post by: thespindoctor on December 12, 2016, 06:55:03 PM
-- turn on soft limits by kfc 12/2016
    local TurnOn=MC_ON;

    local axis=Z_AXIS;
    mcSoftLimitSetState(inst, axis, TurnOn);

    local axis = Y_AXIS;
    mcSoftLimitSetState(inst, axis, TurnOn);

    local axis = X_AXIS;
    mcSoftLimitSetState(inst, axis, TurnOn);
-- ----------------------------------------------


?seemed to work???
Title: Re: Can soft limits be automatically on at start up?
Post by: thespindoctor on December 12, 2016, 06:56:29 PM
compiled last version but bad call   almost working
Title: Re: Can soft limits be automatically on at start up?
Post by: DazTheGas on December 13, 2016, 03:07:02 AM
Try something like this, not near my computer so cant the moment

    mc.mcSoftLimitSetState(inst, mc.Z_AXIS, mc.MC_ON)

DazTheGas
Title: Re: Can soft limits be automatically on at start up?
Post by: Stuart on December 13, 2016, 03:45:18 AM
DTG

I tried o do this very same thing a while ago and failed/gave up on it

How about a 2min. Vidieo to educate us that struggle with this lua plc stuff



where should the code be inserted ?

Does it have to be done for each axis ?

But as you say a picture is worth a 1000 words


Stuart
Title: Re: Can soft limits be automatically on at start up?
Post by: thespindoctor on December 13, 2016, 09:18:26 AM
Stuart

I am sure it goes in the plc program and has to be done for each axis. It needs to be in the section of the plc script where a counter is active so it only gets run one time when the counter equals 1
Title: Re: Can soft limits be automatically on at start up?
Post by: thespindoctor on December 13, 2016, 01:16:40 PM
It works   Here is the code   GO to screen edit on operator menu to open editor.  Click on top wx of upper left screen   Then click on lightening bolt option on lower left box to see plc line the click on ... button to open up plc script.  insert where indicated in code below.  Compile   Save    then exit screen editor by clicking on screen edit of operator menu which will ask again to save screen.  Now when you come into Mach4 the softlimits will be on and the softlimits button will be green!

-here is section of plc to insert the code into
-------------------------------------------------------
--  PLC First Run
-------------------------------------------------------
if (testcount == 1) then --Set Keyboard input startup state
    local iReg = mc.mcIoGetHandle (inst, "Keyboard/Enable")
    mc.mcIoSetState(iReg, 1) --Set register to 1 to ensure KeyboardInputsToggle function will do a disable.
    KeyboardInputsToggle()

--INSERT HERE THE FOLLOWING CODE
-- turn on soft limits
      mc.mcSoftLimitSetState(inst, mc.Z_AXIS, mc.MC_ON);

     mc.mcSoftLimitSetState(inst, mc.Y_AXIS, mc.MC_ON);

     mc.mcSoftLimitSetState(inst, mc.X_AXIS, mc.MC_ON);
-- ----------------------------------------------
Title: Re: Can soft limits be automatically on at start up?
Post by: thespindoctor on December 13, 2016, 01:38:57 PM

      mc.mcSoftLimitSetState(inst, mc.Z_AXIS, mc.MC_ON);

     mc.mcSoftLimitSetState(inst, mc.Y_AXIS, mc.MC_ON);

     mc.mcSoftLimitSetState(inst, mc.X_AXIS, mc.MC_ON);

[/quote]
Notice the capitalization!  Apparently this code is CASE Sensitive!  I did not know that.  Anytime we want to run a mcAnything() we need to add the mc to the mcAnything to get mc.mcAnything   Slowly making more sense.  Studying the LUA Scripting Guide line by line is helping to learn Lua.  Feeling like a champ right now with these one liners...

Keith
Title: Re: Can soft limits be automatically on at start up?
Post by: DazTheGas on December 13, 2016, 02:00:44 PM
Video completed just uploading ;-)

DazTheGas
Title: Re: Can soft limits be automatically on at start up?
Post by: DazTheGas on December 13, 2016, 03:58:09 PM
Here you go

http://www.machsupport.com/forum/index.php/topic,33813.0.html

DazTheGas
Title: Re: Can soft limits be automatically on at start up?
Post by: Stuart on December 14, 2016, 03:11:24 AM
Thank you have a drink on me