Skip to content

Commit 102ac2c

Browse files
committed
Merge pull request #51 from linas/psy
Create OpenPsi version of behavior control
2 parents 593c2ff + af05bc2 commit 102ac2c

File tree

9 files changed

+226
-192
lines changed

9 files changed

+226
-192
lines changed

src/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,11 @@ A list of random ideas.
185185
(DefinedPredicateNode "Is interacting with someone?")
186186

187187
Everything emitted to ROS is a state.... look for the behavior pubs.
188+
189+
----------------
190+
191+
Pending bugs:
192+
* (DefinedPredicateNode "Did someone leave?") being called much much
193+
too often!!! ... why???
194+
* Psi hung ... for no apparent reason.
195+
(psi-running?) (psi-get-loop-count)

src/atomic-dbg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ def blink_rate(mean_node, var_node):
174174
return TruthValue(1, 1)
175175

176176
def say_text(text_node):
177-
text = text_node.name
177+
text = text_node.name
178178
print "(Eva says: ", text, ")"
179-
# evl.say_text(text)
180-
return TruthValue(1, 1)
179+
# evl.say_text(text)
180+
return TruthValue(1, 1)
181181

182182
# Return true as long as ROS is running.
183183
def ros_is_running():

src/behavior.scm

Lines changed: 68 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129

