Hello Guest it is April 18, 2024, 12:30:10 AM

Author Topic: Map Lua Code to ShuttlePro button  (Read 8278 times)

0 Members and 1 Guest are viewing this topic.

Offline Pedio

*
  •  200 200
    • View Profile
Map Lua Code to ShuttlePro button
« on: March 09, 2016, 04:42:00 PM »
Anyone know a way to map Lua code to a ShuttlePro button?

Thanks,
Peter
Re: Map Lua Code to ShuttlePro button
« Reply #1 on: March 10, 2016, 12:41:22 PM »
Hi Peter,
here are a short description

1. enable shuttle plugin


2. Map Input signals to shuttle keys (shuttle key numbers are 0 to 15 from upper left and ignore my change beetwen input2 and input0, description in the code sample)


3. edit screen (menu/Operator/edit Screen)
    select first line in the screen tree manager (in my picture wx4)
    in the lower tab select events
    open "Screen load script"


here you can write handles for all input signals
must be in the SigLib Definition enclosed by { }

---------  code sample start ---------
---------------------------------------------------------------
-- Signal Library
---------------------------------------------------------------
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
    machEnabled = state;
    scr.SetProperty('btnRefAll', 'Enabled', tostring(state));
    scr.SetProperty('btnRefAll2', 'Enabled', tostring(state));
    scr.SetProperty('btnGotoZero', 'Enabled', tostring(state));
    scr.SetProperty('tabJogging', 'Enabled', tostring(state));
    if (state == 1) then
        AxisEnable();
    end
end,

-- here handle for input0
[mc.ISIG_INPUT0] = function (state)
     --- your code here
end,

.....
.......
....
....

---------  code sample ende ---------


Here my code to select axis and steps for the jog
---------  code sample start ---------
-- if screen loaded all inputs are called multiple
-- to save x axis is first selection after screen start i swap  INPUT2 and INPUT0

InputTrigger = 0  --suppress toggle for input7

[mc.ISIG_INPUT0] = function (state)
    JogSetAxis(2)
end,
[mc.ISIG_INPUT1] = function (state)
    JogSetAxis(1)
end,
[mc.ISIG_INPUT2] = function (state)
    JogSetAxis(0)
end,
[mc.ISIG_INPUT4] = function (state)
    local jogRate
    jogRate=0.001
    mc.mcJogSetInc(inst, 0,jogRate);
    mc.mcJogSetInc(inst, 1,jogRate);
    mc.mcJogSetInc(inst, 2,jogRate);
end,
[mc.ISIG_INPUT5] = function (state)
    local jogRate
    jogRate=0.01
    mc.mcJogSetInc(inst, 0,jogRate);
    mc.mcJogSetInc(inst, 1,jogRate);
    mc.mcJogSetInc(inst, 2,jogRate);
end,
[mc.ISIG_INPUT6] = function (state)
    local jogRate
    jogRate=0.1
    mc.mcJogSetInc(inst, 0,jogRate);
    mc.mcJogSetInc(inst, 1,jogRate);
    mc.mcJogSetInc(inst, 2,jogRate);
end,
[mc.ISIG_INPUT7] = function (state)
    local jogRate
    jogRate=1
    mc.mcJogSetInc(inst, 0,jogRate);
    mc.mcJogSetInc(inst, 1,jogRate);
    mc.mcJogSetInc(inst, 2,jogRate);
end,
[mc.ISIG_INPUT8] = function (state)
    if (state==1 and InputTrigger==0) then
        InputTrigger = 1
        ButtonJogModeToggle()
    end
    if (state==0 and InputTrigger==1) then
        InputTrigger = 0
    end
end,

....
.....
....
---------  code sample ende ---------



Hope i can help  ;)
Tom





Re: Map Lua Code to ShuttlePro button
« Reply #2 on: March 10, 2016, 12:54:22 PM »
Here the forgoten function JOGSETAXIS
Insert it after the the SigLib Definition
This function select the axis.

ledX,ledY,ledZ are LEDs on the Screen to show me which axis is selected.
If you don't need comment out all lines with setproperty for led.
Or insert a LED on the Screen and name it ledX,........


