freetype UP_DOWN == { Up, Down, udIdle }

dynamic function TableElevationMot : UP_DOWN
initially udIdle

dynamic function TableRotationMot : ROTATION
initially rIdle

output function MinRotation : BOOL

output function MaxRotation : BOOL

output function ErtInBottomPosition : BOOL

output function ErtInTopPosition : BOOL


dynamic relation TableLoaded
initially false

derived relation StoppedInLoadPosition ==

  ErtInBottomPosition and MinRotation and TableElevationMot = udIdle
  and TableRotationMot = rIdle


derived relation StoppedInUnloadPosition ==

  ErtInTopPosition and MaxRotation and TableElevationMot = udIdle
  and TableRotationMot = rIdle



transition WAITING_LOAD ==

  if StoppedInLoadPosition and TableLoaded
  then TableElevationMot := Up
       TableRotationMot  := Clockwise
  endif


transition MOVING_UNLOAD ==

  if TableElevationMot = Up and ErtInTopPosition
  then TableElevationMot := udIdle
  endif


  if TableRotationMot = Clockwise and MaxRotation
  then TableRotationMot := rIdle
  endif



transition WAITING_UNLOAD ==

  if StoppedInUnloadPosition and not( TableLoaded )
  then TableElevationMot := Down
       TableRotationMot  := CounterClock
  endif


transition MOVING_LOAD ==

  if TableElevationMot = Down and ErtInBottomPosition
  then TableElevationMot := udIdle
  endif

  if TableRotationMot = CounterClock and MinRotation
  then TableRotationMot := rIdle
  endif