Skip to content

Commit

Permalink
Merge pull request #51 from linas/psy
Browse files Browse the repository at this point in the history
Create OpenPsi version of behavior control
  • Loading branch information
linas committed Jun 7, 2016
2 parents 593c2ff + af05bc2 commit 102ac2c
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 192 deletions.
8 changes: 8 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,11 @@ A list of random ideas.
(DefinedPredicateNode "Is interacting with someone?")

Everything emitted to ROS is a state.... look for the behavior pubs.

----------------

Pending bugs:
* (DefinedPredicateNode "Did someone leave?") being called much much
too often!!! ... why???
* Psi hung ... for no apparent reason.
(psi-running?) (psi-get-loop-count)
6 changes: 3 additions & 3 deletions src/atomic-dbg.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ def blink_rate(mean_node, var_node):
return TruthValue(1, 1)

def say_text(text_node):
text = text_node.name
text = text_node.name
print "(Eva says: ", text, ")"
# evl.say_text(text)
return TruthValue(1, 1)
# evl.say_text(text)
return TruthValue(1, 1)

# Return true as long as ROS is running.
def ros_is_running():
Expand Down
117 changes: 68 additions & 49 deletions src/behavior.scm
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@

;; Show random expressions only if NOT talking
(SequentialOr
;(Not (DefinedPredicate "chatbot is listening"))
;(Not (DefinedPredicate "chatbot is listening?"))
(SequentialAnd

(SequentialOrLink
Expand Down Expand Up @@ -170,9 +170,8 @@
;; If interaction is requested, then interact with that specific person.
;; Make sure we look at that person ...
(DefineLink
(DefinedPredicate "Interaction requested")
(DefinedPredicate "Interaction requested action")
(SequentialAnd
(DefinedPredicate "Someone requests interaction?")
(True (DefinedPredicate "If sleeping then wake"))
(True (DefinedPredicate "If bored then alert"))
(DefinedPredicate "interact with requested person")
Expand All @@ -198,7 +197,7 @@

;; Respond to a new face becoming visible.
;
;; XXX TODO -- need to also do line 590, if interacting for a while
;; XXX TODO -- if interacting for a while
;; this alters probability of glance...
(DefineLink
(DefinedPredicate "Respond to new arrival")
Expand Down Expand Up @@ -235,7 +234,6 @@
(DefineLink
(DefinedPredicate "New arrival sequence")
(SequentialAnd
(DefinedPredicate "Did someone arrive?")
(True (DefinedPredicate "If sleeping then wake"))
(True (DefinedPredicate "If bored then alert"))
(DefinedPredicate "Respond to new arrival")
Expand All @@ -244,9 +242,8 @@

;; Check to see if someone left.
(DefineLink
(DefinedPredicate "Someone left")
(DefinedPredicate "Someone left action")
(SequentialAnd
(DefinedPredicate "Did someone leave?")
(Put (DefinedPredicate "Publish behavior")
(Concept "Someone left"))
(Evaluation (GroundedPredicate "scm: print-msg")
Expand Down Expand Up @@ -287,9 +284,6 @@
(DefineLink
(DefinedPredicate "Interact with people")
(SequentialAnd
; True, if there is anyone visible.
(DefinedPredicate "Someone visible")

; Say something, if no one else has said anything in a while.
; i.e. if are being ignored, then say something.
; (SequentialOr
Expand Down Expand Up @@ -559,11 +553,9 @@
; Things to do, if TTS vocalization just started.
(DefineLink
; owyl "chatbot_speech_start()" method
(DefinedPredicate "Speech started?")
(DefinedPredicate "Speech started")
(SequentialAnd
; If the TTS vocalization started (chatbot started talking) ...
(DefinedPredicate "chatbot started talking")
; ... then switch to face-study saccade ...
; Switch to face-study saccade ...
(Evaluation (GroundedPredicate "py:conversational_saccade")
(ListLink))
; ... and show one random gesture from "conversing" set.
Expand All @@ -580,12 +572,12 @@
(ListLink (Node "--- Start talking")))
))

; Currently used for scripted behaviors while STT doesnt publish accurate events.
; Currently used for scripted behaviors while STT doesn't publish
; accurate events.
(DefineLink
(DefinedPredicate "Listening started?")
(DefinedPredicate "Listening started")
(SequentialAnd
(DefinedPredicate "chatbot started listening")
; ... then switch to face-study saccade ...
; Switch to face-study saccade ...
(Evaluation (GroundedPredicate "py:listening_saccade")
(ListLink))
; ... and show one random gesture from "conversing" set.
Expand All @@ -604,11 +596,9 @@

;; Things to do, if the chatbot is currently talking.
(DefineLink
(DefinedPredicate "Speech ongoing?")
(DefinedPredicate "Speech ongoing")
(SequentialAnd
; If the chatbot currently talking ...
(DefinedPredicate "chatbot is talking")
; ... then handle the various affect states.
; Handle the various affect states.
(SequentialOr
(SequentialAnd
; If chatbot is happy ...
Expand Down Expand Up @@ -664,12 +654,9 @@

; Things to do, if the chattbot stopped talking.
(DefineLink
(DefinedPredicate "Speech ended?")
(DefinedPredicate "Speech ended")
(SequentialAnd
; If the chatbot stopped talking ...
(DefinedPredicate "chatbot stopped talking")

; ... then switch back to exploration saccade ...
; Switch back to exploration saccade ...
(Evaluation (GroundedPredicate "py:explore_saccade")
(ListLink))

Expand All @@ -689,12 +676,9 @@

; Things to do, if stopped listening.
(DefineLink
(DefinedPredicate "Listening ended?")
(DefinedPredicate "Listening ended")
(SequentialAnd
; If the chatbot stopped talking ...
(DefinedPredicate "chatbot stopped listening")

; ... then switch back to exploration saccade ...
; Switch back to exploration saccade ...
(Evaluation (GroundedPredicate "py:explore_saccade")
(ListLink))

Expand All @@ -714,11 +698,9 @@

; Things to do, if the chatbot is listening.
(DefineLink
(DefinedPredicate "Listening?")
(DefinedPredicate "Listening ongoing")
(SequentialAnd
; If the chatbot stopped talking ...
(DefinedPredicate "chatbot is listening")
; ... show one of the neutral-speech expressions
; Show one of the neutral-speech expressions
(SequentialOr
(Not (DefinedPredicate "Time to change expression"))
(Put (DefinedPredicateNode "Show random expression")
Expand Down Expand Up @@ -765,11 +747,25 @@
(SatisfactionLink
(SequentialAnd
(SequentialOr
(DefinedPredicate "Skip Interaction?")
(DefinedPredicate "Interaction requested")
(DefinedPredicate "New arrival sequence")
(DefinedPredicate "Someone left")
(DefinedPredicate "Interact with people")
(DefinedPredicate "Skip Interaction?")

(SequentialAnd
(DefinedPredicate "Someone requests interaction?")
(DefinedPredicate "Interaction requested action"))

(SequentialAnd
(DefinedPredicate "Did someone arrive?")
(DefinedPredicate "New arrival sequence"))

(SequentialAnd
(DefinedPredicate "Did someone leave?")
(DefinedPredicate "Someone left action"))

; True, if there is anyone visible.
(SequentialAnd
(DefinedPredicate "Someone visible?")
(DefinedPredicate "Interact with people"))

(DefinedPredicate "Nothing is happening")
(True))

Expand All @@ -778,16 +774,39 @@
;; but the chatbot is still smiling and yabbering.
;; If interaction is turned-off need keep alive gestures
(SequentialOr
(DefinedPredicate "Speech started?")
(DefinedPredicate "Speech ongoing?")
(DefinedPredicate "Speech ended?")
(DefinedPredicate "Listening started?")
(DefinedPredicate "Listening?")
(DefinedPredicate "Listening ended?")
; If the TTS vocalization started (chatbot started talking) ...
(SequentialAnd
(DefinedPredicate "chatbot started talking?")
(DefinedPredicate "Speech started"))

; If the chatbot currently talking ...
(SequentialAnd
(DefinedPredicate "chatbot is talking?")
(DefinedPredicate "Speech ongoing"))

; If the chatbot stopped talking ...
(SequentialAnd
(DefinedPredicate "chatbot stopped talking?")
(DefinedPredicate "Speech ended"))

(SequentialAnd
(DefinedPredicate "chatbot started listening?")
(DefinedPredicate "Listening started"))

; If the chatbot stopped talking ...
(SequentialAnd
(DefinedPredicate "chatbot is listening?")
(DefinedPredicate "Listening ongoing"))

; If the chatbot stopped talking ...
(SequentialAnd
(DefinedPredicate "chatbot stopped listening?")
(DefinedPredicate "Listening ended"))

(SequentialAnd
(DefinedPredicate "Skip Interaction?")
(DefinedPredicate "Keep alive")
)
(DefinedPredicate "Keep alive"))

(True)
)

Expand Down
12 changes: 6 additions & 6 deletions src/btree-eva.scm
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@
(use-modules (opencog nlp relex2logic))

; Work-around to circular dependency: define `dispatch-text` at the
; top level of the guile executation environment.
(define-public (dispatch-text txt)
; top level of the guile execution environment.
(define-public (dispatch-text TXT-ATOM)
"
dispatch-text TEXT
dispatch-text TXT-ATOM
Pass the TEXT that STT heard into the OpenCog chatbot.
Pass the TXT-ATOM that STT heard into the OpenCog chatbot.
"
(call-with-new-thread
; Must run in a new thread, else it deadlocks in python,
; since the text processing results in python calls.
; (lambda () (process-query "luser" (cog-name txt)))
(lambda () (grounded-talk "luser" (cog-name txt)))
; (lambda () (process-query "luser" (cog-name TXT-ATOM)))
(lambda () (grounded-talk "luser" (cog-name TXT-ATOM)))
)
(stv 1 1)
)
Expand Down
43 changes: 32 additions & 11 deletions src/btree-psi.scm
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,33 @@
; Load the Eva personality configuration.
; (display %load-path)
(add-to-load-path "../src")
(load-from-path "cfg-eva.scm") ;;; <<<=== See, its Eva here!
; (load-from-path "cfg-eva.scm") ;;; <<<=== See, its Eva here!
(load-from-path "cfg-sophia.scm") ;;; <<<=== See, its Sophia here!

;; Load the actual psi rules.
(load-from-path "psi-behavior.scm")

; There MUST be a DefinedPredicateNode with exactly the name
; below in order for psi-run to work. Or we could just blow
; that off, and use our own loop...
(define loop-name (string-append psi-prefix-str "loop"))
(DefineLink
(DefinedPredicate loop-name)
(SatisfactionLink
(SequentialAnd
(Evaluation (GroundedPredicate "scm: psi-step")
(ListLink))
(Evaluation (GroundedPredicate "scm: psi-run-continue?")
(ListLink))
; If ROS is dead, or the continue flag not set,
; then stop running the behavior loop.
(DefinedPredicate "ROS is running?")
(DefinedPredicate loop-name))))

;; Call (run) to run the main loop, (halt) to pause the loop.
;; The main loop runs in its own thread.
(define (run) (behavior-tree-run))
(define (halt) (behavior-tree-halt))
(define (run) (psi-run))
(define (halt) (psi-halt))

; ---------------------------------------------------------
; Load the chat modules.
Expand All @@ -59,26 +80,26 @@
(use-modules (opencog nlp relex2logic))

; Work-around to circular dependency: define `dispatch-text` at the
; top level of the guile executation environment.
(define-public (dispatch-text txt)
; top level of the guile execution environment.
(define-public (dispatch-text TXT-ATOM)
"
dispatch-text TEXT
dispatch-text TXT-ATOM
Pass the TEXT that STT heard into the OpenCog chatbot.
Pass the TXT-ATOM that STT heard into the OpenCog chatbot.
"
(call-with-new-thread
; Must run in a new thread, else it deadlocks in python,
; since the text processing results in python calls.
; (lambda () (process-query "luser" (cog-name txt)))
; (lambda () (grounded-talk "luser" (cog-name txt)))
(lambda () (chat (cog-name txt)))
; (lambda () (process-query "luser" (cog-name TXT-ATOM)))
; (lambda () (grounded-talk "luser" (cog-name TXT-ATOM)))
(lambda () (chat (cog-name TXT-ATOM)))
)
(stv 1 1)
)

; ---------------------------------------------------------
; Run the hacky garbage collection loop.
(run-behavior-tree-gc)
; (run-behavior-tree-gc)

; Silence the output.
*unspecified*
Expand Down
14 changes: 7 additions & 7 deletions src/btree.scm
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,20 @@
;(use-modules (opencog nlp relex2logic))

; Work-around to circular dependency: define `dispatch-text` at the
; top level of the guile executation environment.
(define-public (dispatch-text txt)
; top level of the guile execution environment.
(define-public (dispatch-text TXT-ATOM)
"
dispatch-text TEXT
dispatch-text TXT-ATOM
Pass the TEXT that STT heard into the OpenCog chatbot.
Pass the TXT-ATOM that STT heard into the OpenCog chatbot.
"
; (call-with-new-thread
; Must run in a new thread, else it deadlocks in python,
; since the text processing results in python calls.
; (lambda () (process-query "luser" (cog-name txt)))
; (lambda () (grounded-talk "luser" (cog-name txt)))
; (lambda () (process-query "luser" (cog-name TXT-ATOM)))
; (lambda () (grounded-talk "luser" (cog-name TXT-ATOM)))
; XXX Need to ... auuh load the chatbot...
; (lambda () (chat txt))
; (lambda () (chat TXT-ATOM))
; )
(stv 1 1)
)
Expand Down
Loading

0 comments on commit 102ac2c

Please sign in to comment.