Skip to content

Commit 9f87494

Browse files
committed
Merge pull request #49 from linas/mrg
Merge Mandeep's work (pull request #45)
2 parents 3fd059a + 7ec5665 commit 9f87494

File tree

3 files changed

+242
-0
lines changed

3 files changed

+242
-0
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ INSTALL (FILES
77
# Install the Eva and Sophia config files; however, the scheme module
88
# will not load the config parameters -- that has to be done by hand.
99
INSTALL (FILES
10+
psi-behavior.scm
1011
behavior.scm
1112
express.scm
1213
primitives.scm

src/btree-psi.scm

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
;
2+
; btree-psi.scm
3+
;
4+
; OpenPsi-based Eva behavior action selection (for the Eva blender
5+
; model animations).
6+
;
7+
; Runs a set of defined behaviors that express Eva's personality.
8+
; This version integrates the OpenCog chatbot.
9+
;
10+
; The currently-defined behaviors include acknowledging new people who
11+
; enter the room, rotating attention between multiple occupants of the
12+
; room, falling asleep when bored (i.e. the room is empty), and acting
13+
; surprised when someone leaves unexpectedly.
14+
;
15+
; HOWTO:
16+
; Run the main loop:
17+
; (run)
18+
; Pause the main loop:
19+
; (halt)
20+
;
21+
; Make sure that you did a `cmake` and `make install` first!
22+
;
23+
; Unit testing: See `unit-test.scm` and also notes in `behavior.scm`.
24+
;
25+
26+
(add-to-load-path "/usr/local/share/opencog/scm")
27+
28+
(use-modules (opencog))
29+
(use-modules (opencog query)) ; XXX work-around relex2logic bug
30+
31+
; Start the cogsserver. It is used by the face-tracker to poke data
32+
; into the atomspace.
33+
(use-modules (opencog cogserver))
34+
(start-cogserver "../scripts/opencog.conf")
35+
36+
; Load the behavior trees.
37+
(use-modules (opencog exec)) ; needed for cog-evaluate! in put_atoms.py
38+
(use-modules (opencog eva-model)) ; needed for defines in put_atoms.py
39+
(use-modules (opencog eva-behavior))
40+
(use-modules (opencog openpsi))
41+
42+
; Load the Eva personality configuration.
43+
; (display %load-path)
44+
(add-to-load-path "../src")
45+
(load-from-path "cfg-eva.scm") ;;; <<<=== See, its Eva here!
46+
47+
;; Call (run) to run the main loop, (halt) to pause the loop.
48+
;; The main loop runs in its own thread.
49+
(define (run) (behavior-tree-run))
50+
(define (halt) (behavior-tree-halt))
51+
52+
; ---------------------------------------------------------
53+
; Load the chat modules.
54+
;
55+
(use-modules (opencog nlp))
56+
(use-modules (opencog nlp chatbot))
57+
58+
; Work-around to weird bug: must load relex2logic at the top level.
59+
(use-modules (opencog nlp relex2logic))
60+
61+
; Work-around to circular dependency: define `dispatch-text` at the
62+
; top level of the guile executation environment.
63+
(define-public (dispatch-text txt)
64+
"
65+
dispatch-text TEXT
66+
67+
Pass the TEXT that STT heard into the OpenCog chatbot.
68+
"
69+
(call-with-new-thread
70+
; Must run in a new thread, else it deadlocks in python,
71+
; since the text processing results in python calls.
72+
; (lambda () (process-query "luser" (cog-name txt)))
73+
; (lambda () (grounded-talk "luser" (cog-name txt)))
74+
(lambda () (chat (cog-name txt)))
75+
)
76+
(stv 1 1)
77+
)
78+
79+
; ---------------------------------------------------------
80+
; Run the hacky garbage collection loop.
81+
(run-behavior-tree-gc)
82+
83+
; Silence the output.
84+
*unspecified*
85+
86+
;; Actually set it running, by default.
87+
(all-threads) ; print out the curent threads.
88+
(run)

src/psi-behavior.scm

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
;
2+
; psi-behvaior.scm
3+
(use-modules (ice-9 format))
4+
5+
6+
(add-to-load-path "/usr/local/share/opencog/scm")
7+
(use-modules (opencog))
8+
(use-modules (opencog exec))
9+
(use-modules (opencog openpsi))
10+
;
11+
;;
12+
(define (pred-2-schema pnode-str)
13+
(DefineLink
14+
(DefinedSchemaNode pnode-str)
15+
(ExecutionOutputLink (GroundedSchemaNode "scm: cog-evaluate!")
16+
(ListLink (DefinedPredicateNode pnode-str))
17+
)))
18+
;;
19+
(pred-2-schema "Interaction requested action")
20+
(pred-2-schema "New arrival sequence action")
21+
(pred-2-schema "Someone left action")
22+
(pred-2-schema "Interact with people action")
23+
(pred-2-schema "Nothing is happening action")
24+
(pred-2-schema "Speech started? action")
25+
(pred-2-schema "Speech ongoing? action")
26+
(pred-2-schema "Speech ended? action")
27+
(pred-2-schema "Listening started? action")
28+
(pred-2-schema "Listening? action")
29+
(pred-2-schema "Listening ended? action")
30+
(pred-2-schema "Keep alive")
31+
;;
32+
;(DefineLink (DefinedPredicateNode "do-noop") (True))
33+
;(pred-2-schema "do-noop")
34+
35+
(define demand-satisfied (True))
36+
(define speech-demand-satisfied (True))
37+
(define face-demand (psi-demand "face interaction" 1))
38+
(define speech-demand (psi-demand "speech interaction" 1))
39+
(define run-demand (psi-demand "run demand" 1))
40+
41+
;(psi-rule (list (DefinedPredicate "Interaction requested"))(DefinedSchemaNode "Interaction requested action") demand-satisfied (stv 1 1) face-demand)
42+
;(psi-rule (list (DefinedPredicate "New arrival sequence")) (DefinedSchemaNode "New arrival sequence action") demand-satisfied (stv 1 1) face-demand)
43+
;(psi-rule (list (DefinedPredicate "Someone left")) (DefinedSchemaNode "Someone left action") demand-satisfied (stv 1 1) face-demand)
44+
;(psi-rule (list (DefinedPredicate "Interact with people")) (DefinedSchemaNode "Interact with people action") demand-satisfied (stv 1 1) face-demand)
45+
;(psi-rule (list (DefinedPredicate "Nothing is happening")) (DefinedSchemaNode "Nothing is happening action") demand-satisfied (stv 1 1) face-demand)
46+
;(psi-rule (list (DefinedPredicate "Speech started?")) (DefinedSchemaNode "Speech started? action") speech-demand-satisfied (stv 1 1) speech-demand)
47+
;(psi-rule (list (DefinedPredicate "Speech ongoing?")) (DefinedSchemaNode "Speech ongoing? action") speech-demand-satisfied (stv 1 1) speech-demand)
48+
;(psi-rule (list (DefinedPredicate "Speech ended?")) (DefinedSchemaNode "Speech ended? action") speech-demand-satisfied (stv 1 1) speech-demand)
49+
;(psi-rule (list (DefinedPredicate "Skip Interaction?")) (DefinedSchemaNode "Keep alive") speech-demand-satisfied (stv 1 1) speech-demand)
50+
51+
52+
(psi-rule (list (NotLink(DefinedPredicate "Skip Interaction?"))
53+
(DefinedPredicate "Interaction requested"))
54+
(DefinedSchemaNode "Interaction requested action")
55+
demand-satisfied (stv 1 1) face-demand)
56+
57+
(psi-rule (list (NotLink(DefinedPredicate "Skip Interaction?"))
58+
(DefinedPredicate "New arrival sequence"))
59+
(DefinedSchemaNode "New arrival sequence action")
60+
demand-satisfied (stv 1 1) face-demand)
61+
62+
(psi-rule (list (NotLink(DefinedPredicate "Skip Interaction?"))
63+
(DefinedPredicate "Someone left"))
64+
(DefinedSchemaNode "Someone left action")
65+
demand-satisfied (stv 1 1) face-demand)
66+
67+
(psi-rule (list (NotLink(DefinedPredicate "Skip Interaction?"))
68+
(DefinedPredicate "Interact with people"))
69+
(DefinedSchemaNode "Interact with people action")
70+
demand-satisfied (stv 1 1) face-demand)
71+
72+
(psi-rule (list (NotLink(DefinedPredicate "Skip Interaction?"))
73+
(DefinedPredicate "Nothing is happening"))
74+
(DefinedSchemaNode "Nothing is happening action")
75+
demand-satisfied (stv 1 1) face-demand)
76+
77+
(psi-rule (list (NotLink(DefinedPredicate "Skip Interaction?"))
78+
(DefinedPredicate "Speech started?"))
79+
(DefinedSchemaNode "Speech started? action")
80+
speech-demand-satisfied (stv 1 1) speech-demand)
81+
82+
(psi-rule (list (NotLink(DefinedPredicate "Skip Interaction?"))
83+
(DefinedPredicate "Speech ongoing?"))
84+
(DefinedSchemaNode "Speech ongoing? action")
85+
speech-demand-satisfied (stv 1 1) speech-demand)
86+
87+
(psi-rule (list (NotLink(DefinedPredicate "Skip Interaction?"))
88+
(DefinedPredicate "Speech ended?"))
89+
(DefinedSchemaNode "Speech ended? action")
90+
speech-demand-satisfied (stv 1 1) speech-demand)
91+
92+
(psi-rule (list (NotLink(DefinedPredicate "Skip Interaction?"))
93+
(DefinedPredicate "Listening started?"))
94+
(DefinedSchemaNode "Listening started? action")
95+
speech-demand-satisfied (stv 1 1) speech-demand)
96+
97+
(psi-rule (list (NotLink(DefinedPredicate "Skip Interaction?"))
98+
(DefinedPredicate "Listening?"))
99+
(DefinedSchemaNode "Listening? action")
100+
speech-demand-satisfied (stv 1 1) speech-demand)
101+
102+
(psi-rule (list (NotLink(DefinedPredicate "Skip Interaction?"))
103+
(DefinedPredicate "Listening ended?"))
104+
(DefinedSchemaNode "Listening ended? action")
105+
speech-demand-satisfied (stv 1 1) speech-demand)
106+
107+
(psi-rule (list (DefinedPredicate "Skip Interaction?"))
108+
(DefinedSchemaNode "Keep alive")
109+
speech-demand-satisfied (stv 1 1) speech-demand)
110+
111+
;; ------------------------------------------------------------------
112+
;; Main loop. Uses tail recursion optimization to form the loop.
113+
(DefineLink
114+
(DefinedPredicate "main loop")
115+
(SatisfactionLink
116+
(SequentialAnd
117+
; (SequentialOr
118+
; (DefinedPredicate "Skip Interaction?")
119+
; (DefinedPredicate "Interaction requested")
120+
; (DefinedPredicate "New arrival sequence")
121+
; (DefinedPredicate "Someone left")
122+
; (DefinedPredicate "Interact with people")
123+
; (DefinedPredicate "Nothing is happening")
124+
; (True))
125+
126+
; ;; XXX FIXME chatbot is disengaged from everything else.
127+
; ;; The room can be empty, the head is bored or even asleep,
128+
; ;; but the chatbot is still smiling and yabbering.
129+
; ;; If interaction is turned-off need keep alive gestures
130+
; (SequentialOr
131+
; (DefinedPredicate "Speech started?")
132+
; (DefinedPredicate "Speech ongoing?")
133+
; (DefinedPredicate "Speech ended?")
134+
; (DefinedPredicate "Listening started?")
135+
; (DefinedPredicate "Listening?")
136+
; (DefinedPredicate "Listening ended?")
137+
; (SequentialAnd
138+
; (DefinedPredicate "Skip Interaction?")
139+
; (DefinedPredicate "Keep alive")
140+
; )
141+
; (True)
142+
; )
143+
144+
; If ROS is dead, or the continue flag not set, then stop
145+
; running the behavior loop.
146+
(DefinedPredicate "Continue running loop?")
147+
(DefinedPredicate "ROS is running?")
148+
149+
;; Call self -- tail-recurse.
150+
(DefinedPredicate "main loop")
151+
)))
152+
153+
; ----------------------------------------------------------------------

0 commit comments

Comments
 (0)