Coronavirus (Covid-19): Latest updates and information
Skip to main content Skip to navigation

LSD account for a cat flap (Simon Yung)

LSD account for a Cat Flap

/*******************************************************************
file : catflap.lsd
date : 1990
author : S.Yung
notes : Description of agents for a 'catflap' system
********************************************************************/

AGENT flap() {
STATE-HANDLE
(int) lflap = 5 // the length of the flap
(int) angle = 0 // the inclination of the flap
(bool) switch = true // whether the electronic lock is operating
(int) fourWayLock = 0 // fourWayLock =
// 0 - the cat can pass through from either direction
// 1 - the cat can go out only
// 2 - the cat can go in only
// 3 - the cat cannot pass through from either direction
(int) Radius = 10 // range of the detector of the electronic lock
STATE-ORACLE
(bool) pushOut
(bool) pushIn
STATE
(int) pos
DERIVATE-STATE
(bool) elecLock = abs(pos) > Radius AND switch
(bool) canPushOut = angle != 0 OR !elecLock AND (fourWayLock == 0 OR fourWayLock == 1)
(bool) canPushIn = angle != 0 OR !elecLock AND (fourWayLock == 0 OR fourWayLock == 2)
PROTOCOL
pushOut AND canPushOut -> angle = |angle| + 1
pushIn AND canPushIn -> angle = |angle| - 1
!pushOut AND !pushIn AND angle > 0 -> angle = |angle| - 1
!pushOut AND !pushIn AND angle < 0 -> angle = |angle| + 1
}

// the 4-way-lock is rotated only when the flap is closed
AGENT man() {
HANDLE-ORACLE
(bool) switch
(int) fourWayLock
ORACLE
(int) angle
PROTOCOL
switch == false -> switch = true
switch == true -> switch = false
angle == 0 AND fourWayLock != 0 -> fourWayLock = 0
angle == 0 AND fourWayLock != 1 -> fourWayLock = 1
angle == 0 AND fourWayLock != 2 -> fourWayLock = 2
angle == 0 AND fourWayLock != 3 -> fourWayLock = 3
}

AGENT cat() {
STATE-HANDLE
(int) height = 2 // height of the cat
(int) pos // pos > 0 - outside the house; < 0 inside the house
(int) intention // intention =
// 1 - is going out
// 0 - is staying put
// -1 - is coming in
ORACLE
(int) lflap, angle
DERIVATE-STATE
(bool) obstructOut = lflap * tan(angle) > pos > (lflap - height) * tan(angle) - 1
(bool) obstructIn = lflap * tan(angle) < pos < (lflap - height) * tan(angle) + 1
DERIVATE
(bool) pushOut = intention > 0 AND obstructOut
(bool) pushIn = intention < 0 AND obstructIn
PROTOCOL
intention > 0 AND !obstructOut -> pos = |pos| + 1
intention < 0 AND !obstructIn -> pos = |pos| - 1
true -> intention = 1
true -> intention = 0
true -> intention = -1
}