function JogSetAxis(axis)
    scr.SetProperty("ledX", "Value", "0")   
    scr.SetProperty("ledY", "Value", "0")   
    scr.SetProperty("ledZ", "Value", "0")
    if (axis==0) then
            scr.SetProperty("ledX", "Value", "1") ;
    end
    if (axis==1) then
            scr.SetProperty("ledY", "Value", "1") ;
    end
    if (axis==2) then
            scr.SetProperty("ledZ", "Value", "1") ;
    end
    mc.mcMpgSetAxis(0, 0, axis);
    mc.mcCntlSetLastError(inst, "Axis " .. tostring(axis));   -- write to history
end

Offline Pedio

*
  •  200 200
    • View Profile
Re: Map Lua Code to ShuttlePro button
« Reply #3 on: March 10, 2016, 03:08:06 PM »
I will be at the CNC next week and will give it a try. Will let you know what happens.

Offline Pedio

*
  •  200 200
    • View Profile
Re: Map Lua Code to ShuttlePro button
« Reply #4 on: March 11, 2016, 01:40:54 PM »
tom|tom,

I am having problem with the } at the end of the code. I am getting "Unexpected character by }"

Here is the code I was using:

-- Turn on Laser at low power map to shuttle pro button 7
---------------------------------------------------------------
-- Signal Library
---------------------------------------------------------------
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
    machEnabled = state;
    scr.SetProperty('btnRefAll', 'Enabled', tostring(state));
    scr.SetProperty('btnRefAll2', 'Enabled', tostring(state));
    scr.SetProperty('btnGotoZero', 'Enabled', tostring(state));
    scr.SetProperty('tabJogging', 'Enabled', tostring(state));
    if (state == 1) then
        AxisEnable();
    end
end,
[mc.ISIG_INPUT7] = function (state)
local inst = mc.mcGetInstance();
local rpm = 1;    -- Set this to the actual RPM you want as your starting point
mc.mcSpindleSetCommandRPM( inst, rpm );
mc.mcSpindleSetDirection( inst, 1 );    -- 1 == forward, 0 == off, -1 == reverse
}

-- End Turn on Laser at low power
Re: Map Lua Code to ShuttlePro button
« Reply #5 on: March 11, 2016, 02:44:31 PM »
I think there is a missing end at the end  ;)

-- Turn on Laser at low power map to shuttle pro button 7
---------------------------------------------------------------
-- Signal Library
---------------------------------------------------------------
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
    machEnabled = state;
    scr.SetProperty('btnRefAll', 'Enabled', tostring(state));
    scr.SetProperty('btnRefAll2', 'Enabled', tostring(state));
    scr.SetProperty('btnGotoZero', 'Enabled', tostring(state));
    scr.SetProperty('tabJogging', 'Enabled', tostring(state));
    if (state == 1) then
        AxisEnable();
    end
end,
[mc.ISIG_INPUT7] = function (state)
local inst = mc.mcGetInstance();
local rpm = 1;    -- Set this to the actual RPM you want as your starting point
mc.mcSpindleSetCommandRPM( inst, rpm );
mc.mcSpindleSetDirection( inst, 1 );    -- 1 == forward, 0 == off, -1 == reverse
end
}

Offline Pedio

*
  •  200 200
    • View Profile
Re: Map Lua Code to ShuttlePro button
« Reply #6 on: March 13, 2016, 02:32:17 PM »
Hmmmm - something does not seem to be working for me. I mapped button 7 on the ShuttlePro to input 6 and added the following code to the screen load.

-- Turn on Laser at low power map to shuttle pro button 7 (which is actually input 6 - I think)
---------------------------------------------------------------
-- Signal Library
---------------------------------------------------------------
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
    machEnabled = state;
    scr.SetProperty('btnRefAll', 'Enabled', tostring(state));
    scr.SetProperty('btnRefAll2', 'Enabled', tostring(state));
    scr.SetProperty('btnGotoZero', 'Enabled', tostring(state));
    scr.SetProperty('tabJogging', 'Enabled', tostring(state));
    if (state == 1) then
        AxisEnable();
    end