130130
;; Show random expressions only if NOT talking
131131
(SequentialOr
132-
;(Not (DefinedPredicate "chatbot is listening"))
132+
;(Not (DefinedPredicate "chatbot is listening?"))
133133
(SequentialAnd
134134

135135
(SequentialOrLink
@@ -170,9 +170,8 @@
170170
;; If interaction is requested, then interact with that specific person.
171171
;; Make sure we look at that person ...
172172
(DefineLink
173-
(DefinedPredicate "Interaction requested")
173+
(DefinedPredicate "Interaction requested action")
174174
(SequentialAnd
175-
(DefinedPredicate "Someone requests interaction?")
176175
(True (DefinedPredicate "If sleeping then wake"))
177176
(True (DefinedPredicate "If bored then alert"))
178177
(DefinedPredicate "interact with requested person")
@@ -198,7 +197,7 @@
198197

199198
;; Respond to a new face becoming visible.
200199
;
201-
;; XXX TODO -- need to also do line 590, if interacting for a while
200+
;; XXX TODO -- if interacting for a while
202201
;; this alters probability of glance...
203202
(DefineLink
204203
(DefinedPredicate "Respond to new arrival")
@@ -235,7 +234,6 @@
235234
(DefineLink
236235
(DefinedPredicate "New arrival sequence")
237236
(SequentialAnd
238-
(DefinedPredicate "Did someone arrive?")
239237
(True (DefinedPredicate "If sleeping then wake"))
240238
(True (DefinedPredicate "If bored then alert"))
241239
(DefinedPredicate "Respond to new arrival")
@@ -244,9 +242,8 @@
244242

245243
;; Check to see if someone left.
246244
(DefineLink
247-
(DefinedPredicate "Someone left")
245+
(DefinedPredicate "Someone left action")
248246
(SequentialAnd
249-
(DefinedPredicate "Did someone leave?")
250247
(Put (DefinedPredicate "Publish behavior")
251248
(Concept "Someone left"))
252249
(Evaluation (GroundedPredicate "scm: print-msg")
@@ -287,9 +284,6 @@
287284
(DefineLink
288285
(DefinedPredicate "Interact with people")
289286
(SequentialAnd
290-
; True, if there is anyone visible.
291-
(DefinedPredicate "Someone visible")
292-
293287
; Say something, if no one else has said anything in a while.
294288
; i.e. if are being ignored, then say something.
295289
; (SequentialOr
@@ -559,11 +553,9 @@
559553
; Things to do, if TTS vocalization just started.
560554
(DefineLink
561555
; owyl "chatbot_speech_start()" method
562-
(DefinedPredicate "Speech started?")
556+
(DefinedPredicate "Speech started")
563557
(SequentialAnd
564-
; If the TTS vocalization started (chatbot started talking) ...
565-
(DefinedPredicate "chatbot started talking")
566-
; ... then switch to face-study saccade ...
558+
; Switch to face-study saccade ...
567559
(Evaluation (GroundedPredicate "py:conversational_saccade")
568560
(ListLink))
569561
; ... and show one random gesture from "conversing" set.
@@ -580,12 +572,12 @@
580572
(ListLink (Node "--- Start talking")))
581573
))
582574

583-
; Currently used for scripted behaviors while STT doesnt publish accurate events.
575+
; Currently used for scripted behaviors while STT doesn't publish
576+
; accurate events.
584577
(DefineLink
585-
(DefinedPredicate "Listening started?")
578+
(DefinedPredicate "Listening started")
586579
(SequentialAnd
587-
(DefinedPredicate "chatbot started listening")
588-
; ... then switch to face-study saccade ...
580+
; Switch to face-study saccade ...
589581
(Evaluation (GroundedPredicate "py:listening_saccade")
590582
(ListLink))
591583
; ... and show one random gesture from "conversing" set.
@@ -604,11 +596,9 @@
604596

605597
;; Things to do, if the chatbot is currently talking.
606598
(DefineLink
607-
(DefinedPredicate "Speech ongoing?")
599+
(DefinedPredicate "Speech ongoing")
608600
(SequentialAnd
609-
; If the chatbot currently talking ...
610-
(DefinedPredicate "chatbot is talking")
611-
; ... then handle the various affect states.
601+
; Handle the various affect states.
612602
(SequentialOr
613603
(SequentialAnd
614604
; If chatbot is happy ...
@@ -664,12 +654,9 @@
664654

665655
; Things to do, if the chattbot stopped talking.
666656
(DefineLink
667-
(DefinedPredicate "Speech ended?")
657+
(DefinedPredicate "Speech ended")
668658
(SequentialAnd
669-
; If the chatbot stopped talking ...
670-
(DefinedPredicate "chatbot stopped talking")
671-
672-
; ... then switch back to exploration saccade ...
659+
; Switch back to exploration saccade ...
673660
(Evaluation (GroundedPredicate "py:explore_saccade")
674661
(ListLink))
675662

@@ -689,12 +676,9 @@
689676

690677
; Things to do, if stopped listening.
691678
(DefineLink
692-
(DefinedPredicate "Listening ended?")
679+
(DefinedPredicate "Listening ended")
693680
(SequentialAnd
694-
; If the chatbot stopped talking ...
695-
(DefinedPredicate "chatbot stopped listening")
696-
697-
; ... then switch back to exploration saccade ...
681+
; Switch back to exploration saccade ...
698682
(Evaluation (GroundedPredicate "py:explore_saccade")
699683
(ListLink))
700684

@@ -714,11 +698,9 @@
714698

715699
; Things to do, if the chatbot is listening.
716700
(DefineLink
717-
(DefinedPredicate "Listening?")
701+
(DefinedPredicate "Listening ongoing")
718702
(SequentialAnd
719-
; If the chatbot stopped talking ...
720-
(DefinedPredicate "chatbot is listening")
721-
; ... show one of the neutral-speech expressions
703+
; Show one of the neutral-speech expressions
722704
(SequentialOr
723705
(Not (DefinedPredicate "Time to change expression"))
724706
(Put (DefinedPredicateNode "Show random expression")
@@ -765,11 +747,25 @@
765747
(SatisfactionLink
766748
(SequentialAnd
767749
(SequentialOr
768-
(DefinedPredicate "Skip Interaction?")
769-
(DefinedPredicate "Interaction requested")
770-
(DefinedPredicate "New arrival sequence")
771-
(DefinedPredicate "Someone left")
772-
(DefinedPredicate "Interact with people")
750+
(DefinedPredicate "Skip Interaction?")
751+
752+
(SequentialAnd
753+
(DefinedPredicate "Someone requests interaction?")
754+
(DefinedPredicate "Interaction requested action"))
755+
756+
(SequentialAnd
757+
(DefinedPredicate "Did someone arrive?")
758+
(DefinedPredicate "New arrival sequence"))
759+
760+
(SequentialAnd
761+
(DefinedPredicate "Did someone leave?")
762+
(DefinedPredicate "Someone left action"))
763+
764+
; True, if there is anyone visible.
765+
(SequentialAnd
766+
(DefinedPredicate "Someone visible?")
767+
(DefinedPredicate "Interact with people"))
768+
773769
(DefinedPredicate "Nothing is happening")
774770
(True))
775771

@@ -778,16 +774,39 @@
778774
;; but the chatbot is still smiling and yabbering.
779775
;; If interaction is turned-off need keep alive gestures
780776
(SequentialOr
781-
(DefinedPredicate "Speech started?")
782-
(DefinedPredicate "Speech ongoing?")
783-
(DefinedPredicate "Speech ended?")
784-
(DefinedPredicate "Listening started?")
785-
(DefinedPredicate "Listening?")
786-
(DefinedPredicate "Listening ended?")
777+
; If the TTS vocalization started (chatbot started talking) ...
778+
(SequentialAnd
779+
(DefinedPredicate "chatbot started talking?")
780+
(DefinedPredicate "Speech started"))
781+
782+
; If the chatbot currently talking ...
783+
(SequentialAnd
784+
(DefinedPredicate "chatbot is talking?")
785+
(DefinedPredicate "Speech ongoing"))
786+
787+
; If the chatbot stopped talking ...
788+
(SequentialAnd
789+
(DefinedPredicate "chatbot stopped talking?")
790+
(DefinedPredicate "Speech ended"))
791+
792+
(SequentialAnd
793+
(DefinedPredicate "chatbot started listening?")
794+
(DefinedPredicate "Listening started"))
795+
796+
; If the chatbot stopped talking ...
797+
(SequentialAnd
798+
(DefinedPredicate "chatbot is listening?")
799+
(DefinedPredicate "Listening ongoing"))
800+
801+
; If the chatbot stopped talking ...
802+
(SequentialAnd
803+
(DefinedPredicate "chatbot stopped listening?")
804+
(DefinedPredicate "Listening ended"))
805+
787806
(SequentialAnd
788807
(DefinedPredicate "Skip Interaction?")
789-
(DefinedPredicate "Keep alive")
790-
)
808+
(DefinedPredicate "Keep alive"))
809+
791810
(True)
792811
)
793812

src/btree-eva.scm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@
5757
(use-modules (opencog nlp relex2logic))
5858

5959
; Work-around to circular dependency: define `dispatch-text` at the
60-
; top level of the guile executation environment.
61-
(define-public (dispatch-text txt)
60+
; top level of the guile execution environment.
61+
(define-public (dispatch-text TXT-ATOM)
6262
"
63-
dispatch-text TEXT
63+
dispatch-text TXT-ATOM
6464
65-
Pass the TEXT that STT heard into the OpenCog chatbot.
65+
Pass the TXT-ATOM that STT heard into the OpenCog chatbot.
6666
"
6767
(call-with-new-thread
6868
; Must run in a new thread, else it deadlocks in python,
6969
; since the text processing results in python calls.
70-
; (lambda () (process-query "luser" (cog-name txt)))
71-
(lambda () (grounded-talk "luser" (cog-name txt)))
70+
; (lambda () (process-query "luser" (cog-name TXT-ATOM)))
71+
(lambda () (grounded-talk "luser" (cog-name TXT-ATOM)))
7272
)
7373
(stv 1 1)
7474
)

src/btree-psi.scm

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,33 @@
4242
; Load the Eva personality configuration.
4343
; (display %load-path)
4444
(add-to-load-path "../src")
45-
(load-from-path "cfg-eva.scm") ;;; <<<=== See, its Eva here!
45+
; (load-from-path "cfg-eva.scm") ;;; <<<=== See, its Eva here!
46+
(load-from-path "cfg-sophia.scm") ;;; <<<=== See, its Sophia here!
47+
48+
;; Load the actual psi rules.
49+
(load-from-path "psi-behavior.scm")
50+
51+
; There MUST be a DefinedPredicateNode with exactly the name
52+
; below in order for psi-run to work. Or we could just blow
53+
; that off, and use our own loop...
54+
(define loop-name (string-append psi-prefix-str "loop"))
55+
(DefineLink
56+
(DefinedPredicate loop-name)
57+
(SatisfactionLink
58+
(SequentialAnd
59+
(Evaluation (GroundedPredicate "scm: psi-step")
60+
(ListLink))
61+
(Evaluation (GroundedPredicate "scm: psi-run-continue?")
62+
(ListLink))
63+
; If ROS is dead, or the continue flag not set,
64+
; then stop running the behavior loop.
65+
(DefinedPredicate "ROS is running?")
66+
(DefinedPredicate loop-name))))
4667

4768
;; Call (run) to run the main loop, (halt) to pause the loop.
4869
;; The main loop runs in its own thread.
49-
(define (run) (behavior-tree-run))
50-
(define (halt) (behavior-tree-halt))
70+
(define (run) (psi-run))
71+
(define (halt) (psi-halt))
5172

5273
; ---------------------------------------------------------
5374
; Load the chat modules.
@@ -59,26 +80,26 @@
5980
(use-modules (opencog nlp relex2logic))
6081

6182
; Work-around to circular dependency: define `dispatch-text` at the
62-
; top level of the guile executation environment.
63-
(define-public (dispatch-text txt)
83+
; top level of the guile execution environment.
84+
(define-public (dispatch-text TXT-ATOM)
6485
"
65-
dispatch-text TEXT
86+
dispatch-text TXT-ATOM
6687
67-
Pass the TEXT that STT heard into the OpenCog chatbot.
88+
Pass the TXT-ATOM that STT heard into the OpenCog chatbot.
6889
"
6990
(call-with-new-thread
7091
; Must run in a new thread, else it deadlocks in python,
7192
; 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)))
93+
; (lambda () (process-query "luser" (cog-name TXT-ATOM)))
94+
; (lambda () (grounded-talk "luser" (cog-name TXT-ATOM)))
95+
(lambda () (chat (cog-name TXT-ATOM)))
7596
)
7697
(stv 1 1)
7798
)
7899

79100
; ---------------------------------------------------------
80101
; Run the hacky garbage collection loop.
81-
(run-behavior-tree-gc)
102+
; (run-behavior-tree-gc)
82103

83104
; Silence the output.
84105
*unspecified*

src/btree.scm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,20 @@
7474
;(use-modules (opencog nlp relex2logic))
7575

7676
; Work-around to circular dependency: define `dispatch-text` at the
77-
; top level of the guile executation environment.
78-
(define-public (dispatch-text txt)
77+
; top level of the guile execution environment.
78+
(define-public (dispatch-text TXT-ATOM)
7979
"
80-
dispatch-text TEXT
80+
dispatch-text TXT-ATOM
8181
82-
Pass the TEXT that STT heard into the OpenCog chatbot.
82+
Pass the TXT-ATOM that STT heard into the OpenCog chatbot.
8383
"
8484
; (call-with-new-thread
8585
; Must run in a new thread, else it deadlocks in python,
8686
; since the text processing results in python calls.
87-
; (lambda () (process-query "luser" (cog-name txt)))
88-
; (lambda () (grounded-talk "luser" (cog-name txt)))
87+
; (lambda () (process-query "luser" (cog-name TXT-ATOM)))
88+
; (lambda () (grounded-talk "luser" (cog-name TXT-ATOM)))
8989
; XXX Need to ... auuh load the chatbot...
90-
; (lambda () (chat txt))
90+
; (lambda () (chat TXT-ATOM))
9191
; )
9292
(stv 1 1)
9393
)

0 commit comments

Comments
 (0)