维宏LOGO
搜索结果

    NK260二次开发常用修改说明(三)

    《NK260二次开发常用修改说明》系列文档共有三篇,主要针对版本号为NK260_XXX_WOOD的维宏木工产品线软件,指导在NK260二次开发过程中常见的修改和功能定制。

    本文将指导您完成以下NK260二次开发任务:

    • 外接输入按钮控制程序启停
    • 外接输入按钮控制输出
    • 外接紧停报警
    • 外接气压检测报警
    • 外接刀库收回检测

    外接输入按钮控制程序启停

    可自定义外接输入按钮,用于控制程序启停。包括:

    • 程序开始
    • 程序停止
    • 程序暂停
    • 断点继续

    此4个功能定义已经在**InportFunction()**函数中完成,您只需定义4个输入端口。

    打开port.lua文件,定义4个输入端口的usage值分为:

    • nc_start
    • nc_stop
    • nc_pause
    • nc_resume

    外接输入按钮控制输出

    典型案例:外接输入控制松夹刀。

    定义松夹刀开关类型,0:按下输出,弹起关闭;1:按下输出,再次按下关闭。使用自定义参数4作为开关类型。

    需作三处修改:

    • UserParamCHN.xaml文件中自定义参数4

    • Luui-main.lua文件中定义函数

    • 100ms定时器中调用函数

    UserParamCHN.xaml文件中自定义参数4

    <ITEM name="USERPARAM4" type="1"    value="0"   unit=""      multiple="1" title="松夹刀开关类型"                      text="0:按下输出,弹起关闭;1:按下输出,再按下关闭 "/>
    

    Luui-main.lua文件中定义函数

    --手动松夹刀,控制方式
    g_spin_tool_oldmask = -1
    g_timeDelay = -1
    function nc_manual_tool_clamp_release()
        local bInport = luui.get_inport("in_ManulTool")--输入端口usage
        local spin_tool_mask = 0
    
        if g_timeDelay <= -1 and bInport then
            g_timeDelay = 200
            return
        elseif g_timeDelay > 0 then
            if bInport then
                g_timeDelay = g_timeDelay - 100
            else
                g_timeDelay = -1
            end
            return
        else
            g_timeDelay = -1
        end
    
        if bInport then
            spin_tool_mask = 1
        else
            spin_tool_mask = -1
        end
    
        if g_spin_tool_oldmask == spin_tool_mask then
            return
        end
    
        --急停状态下 可以松夹刀
        if luui.get_sys_state() ~= ESTOP_STATE then
            if not luui.is_kernel_idle() then
                luui.prompt_message(s_szILLEGAL_OPER[luui.get_language_version()])
                g_spin_tool_oldmask = spin_tool_mask
                return
            end
        end
    
        --主轴输出或者未检测到主轴零速信号,不能松夹刀
        if luui.get_outport("nc_spin") or not luui.get_inport("in_SpindleZero") then
            luui.prompt_message(s_szSpindleIsOpen[luui.get_language_version()])
            g_spin_tool_oldmask = spin_tool_mask
            return
        end
    
        --按下输出 弹起关闭
        if luui.get_user_param(4) == 0 then
            if bInport then
                g_spin_tool_oldmask = 1
                if not luui.get_outport("out_Clamp") then
                    luui.set_outport("out_Clamp",  true)
                end
            else
                luui.set_outport("out_Clamp",false)
                g_spin_tool_oldmask = -1
            end
        --按下输出,再次按下关闭
        elseif luui.get_user_param(4) == 1 then
            if bInport then
                g_spin_tool_oldmask = 1
                if luui.get_outport("out_Clamp") then
                    luui.set_outport("out_Clamp",  false)
                else
                    luui.set_outport("out_Clamp",  true)
                end
            else
                g_spin_tool_oldmask = -1
            end 
        end
    end
    

    100ms定时器调用函数

    --100ms定时器
    function nc_100ms_timer()
        g_ticks = luui.get_ticks()
        InportFunction()
        nc_manual_tool_clamp_release()
    end
    

    外接紧停报警

    将外接一个输入作为紧停报警。以Z轴伺服报警为例,定义好输入端口后打开luplc.luplc文件,新增如下:

    +-@nc_syalm $1 nc_syalm -> CALL(`set_state`, ESTOP_STATE) 
                $1 true     -> CMD_MSG(IDCMD_NK260_ESTOP_NORMAL, "nc_syalm")
            
    +-@nc_szalm  $1 nc_szalm -> CALL(`set_state`, ESTOP_STATE) 
                 $1 true     -> CMD_MSG(IDCMD_NK260_ESTOP_NORMAL, "nc_szalm")
                         
    not nc_cutp and not nc_xplim and not nc_xnlim and not nc_yplim and  not nc_ynlim and not nc_zplim and  not nc_znlim -> no_limit
    not nc_sxalm and not nc_syalm and not nc_szalm and  not nc_estop and not nc_oilalm and not nc_salam -> no_estop
    no_limit or M[LuKernel.m_rlimit] $1 (d_state == ESTOP_STATE) and no_estop -> toidle
    

    外接气压检测报警

    气压检测报警,并不影响手动模式下手动移动机床,只影响自动加工,即自动加工过程中检测到该信号,系统停止加工。

    当“气压报警”输入端口有信号时,该黄色提示一直显示(所有模式下都有提示)直至手动按ESC键后消失。

    请做以下修改。

    修改一

    s_szAirAlm = {"|W|气压报警!", "|W|Air alarm!"};
    --实时检测气压状态
    g_airalm = false   --防止多次进入 
    function nc_check_air_state()
        local bMode = luui.get_sys_mode()
        local bState =  luui.get_sys_state()
        local _lan = luui.get_language_version()  
        
        if luui.get_inport("in_AirAlm") then
            if not g_airalm then
                g_airalm = true   
                luui.prompt_message(s_szAirAlm[_lan],false,true)
            
                --自动加工过程中停止加工      
                if ((bMode == AUTO_MODE) and (bState == RUN_STATE  or bState == PAUSING_STATE)) then
                    luui.on_stop()
                end           
            end   
        else
            g_airalm = false
        end
    end
    

    修改二

    --程序开始按键
    function nc_start_auxiop()
        local _lan = luui.get_language_version()
        if not luui.get_inport("in_ToolLibIn") then
            luui.prompt_message(s_szILLEGAL_ToollibIN[_lan])
            return false
        end
    
        if luui.get_inport("in_AirAlm") then
            luui.prompt_message(s_szAirAlm[_lan],false,true)
            return false
        end
         
        g_reset_start_led = g_ticks + 3000
        set_led_state(led_table.LED_PROCESS_START, true)
        return true
    end
    

    修改三

    --断点继续按键
    function nc_resume_auxiop()
        local _lan = luui.get_language_version()
        if not luui.get_inport("in_ToolLibIn") then
            luui.prompt_message(s_szILLEGAL_ToollibIN[_lan])
            return false
        end
        
        if luui.get_inport("in_AirAlm") then
            luui.prompt_message(s_szAirAlm[_lan],false,true)
            return false
        end
            
        g_reset_resume_led = g_ticks + 3000
        set_led_state(led_table.LED_RESUME, true)
        return true
    end
    

    修改四:100ms定时器中调用函数nc_check_air_state()

    --100ms定时器
    function nc_100ms_timer()
        g_ticks = luui.get_ticks()
        InportFunction()
        nc_manual_tool_clamp_release()
        nc_check_air_state()
        nc_check_toollibin_state()
    end
    

    外接刀库收回检测

    刀库收回检测:系统处于运行状态时,除换刀过程外,都会对刀库收回到位信号进行检测,没有检测到该信号时,系统停止加工。

    刀库收回检测类似于气压检测,但又有以下区别:

    • 气压检测是任何状态都需要检测,而刀库收回检测只需在运行状态且非换刀过程检测;
    • 气压检测中,气压报警端口一旦有输入,系统就有黄色提示;而刀库收回检测中,没有检测到刀库收回到位信号时,系统才会有黄色提示。
    s_szILLEGAL_ToollibIN = {"|W|刀库未收回到位!", "|W|Toollib is open!"};
    --检测刀库收回信号
    g_toollibin = false   --防止多次进入
    function nc_check_toollibin_state()
        local bState =  luui.get_sys_state()
        local _lan = luui.get_language_version()
    
        --系统运行过程中(非换刀状态),需要实时检测刀库收回到位信号
        if (bState == RUN_STATE  or bState == PAUSING_STATE) 
        and  not luui.get_m_reg("m_toolchange") then
            if not g_toollibin and not luui.get_inport("in_ToolLibIn") then
                luui.prompt_message
                (s_szILLEGAL_ToollibIN[_lan],false,true)
                luui.on_stop()
                g_toollibin = true
            end
        else
            g_toollibin = false
        end
    end
    

    相关文章

    NK260二次开发常用修改说明(一)

    NK260二次开发常用修改说明(二)

    本文内容
    回到顶端 Shanghai Weihong Electronic Technology Co., Ltd.