aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar rcoh <rcoh@mit.edu>2011-02-14 01:51:43 -0500
committerGravatar rcoh <rcoh@mit.edu>2011-02-14 01:51:43 -0500
commit83242972c09032eb89dd547f3ff3c4dcc2693555 (patch)
tree62fdb611afbb37ff90f0356cac5828f48ec50f60
parent9c76b22071259fe8195eaf5bd846219fc2cade4d (diff)
Fixed some threading bugs. Modified LightInstallation.py so that Behaviors are *Only* run if they
are marked to be rendered. Fixed a threading issue tied to the component registry.
-rwxr-xr-xLightInstallation.py6
-rw-r--r--behaviors/TimeSwitch.py11
-rw-r--r--behaviors/VerticalBar.py11
-rw-r--r--config/C5Sign.xml155
-rw-r--r--inputs/ContinuousCenterInput.py3
-rw-r--r--inputs/ContinuousLocationInput.py2
-rw-r--r--renderers/PygameRenderer.py2
-rw-r--r--util/ComponentRegistry.py17
8 files changed, 100 insertions, 107 deletions
diff --git a/LightInstallation.py b/LightInstallation.py
index cca1588..91be752 100755
--- a/LightInstallation.py
+++ b/LightInstallation.py
@@ -103,9 +103,6 @@ class LightInstallation(object):
for component in components:
cid = compReg.registerComponent(component)
main_log.info(cid + ' registered')
- compReg.registerComponent(component)
- main_log.info(cid + ' registered')
-
def initializeComponent(self, config):
components = []
if config != None:
@@ -164,8 +161,8 @@ class LightInstallation(object):
responses = {}
responses['Screen'] = [] #responses to the screen
for behavior in self.behaviors:
- responses[behavior['Id']] = behavior.timeStep()
if behavior['RenderToScreen'] == True:
+ responses[behavior['Id']] = behavior.timeStep()
responses['Screen'] += responses[behavior['Id']]
return responses['Screen']
@@ -184,6 +181,7 @@ class LightInstallation(object):
def processResponse(self,inputDict, responseDict):
inputId = inputDict['Id']
+ #coming from.
boundBehaviorIds = self.inputBehaviorRegistry[inputId]
try:
[compReg.getComponent(b).addInput(responseDict) for b in boundBehaviorIds]
diff --git a/behaviors/TimeSwitch.py b/behaviors/TimeSwitch.py
index 2cedfcf..cfbfe4a 100644
--- a/behaviors/TimeSwitch.py
+++ b/behaviors/TimeSwitch.py
@@ -10,15 +10,16 @@ class TimeSwitch(Behavior):
"""
def behaviorInit(self):
self.keyIndex = 0
- self.currentBehaviorId = self['Behaviors'].keys()[self.keyIndex]
+ self.currentBehaviorId = self['TimeMap'].keys()[self.keyIndex]
self.behaviorStart = clock.time()
def processResponse(self, sensors, recurs):
- if self.behaviorStart + self['Behaviors'][self.currentBehaviorId]*1000 <= clock.time():
+ if self.behaviorStart + self['TimeMap'][self.currentBehaviorId]*1000 <= clock.time():
self.keyIndex += 1
- self.keyIndex = self.keyIndex % len(self['Behaviors'])
- self.currentBehaviorId = self['Behaviors'].keys()[self.keyIndex]
+ self.keyIndex = self.keyIndex % len(self['TimeMap'])
+ self.currentBehaviorId = self['TimeMap'].keys()[self.keyIndex]
self.behaviorStart = clock.time()
main_log.info('Switching behaviors')
- return compReg.getComponent(self.currentBehaviorId).processResponse(sensors, recurs)
+ sensors = [s for s in sensors if s['InputId'] == self['InputMap'][self.currentBehaviorId]]
+ return compReg.getComponent(self.currentBehaviorId).immediateProcessInput(sensors, recurs)
diff --git a/behaviors/VerticalBar.py b/behaviors/VerticalBar.py
index e1a67fe..66c8e56 100644
--- a/behaviors/VerticalBar.py
+++ b/behaviors/VerticalBar.py
@@ -2,11 +2,11 @@ from operationscore.Behavior import *
class VerticalBar(Behavior):
def processResponse(self, inputs, recurs):
-
ret = []
+ inputs = list(inputs)
for inputset in inputs:
#import pdb; pdb.set_trace()
-
+ inputset = dict(inputset)
if 'xLoc' not in inputset:
inputset['xLoc'] = inputset['Location'][0]
xLoc = inputset['xLoc']
@@ -19,12 +19,5 @@ class VerticalBar(Behavior):
inputset['Location'] = condition
ret.append(inputset)
-
return (ret, [])
- def setLastOutput(self, output):
-
- coutput = Behavior.deepCopyPacket(output)
- for data in coutput:
- data['Location'] = data['xLoc']
- return coutput
diff --git a/config/C5Sign.xml b/config/C5Sign.xml
index d4abdc1..a05cb1e 100644
--- a/config/C5Sign.xml
+++ b/config/C5Sign.xml
@@ -26,22 +26,30 @@
<Height>1</Height>
</Args>
</PixelMapper>
+ <PixelMapper>
+ <Class>pixelmappers.C5SignMapper</Class>
+ <Args>
+ <Id>c5signmapper</Id>
+ <CutoffDist>20</CutoffDist>
+ </Args>
+ </PixelMapper>
</PixelMapperConfiguration>
<RendererConfiguration>
<Renderer>
<InheritsFrom>renderers/C5Renderer.xml</InheritsFrom>
</Renderer>
- <Renderer>
+ <Renderer Scale="5">
<InheritsFrom>renderers/Pygame.xml</InheritsFrom>
</Renderer>
</RendererConfiguration>
<InputConfiguration>
<InputElement>
- <Class>inputs.PygameInput</Class>
+ <Class>inputs.ContinuousLocationInput</Class>
<Args>
- <Id>pygameclick</Id>
- <RefreshInterval>10</RefreshInterval>
- <Clicks>True</Clicks>
+ <Id>centerleft</Id>
+ <xloc>left</xloc>
+ <yloc>center</yloc>
+ <RefreshInterval>1800</RefreshInterval>
</Args>
</InputElement>
<InputElement>
@@ -72,20 +80,9 @@
<Class>inputs.ContinuousCenterInput</Class>
<Args>
<Id>center</Id>
- <RefreshInterval>1800</RefreshInterval>
+ <RefreshInterval>700</RefreshInterval>
</Args>
</InputElement>
- <!--<InputElement>
- <Class>inputs.TCPInput</Class>
- <Args>
- <Id>tcp</Id>
- <Port>20120</Port>
- <RefreshInterval>10</RefreshInterval>
- </Args>
- </InputElement>-->
- <InputElement Id="followmouse" RefreshInterval="10">
- <InheritsFrom>inputs/MouseFollower.xml</InheritsFrom>
- </InputElement>
</InputConfiguration>
<BehaviorConfiguration>
<Behavior>
@@ -94,18 +91,59 @@
</Args>
<Class>behaviors.TouchOSC</Class>
</Behavior>
- <Behavior Id="colorchange">
- <InheritsFrom>behaviors/RandomColor.xml</InheritsFrom>
+ <Behavior Id="slowdecay">
+ <InheritsFrom>behaviors/PixelDecay.xml</InheritsFrom>
+ <Args>
+ <Coefficient>.001</Coefficient>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.ModifyParam</Class>
+ <Args>
+ <Id>incrVertBarLoc</Id>
+ <ParamName>xLoc</ParamName>
+ <ParamOp>{val}+1</ParamOp>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.VerticalBar</Class>
<Args>
- <!--ColorList>
- <Val>(255,0,0)</Val>
- <Val>(0,0,255)</Val>
- </ColorList-->
+ <Id>vertBar</Id>
</Args>
</Behavior>
<Behavior>
<Class>behaviors.BehaviorChain</Class>
<Args>
+ <Id>bar_move</Id>
+ <ChainedBehaviors>
+ <Id>vertBar</Id>
+ <Id>incrVertBarLoc</Id>
+ <Id>recursivedecay</Id>
+ </ChainedBehaviors>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.BehaviorChain</Class>
+ <Args>
+ <Id>scanningbars</Id>
+ <Inputs>
+ <Id>centerleft</Id>
+ </Inputs>
+ <ChainedBehaviors>
+ <Id>colorchange</Id>
+ <Id>mover</Id>
+ <Id>slowdecay</Id>
+ </ChainedBehaviors>
+ <RecursiveHooks>{'mover':'bar_move'}</RecursiveHooks>
+ <RenderToScreen>False</RenderToScreen>
+ </Args>
+ </Behavior>
+ <Behavior Id="colorchange">
+ <InheritsFrom>behaviors/RandomColor.xml</InheritsFrom>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.BehaviorChain</Class>
+ <Args>
<Id>OSCTouchChase</Id>
<Inputs>
<Id>osc</Id>
@@ -115,7 +153,7 @@
<Id>decay</Id>
</ChainedBehaviors>
<Mapper>gaussmap</Mapper>
- <RenderToScreen>True</RenderToScreen>
+ <RenderToScreen>False</RenderToScreen>
</Args>
</Behavior>
<Behavior Id="decay">
@@ -124,12 +162,6 @@
<Behavior Id="singleframe">
<InheritsFrom>behaviors/SingleFrame.xml</InheritsFrom>
</Behavior>
- <Behavior Id="slowdecay">
- <InheritsFrom>behaviors/PixelDecay.xml</InheritsFrom>
- <Args>
- <Coefficient>.01</Coefficient>
- </Args>
- </Behavior>
<Behavior>
<Class>behaviors.XYMove</Class>
<Args>
@@ -169,23 +201,17 @@
</Args>
</Behavior>
<Behavior>
- <Class>behaviors.ModifyParam</Class>
- <Args>
- <Id>ysin</Id>
- <ParamName>YStep</ParamName>
- <ParamType>Sensor</ParamType>
- <ParamOp>4*math.sin({x}/float(40))</ParamOp>
- </Args>
- </Behavior>
- <Behavior>
<Class>behaviors.TimeSwitch</Class>
<Args>
<Id>main</Id>
<Inputs>
+ <Id>centerleft</Id>
<Id>center</Id>
</Inputs>
- <Behaviors>{'runcolordecay':10,'expandingcircles':10}</Behaviors>
- <RenderToScreen>False</RenderToScreen>
+ <TimeMap>{'scanningbars':10,'runcolordecay':10,'expandingcircles':10}</TimeMap>
+ <InputMap>{'scanningbars':'centerleft', 'runcolordecay':'center',\
+ 'expandingcircles':'center'}</InputMap>
+ <RenderToScreen>True</RenderToScreen>
</Args>
</Behavior>
<Behavior>
@@ -206,10 +232,10 @@
<Width>20</Width>
</Args>
</Behavior>
- <Behavior Id="recursivedecay" InitialResponseCount="80">
+ <Behavior Id="recursivedecay" InitialResponseCount="50">
<InheritsFrom>behaviors/LoopAndDie.xml</InheritsFrom>
</Behavior>
- <Behavior Id="longrecursivedecay" InitialResponseCount="400">
+ <Behavior Id="longrecursivedecay" InitialResponseCount="80">
<InheritsFrom>behaviors/LoopAndDie.xml</InheritsFrom>
</Behavior>
<Behavior>
@@ -234,45 +260,12 @@
</Args>
</Behavior>
<Behavior>
- <Class>behaviors.RandomWalk</Class>
- <Args>
- <Id>randmovement</Id>
- <StepSize>2</StepSize>
- </Args>
- </Behavior>
- <Behavior Id="accelerate">
- <InheritsFrom>behaviors/Accelerate.xml</InheritsFrom>
- </Behavior>
- <Behavior>
- <Class>behaviors.EchoBehavior</Class>
- <Args>
- <Id>echo</Id>
- <z-index>0</z-index>
- <RenderToScreen>False</RenderToScreen>
- </Args>
- </Behavior>
- <Behavior>
<Class>behaviors.ColorShift</Class>
<Args>
<Id>colorshift</Id>
</Args>
</Behavior>
<Behavior>
- <Class>behaviors.BehaviorChain</Class>
- <Args>
- <Id>mousechaser</Id>
- <Inputs>
- </Inputs>
- <ChainedBehaviors>
- <Id>echo</Id>
- <Id>innercircle</Id>
- <Id>outercircle</Id>
- <Id>singleframe</Id>
- </ChainedBehaviors>
- <RenderToScreen>False</RenderToScreen>
- </Args>
- </Behavior>
- <Behavior>
<Class>behaviors.Circle</Class>
<Args>
<Id>innercircle</Id>
@@ -292,7 +285,7 @@
<Class>behaviors.ModifyParam</Class>
<Args>
<Id>incrinner</Id>
- <ParamOp>{val}+.3</ParamOp>
+ <ParamOp>{val}+.6</ParamOp>
<ParamName>innercircleRadius</ParamName>
</Args>
</Behavior>
@@ -300,7 +293,7 @@
<Class>behaviors.ModifyParam</Class>
<Args>
<Id>incrouter</Id>
- <ParamOp>{val}+.3</ParamOp>
+ <ParamOp>{val}+.6</ParamOp>
<ParamName>outercircleRadius</ParamName>
</Args>
</Behavior>
@@ -324,13 +317,11 @@
<ChainedBehaviors>
<Id>colorchange</Id>
<Id>mover</Id>
- <Id>singleframe</Id>
+ <Id>decay</Id>
+ <!--Id>singleframe</Id-->
</ChainedBehaviors>
<RecursiveHooks>{'mover':'circle_expand'}</RecursiveHooks>
</Args>
</Behavior>
- <Behavior Id="running">
- <InheritsFrom>behaviors/RunningBehavior.xml</InheritsFrom>
- </Behavior>
</BehaviorConfiguration>
</LightInstallation>
diff --git a/inputs/ContinuousCenterInput.py b/inputs/ContinuousCenterInput.py
index a7635b2..88534f0 100644
--- a/inputs/ContinuousCenterInput.py
+++ b/inputs/ContinuousCenterInput.py
@@ -4,9 +4,10 @@ import util.Strings as Strings
from operationscore.Input import *
class ContinuousCenterInput(Input):
def inputInit(self):
+ compReg.getLock().acquire()
minX,minY,maxX,maxY = compReg.getComponent('Screen').getSize()
+ compReg.getLock().release()
self.center = ((minX+maxX) / 2, (minY+maxY) / 2)
- print self.center
def sensingLoop(self):
self.respond({Strings.LOCATION: self.center})
diff --git a/inputs/ContinuousLocationInput.py b/inputs/ContinuousLocationInput.py
index 52a36ad..72ca8f0 100644
--- a/inputs/ContinuousLocationInput.py
+++ b/inputs/ContinuousLocationInput.py
@@ -8,7 +8,9 @@ class ContinuousLocationInput(Input):
def inputInit(self):
xvals = {}
yvals = {}
+ compReg.getLock().acquire()
xvals['left'], yvals['bottom'], xvals['right'], yvals['top'] = compReg.getComponent('Screen').getSize()
+ compReg.getLock().release()
(xvals['center'], yvals['center']) = ((xvals['left']+xvals['right']) / 2, (yvals['top']+yvals['bottom']) / 2)
self.location = (xvals[self['xloc']], yvals[self['yloc']])
diff --git a/renderers/PygameRenderer.py b/renderers/PygameRenderer.py
index 01e2615..8be272c 100644
--- a/renderers/PygameRenderer.py
+++ b/renderers/PygameRenderer.py
@@ -25,7 +25,7 @@ class PygameRenderer(Renderer):
for light in lightSystem:
scaledLoc = [l*scale for l in light.location]
pygame.draw.circle(self.background, light.state(currentTime), scaledLoc, \
- light.radius)
+ 5)
self.screen.blit(self.background, (0,0))
pygame.display.flip()
diff --git a/util/ComponentRegistry.py b/util/ComponentRegistry.py
index be913df..3036138 100644
--- a/util/ComponentRegistry.py
+++ b/util/ComponentRegistry.py
@@ -1,12 +1,18 @@
import pdb
import hashlib
from logger import main_log
+import thread
#TODO: make component registry a singleton
def initRegistry():
#TODO: don't overwrite existing registry
if not 'Registry' in globals():
globals()['Registry'] = {}
-
+ makelock()
+
+
+def makelock():
+ global utilLock
+ utilLock = thread.allocate_lock()
def clearRegistry():
initRegistry()
@@ -14,6 +20,9 @@ def removeComponent(cid):
global Registry
Registry.pop(cid)
+def getLock():
+ global utilLock
+ return utilLock
def getComponent(cid):
global Registry
return Registry[cid]
@@ -31,6 +40,8 @@ def registerComponent(component, cid=None):
cid = getNewId()
component['Id'] = cid
main_log.debug(cid + 'automatically assigned')
+ if cid in Registry:
+ import pdb; pdb.set_trace()
Registry[cid] = component
return cid
@@ -42,10 +53,6 @@ def removeComponent(cid):
global Registry
Registry.pop(cid)
-def getComponent(cid):
- global Registry
- return Registry[cid]
-
def getNewId():
global Registry
trialKey = len(Registry)