;;;====================================================== ;;; Intelligent Environment Sample Rules ;;; ;;; To execute, merely load, reset and run. ;;;====================================================== (deffacts initial-state (run) (time 7 15) (location 1 t) (location 2 f) (location 3 f) (location 4 f) (location 5 f) (location 6 f) (lights 1 off) (lights 2 off) (lights 3 off) (lights 4 off) (lights 5 off) (lights 6 off) (ac 1 off) (ac 2 off) (ac 3 off) (ac 4 off) (ac 5 off) (ac 6 off) (temperature 1 70) (temperature 2 70) (temperature 3 70) (temperature 4 70) (temperature 5 70) (temperature 6 70) (robot-location 3) (robot-sens 0 0 0) (power 0) (light-cost 1.5) (heat-cost 20) (ac-cost 25) (robot-com 0)) ;;;***************************** ;;; rules for the robot control ;;;***************************** ;; ;; moves robot by x if (move-robot x) is set ;; (defrule move-robot ?act <- (move-robot ?dist) ?com <- (robot-com 1) => (retract ?act) (retract ?com) (assert (robot-com (send_robot_move ?dist)))) ;; ;; turns robot by x if (turn-robot x) is set ;; (defrule turn-robot ?act <- (turn-robot ?dist) ?com <- (robot-com 1) => (retract ?act) (retract ?com) (assert (robot-com (send_robot_turn ?dist)))) ;;;***************************** ;;; rules to read robot sensors ;;;***************************** ;; ;; reads the sensors of the robot ;; (defrule read-robot-sensors ?act <- (read-robot) ?ostate <- (robot-sens ?enc1 ?enc2 ?lightsens) ?com <- (robot-com 1) => (retract ?act ?ostate) (retract ?com) (assert (robot-sens (get_robot_data 0) (get_robot_data 1) (get_robot_data 2))) (assert (robot-com 1))) ;;;***************************** ;;; rules for the device control ;;;***************************** ;; ;; toggles the ligth in room x if (toggle-light x) is set ;; (defrule toggle-light ?act <- (toggle-light ?room) ?olight <- (lights ?room ?state) => (retract ?act ?olight) (if (eq ?state off) then (assert (lights ?room on)) (printout t "Light in room " ?room " turned on" crlf) else (assert (lights ?room off)) (printout t "Light in room " ?room " turned off" crlf))) ;; ;; turns on the heat in room x if (turn-heat x) is set ;; (defrule turn-heat ?act <- (turn-heat ?room) ?olight <- (ac ?room ?state) => (retract ?act ?olight) (assert (ac ?room heat)) (if (or (eq ?state off) (eq ?state cool)) then (printout t "Heat in room " ?room " turned on" crlf))) ;; ;; turns on the ac in room x if (turn-ac x) is set ;; (defrule turn-ac ?act <- (turn-ac ?room) ?olight <- (ac ?room ?state) => (retract ?act ?olight) (assert (ac ?room cool)) (if (or (eq ?state off) (eq ?state heat)) then (printout t "AC in room " ?room " turned on" crlf))) ;; ;; turns off the ac/heat in room x if (turn-ac-off x) is set ;; (defrule turn-ac-off ?act <- (turn-ac-off ?room) ?olight <- (ac ?room ?state) => (retract ?act ?olight) (assert (ac ?room off)) (if (or (eq ?state heat) (eq ?state cool)) then (printout t "AC/Heat in room " ?room " turned off" crlf)))