aboutsummaryrefslogtreecommitdiff
path: root/behaviors/BehaviorChain.py
blob: fe5057335484d7fcb7de32546bf635e25c22a060 (plain)
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
from operationscore.Behavior import *
import Util
import pdb
class BehaviorChain(Behavior):
    def behaviorInit(self):
        self.feedback = {} #dictionary to allow feedback of recursives
        self.hooks = self['RecursiveHooks']
        if self.hooks == None:
            self.hooks = {}
    def processResponse(self, sensorInputs, recursiveInputs):
        response = sensorInputs
        for behaviorId in self['ChainedBehaviors']:
            behavior = Util.getComponentById(behaviorId)
            if behaviorId in self.feedback:
                recurrence = self.feedback[behaviorId]
            else:
                recurrence = []
            (response,recurrence) = behavior.immediateProcessInput(response,\
                    recurrence)

            if behaviorId in self.hooks: #process recursive hook if there is one
                hookBehavior = Util.getComponentById(self.hooks[behaviorId])
#we feed its recurrence in as input to the behavior.  
                (recurrence, hookRecurrence) = \
                hookBehavior.immediateProcessInput(recurrence, \
                        [])
                if hookRecurrence != []:
                    print 'Hook recurrences are not currently supported.  Implement it yourself or bug russell'
            self.feedback[behaviorId] = recurrence 
        return response