forked from hansonrobotics/ros-behavior-scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbtree-demo.scm
85 lines (70 loc) · 2.13 KB
/
btree-demo.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
;
; btree-demo.scm
;
; A super-simplified example of a behavior tree, implemented
; in the atomspace. This is built with the same general conceptual
; design as the "real" behavior tree.
;
(add-to-load-path "/usr/local/share/opencog/scm")
(use-modules (opencog))
(use-modules (opencog query))
(use-modules (opencog exec))
(load-from-path "utilities.scm")
; ------------------------------------------------------
; Same as in eva-fsm.scm
; Is the room empty, or is someone in it?
(define room-state (AnchorNode "Room State"))
(define room-empty (ConceptNode "room empty"))
(define room-nonempty (ConceptNode "room nonempty"))
(define soma-state (AnchorNode "Soma State"))
(define soma-sleeping (ConceptNode "Sleeping"))
;; Assume room empty at first
(ListLink room-state room-empty)
(ListLink soma-state soma-sleeping)
(define (print-msg) (display "Triggered\n") (stv 1 1))
(define (print-atom atom) (format #t "Triggered: ~a \n" atom) (stv 1 1))
; ------------------------------------------------------
;;
;; Determine if the atomspace contains the link
;; (ListLink (AnchorNode "Room State") (ConceptNode "room empty"))
;; If the atomspace does contain the above, then the print-msg
;; function is run.
; ------------------------------------------------------
#|
(define empty-seq
(SatisfactionLink
(SequentialAndLink
(PresentLink (ListLink room-state (VariableNode "$x")))
(EqualLink (VariableNode "$x") room-empty)
(EvaluationLink
(GroundedPredicateNode "scm: print-msg")
(ListLink))
)))
|#
(DefineLink
(DefinedPredicateNode "is-empty")
(EqualLink
(SetLink room-empty)
(GetLink (ListLink room-state (VariableNode "$x")))
))
(DefineLink
(DefinedPredicateNode "is-sleeping")
(EqualLink
(SetLink soma-sleeping)
(GetLink (ListLink soma-state (VariableNode "$y")))
))
(DefineLink
(DefinedPredicateNode "Print Msg")
(EvaluationLink
(GroundedPredicateNode "scm: print-msg")
(ListLink))
)
(define empty-seq
(SatisfactionLink
(SequentialAndLink
(DefinedPredicateNode "is-empty")
(DefinedPredicateNode "Print Msg")
(DefinedPredicateNode "is-sleeping")
(DefinedPredicateNode "Print Msg")
)))
(cog-satisfy empty-seq)