end,
[mc.ISIG_INPUT6] = function (state)
local inst = mc.mcGetInstance();
local rpm = 1;    -- Set this to the actual RPM you want as your starting point
mc.mcSpindleSetCommandRPM( inst, rpm );
mc.mcSpindleSetDirection( inst, 1 );    -- 1 == forward, 0 == off, -1 == reverse
end
}



The ShuttlePro plugin is enabled. I then restarted M4. Am I doing anything wrong?

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Map Lua Code to ShuttlePro button
« Reply #7 on: March 15, 2016, 01:52:09 AM »
mc.ISIG_INPUT6 = function (state)
local inst = mc.mcGetInstance();
local rpm = 1;    -- Set this to the actual RPM you want as your starting point
mc.mcSpindleSetCommandRPM( inst, rpm );
mc.mcSpindleSetDirection( inst, 1 );    -- 1 == forward, 0 == off, -1 == reverse
end
this compiles

this does not
[mc.ISIG_INPUT6] = function (state)
local inst = mc.mcGetInstance();
local rpm = 1;    -- Set this to the actual RPM you want as your starting point
mc.mcSpindleSetCommandRPM( inst, rpm );
mc.mcSpindleSetDirection( inst, 1 );    -- 1 == forward, 0 == off, -1 == reverse
end
}

when you get to something that does not work test it by it's self if you go find what DAZ posted about how signals are done now that will help, the manual is wrong needs updated they should get Daz to do it

Offline Pedio

*
  •  200 200
    • View Profile
Re: Map Lua Code to ShuttlePro button
« Reply #8 on: May 23, 2016, 04:10:57 PM »
I am still trying to get the spindle button to work to turn the laser on my CNC on and off for positioning the work piece. I came back to this issue after I got a couple of other things fixed on the machine. Seems there is not enough time in the day.

Sorry if I am being remedial. The code after the siglib toggles the spindle (I use this to control the laser). The code after the second end statement works when used in a button.

Do I need to insert the following code in the 'screen load' load script on the top level of the tree? Is there any place special it should be inserted? I know nothing about Lua.

-- Map laser to shuttle pro button 8
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
    machEnabled = state;
    scr.SetProperty('btnRefAll', 'Enabled', tostring(state));
    scr.SetProperty('btnRefAll2', 'Enabled', tostring(state));
    scr.SetProperty('btnGotoZero', 'Enabled', tostring(state));
    scr.SetProperty('tabJogging', 'Enabled', tostring(state));
    if (state == 1) then
        AxisEnable();
    end
end,
mc.ISIG_INPUT6 = function (state)
local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
local sigState = mc.mcSignalGetState(sigh);
if (sigState == 1) then
    mc.mcSpindleSetDirection(inst, 0);
else
    mc.mcSpindleSetDirection(inst, 1);
    local rpm = 1;    -- Set this to the actual RPM you want as your starting point
    mc.mcSpindleSetCommandRPM( inst, rpm );
end

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Map Lua Code to ShuttlePro button
« Reply #9 on: May 23, 2016, 05:03:18 PM »
Not sure I understand? but if you are referring to the 2 buttons on the right of the screen then you need to edit the functions for them in the screen load script as these turn the spindle on and off.


Code: [Select]
---------------------------------------------------------------
-- Spin CW function.
---------------------------------------------------------------
function SpinCW()
    local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
    local sigState = mc.mcSignalGetState(sigh);
   
    if (sigState == 1) then
        mc.mcSpindleSetDirection(inst, 0);
    else
        mc.mcSpindleSetDirection(inst, 1);
    end
end

---------------------------------------------------------------
-- Spin CCW function.
---------------------------------------------------------------
function SpinCCW()
    local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
    local sigState = mc.mcSignalGetState(sigh);
   
    if (sigState == 1) then
        mc.mcSpindleSetDirection(inst, 0);
    else
        mc.mcSpindleSetDirection(inst, -1);
    end
end

DazTheGas
New For 2022 - Instagram: dazthegas