aboutsummaryrefslogtreecommitdiff
path: root/operationscore
diff options
context:
space:
mode:
authorGravatar rcoh <rcoh@mit.edu>2010-12-22 14:27:33 -0500
committerGravatar rcoh <rcoh@mit.edu>2010-12-22 14:27:33 -0500
commitc581408f028d5b8ceadc53c68d7c1252fbe09e6d (patch)
tree8724862d05bde3bb3427cdff378cdb08da8babd2 /operationscore
parenta1d9b85320c9b07d62470d78ef0c5f9015baf813 (diff)
About halfway done with support for pixel regions. Modified the component registry a bit. Added
support for multiple pixel mappers (and along with that, default components). RCOH
Diffstat (limited to 'operationscore')
-rw-r--r--operationscore/Behavior.py21
-rw-r--r--operationscore/Input.py6
-rw-r--r--operationscore/PixelAssembler.py1
-rw-r--r--operationscore/PixelMapper.py1
-rw-r--r--operationscore/SmootCoreObject.py2
5 files changed, 18 insertions, 13 deletions
diff --git a/operationscore/Behavior.py b/operationscore/Behavior.py
index 3bdf1ec..d48c1d5 100644
--- a/operationscore/Behavior.py
+++ b/operationscore/Behavior.py
@@ -33,14 +33,26 @@ class Behavior(SmootCoreObject):
recursiveInputs)
if type(output) != type([]):
output = [output]
- return (output, recursions)
- except:
+ return self.addMapperToResponse((output, recursions)) #TODO: use a decorator for this?
+ except: #deal with behaviors that don't return a tuple.
+ responses = self.processResponse(sensorInputs, recursiveInputs)
return (self.processResponse(sensorInputs, recursiveInputs),[])
def addInputs(self, sensorInputs):
if type(sensorInputs) == type([]):
[self.addInput(sensorInput) for sensorInput in sensorInputs]
else:
self.addInput(sensorInputs)
+ #private
+ def addMapperToResponse(self, responses):
+ if self['Mapper'] != None:
+ if type(responses) == type(tuple):
+ (out, recurs) = responses
+ return (self.addMapperToResponse(out), self.addMapperToResponse(recurs))
+ if type(responses) == type([]):
+ for r in responses:
+ r['Mapper'] = self['Mapper']
+ return responses
+ return responses
def timeStep(self): #TODO: type checking. clean this up
responses = self.processResponse(self.sensorResponseQueue, \
self.recursiveResponseQueue)
@@ -54,8 +66,7 @@ class Behavior(SmootCoreObject):
if type(outputs) != type([]):
outputs = [outputs]
try:
- return outputs
+ return self.addMapperToResponse(outputs) #TODO: WTF is up with this?
except:
pass
- #pdb.set_trace()
- return outputs
+ return self.addMapperToResponse(outputs)
diff --git a/operationscore/Input.py b/operationscore/Input.py
index 2144678..62c4682 100644
--- a/operationscore/Input.py
+++ b/operationscore/Input.py
@@ -1,4 +1,4 @@
-import threading,time,Util
+import threading,time
from operationscore.SmootCoreObject import *
#Abstract class for inputs. Inheriting classes should call "respond" to raise
#their event. Inheriting classes MUST define sensingLoop. Called at the
@@ -22,14 +22,10 @@ class Input(SmootCoreObject):
self.daemon = True #This kills this thread when the main thread stops
def respond(self, eventDict):
#if eventDict != []:
- #pdb.set_trace()
self.parentScope.lock.acquire()
self.parentScope.processResponse(self.argDict, eventDict)
self.parentScope.lock.release()
time.sleep(.001)
- def newEvent(self, event): #Mostly just useful for grabbing events from the
- #computer running the sim (key presses, clicks etc.)
- self.eventQueue.append(event)
def parentAlive(self):
try:
parentAlive = self.parentScope.alive()
diff --git a/operationscore/PixelAssembler.py b/operationscore/PixelAssembler.py
index c8563fb..6878f8a 100644
--- a/operationscore/PixelAssembler.py
+++ b/operationscore/PixelAssembler.py
@@ -1,6 +1,5 @@
from operationscore.SmootCoreObject import *
import util.Geo as Geo
-import Util
import pdb
class PixelAssembler(SmootCoreObject):
def init(self):
diff --git a/operationscore/PixelMapper.py b/operationscore/PixelMapper.py
index bbbfcf4..e3f2515 100644
--- a/operationscore/PixelMapper.py
+++ b/operationscore/PixelMapper.py
@@ -1,5 +1,4 @@
from operationscore.SmootCoreObject import *
-import Util
import pdb
class PixelMapper(SmootCoreObject):
def init(self):
diff --git a/operationscore/SmootCoreObject.py b/operationscore/SmootCoreObject.py
index 10df299..9784aab 100644
--- a/operationscore/SmootCoreObject.py
+++ b/operationscore/SmootCoreObject.py
@@ -1,4 +1,3 @@
-import Util
import pdb
import threading
import thread
@@ -8,6 +7,7 @@ class SmootCoreObject(threading.Thread):
self.argDict = argDict
self.validateArgs(self.className()+'.params')
self.lock = thread.allocate_lock()
+ threading.Thread.__init__(self)
self.init() #call init of inheriting class
# self.__setitem__ = self.argDict.__setitem__
# self.__getitem__ = self.argDict.__getitem__