diff options
author | Russell Cohen <rcoh@mit.edu> | 2010-11-29 00:00:26 -0500 |
---|---|---|
committer | Russell Cohen <rcoh@mit.edu> | 2010-11-29 00:00:26 -0500 |
commit | cf1f2224b3625b01a6aa7db221403849b308b3bc (patch) | |
tree | 9ad55077f45efc7a8434688332ee281a28a1cae7 /operationscore | |
parent | 9c9babfa7032b443138c4b457aabaf79fad385b3 (diff) |
Making recursive behaviors work. Some bugs existed before. Adding running
behavior which makes a signal bounce back and forth.
Diffstat (limited to 'operationscore')
-rw-r--r-- | operationscore/Behavior.py | 42 | ||||
-rw-r--r-- | operationscore/PixelEvent.py | 7 |
2 files changed, 36 insertions, 13 deletions
diff --git a/operationscore/Behavior.py b/operationscore/Behavior.py index 198c4b2..8db2d88 100644 --- a/operationscore/Behavior.py +++ b/operationscore/Behavior.py @@ -2,11 +2,11 @@ #inputs from all sensors it is bound to as well as any recursive inputs that it #spawned during the last time step. Inheriting classes MUST define #processResponse. processResponse should return a list of dictionaries which -#define the properties of the light response. They must give a location and -#color. They may define a function pointer which defines a custom mapping. -#[More on this later. Bug Russell if you want to do it]. -#recursiveResponse to queue a input on the next iteration with a dictionary -#argument. This will be passed in via recursive inputs. +#define the properties of the light response, (outputs, recursions). They must give a location and +#color. They may define a PixelEvent to more closely control the outgoing +#data, however, this is normally handled by routing the event to a behavior +#specifically designed to do this (like DecayBehavior). + import pdb from operationscore.SmootCoreObject import * #timeStep is called on every iteration of the LightInstallation @@ -19,23 +19,43 @@ class Behavior(SmootCoreObject): self.recursiveResponseQueue = [] self.sensorResponseQueue = [] self.outGoingQueue = [] + self.behaviorInit() + def behaviorInit(self): + pass def processResponse(self, sensorInputs, recursiveInputs): pass def addInput(self, sensorInput): self.sensorResponseQueue.append(sensorInput) #used for behavior chaining - def immediateProcessInput(self, sensorInputs): - return self.processResponse(sensorInputs, []) + def immediateProcessInput(self, sensorInputs, recursiveInputs=[]): + try: + (output,recursions) = self.processResponse(sensorInputs, \ + recursiveInputs) + if type(output) != type([]): + output = [output] + return (output, recursions) + except: + return (self.processResponse(sensorInputs, recursiveInputs),[]) def addInputs(self, sensorInputs): + print sensorInputs if type(sensorInputs) == type([]): [self.addInput(sensorInput) for sensorInput in sensorInputs] else: self.addInput(sensorInputs) - def recursiveReponse(self, args): - self.responseQueue.append(args) def timeStep(self): responses = self.processResponse(self.sensorResponseQueue, \ self.recursiveResponseQueue) + if type(responses) == type(tuple()) and len(responses) == 2: + (outputs, recursions) = responses + else: + outputs = responses + recursions = [] self.sensorResponseQueue = [] - self.recursiveResponseQueue = [] - return responses + self.recursiveResponseQueue = recursions + if type(outputs) != type([]): + outputs = [outputs] + try: + return outputs + except: + pdb.set_trace() + return outputs diff --git a/operationscore/PixelEvent.py b/operationscore/PixelEvent.py index 8567d93..66b6fdf 100644 --- a/operationscore/PixelEvent.py +++ b/operationscore/PixelEvent.py @@ -8,8 +8,11 @@ class PixelEvent(SmootCoreObject): self.initEvent() def initEvent(self): pass - def scale(c): - self['Color'] *= c + #Returns a new PixelEvent, but with a response scaled by c. + def scale(self,c): + newDict = dict(self.argDict) + newDict['Color'] = Util.multiplyColor(newDict['Color'], c) + return self.__class__(newDict) def state(self,timeDelay): pass |