dynamic function DepBeltMot : ON_OFF
initially On

dynamic relation Critical
initially false

dynamic relation PieceAtDepositBeltEnd
initially false

dynamic relation DepositBeltReadyForLoading
initially true

output function PieceInDepositBeltLightBarrier : BOOL


derived relation DB_NormalRun ==

  DepBeltMot = On and not ( Critical )


derived relation DB_CriticalRun ==

  DepBeltMot = On and Critical


derived relation DB_Stopped ==

  DepBeltMot = Off


transition DB_NORMAL ==

  if DB_NormalRun and PieceInDepositBeltLightBarrier
  then Critical := true
  endif


transition DB_CRITICAL ==

  if DB_CriticalRun and not ( PieceInDepositBeltLightBarrier )
  then DepBeltMot                 := Off
       DepositBeltReadyForLoading := true
       PieceAtDepositBeltEnd      := true
  endif


transition DB_STOPPED ==

  if DB_Stopped and not ( PieceAtDepositBeltEnd )
  then DepBeltMot := On
       Critical   := false
  endif