KUKA零碎程序模块之io点超时报警的一种实现方法 点击:8 | 回复:1



monzer

    
  • [版主]
  • 精华:10帖
  • 求助:7帖
  • 帖子:62帖 | 166回
  • 年度积分:338
  • 历史总积分:14583
  • 注册:2020年3月27日
发表于:2026-08-06 11:52:14
楼主

信号或者io点的超时报警,通常是用定时器去实现,这种方法需要分配一些定时器,这么做并没有什么坏处。只不过要记住占用了哪些定时器从而避免在其它地方再次占用。


本帖使用另外的方法,通过循环记数,然后与规定的超时时间进行求余运算,当余数为零时发出报警。这种方法的好处是不需要管理定时器,只需要给定超时时间。不会出现定时器占用冲突。


-----------------------------------------------

&ACCESS RV1

DEF  WaitClawGraspCell (cmd_griClose_no:in, sensor_group_input:in)

   int cmd_griClose_no, sensor_group_input 

   int diffBit[64]

   int diffBitSize,duration,j,i

   

   duration=10

   i=0

   while (cmd_griClose_no<>sensor_group_input)

      FindDifferentBit(cmd_griClose_no,sensor_group_input,diffBit[],diffBitSize,1)

      if (i-(i/duration)*duration)==0 then

         for j=1 to diffBitSize step 1 

            PrintNum(666, "WaitClawGraspCell():", "claws %1 miss the cell! current close no=%2", diffBit[j], cmd_griClose_no, , #state )

            ErrorReport(45, "ohuo", )

         endfor 

         WaitSemaphoreValid("ohuo", FALSE)

      endif

      i=i+1

      continue

      wait sec 1.0

      cmd_griClose_no = gi_GriClose_No

   endwhile

END

----------------------------------------------

&ACCESS RVO1

DEF WaitSemaphoreValid (semaphoreName[]:in,validState:in)

   char semaphoreName[]

   bool validState

   decl SIGINF S_INF

   int i,duration

   char value1[26], value2[26], value3[26]

   

   duration=10

   S_INF = GET_SIG_INF(semaphoreName[])

   if (validState) then

      if strcopy(value1[],"True") then

         if (NumToStr(S_INF.IDX, value2[])) then

            ;--

         endif

      endif

   else

      if strcopy(value1[],"False") then

         if (NumToStr(S_INF.IDX, value2[])) then

            ;--

         endif

      endif

   endif 

   i=0

   

   if (S_INF.typ == #out) and (S_INF.IDX<>0) then 

      while (validState<>$out[S_INF.IDX]) 

         if (i-(i/duration)*duration)==0 then

            PrintString(S_INF.IDX, "WaitSemaphoreValid():", "The signal $OUT[%1] should be %2.", value2[], value1[], , #state )

         endif

         i=i+1

         continue

         wait sec 1.0

      endwhile   

   else 

      i=0

      if (S_INF.typ == #in) and (S_INF.IDX<>0) then

         while (validState<>$in[S_INF.IDX]) 

            if (i-(i/duration)*duration)==0 then

               PrintString(S_INF.IDX, "WaitSemaphoreValid():", "The signal $IN[%1] should be %2.", value2[], value1[], , #state )

            endif

            i=i+1

            continue

            wait sec 1.0

         endwhile

      else

         PrintString(911, $prog_info[1].pro_ip_name[], "The signal of [%1] is not declared!", semaphoreName[], , )

         ResetProgram()

      endif

   endif

END

---------------------------------------------------

一般情况下,没办法通过io信号的名称索引到$OUT[....]或者$IN[...]。需要使用GET_SIG_INF()这个函数实现。

------

紫色标记的语句建议不要用递归调用去替换,因为很容易引发堆栈警告。

-------------------------------------------------------------------------------------------


正在下载,请等待……
下载附件需1积分!



fighting2021

  • [管理员]
  • 精华:4帖
  • 求助:4帖
  • 帖子:1352帖 | 8409回
  • 年度积分:592
  • 历史总积分:24101
  • 注册:2008年11月11日
发表于:2026-08-07 15:18:25
1楼

感谢分享

回复本条

    

热门招聘
相关主题

官方公众号

智造工程师