From 6e0e6869a5ee1e4963071a18f24aa4dfdd442689 Mon Sep 17 00:00:00 2001 From: rcoh Date: Sun, 13 Feb 2011 16:03:39 -0500 Subject: Added a circle behavior to make circles. Added ContinuousCenterInput to do what it says. Modified SimpleMapper a bit. --- behaviors/Circle.py | 29 +++++++++++++++++++++++++++++ behaviors/ModifyParam.py | 2 ++ 2 files changed, 31 insertions(+) create mode 100644 behaviors/Circle.py (limited to 'behaviors') diff --git a/behaviors/Circle.py b/behaviors/Circle.py new file mode 100644 index 0000000..24d71f1 --- /dev/null +++ b/behaviors/Circle.py @@ -0,0 +1,29 @@ +from operationscore.Behavior import * +class Circle(Behavior): + def processResponse(self, sensors, recurs): + ret = [] + for data in sensors: + #import pdb; pdb.set_trace() + if 'CenterLoc' in data: + xLoc = data['CenterLoc'][0] + yLoc = data['CenterLoc'][1] + else: + data['CenterLoc'] = tuple(data['Location']) + xLoc = data['Location'][0] + yLoc = data['Location'][1] + if not self['Id']+'Radius' in data: + data[self['Id']+'Radius'] = self['Radius'] + rad = data[self['Id']+'Radius'] + cond = '>=' if self['Outside'] else '<=' + circleStr = 'math.sqrt(({x}-'+str(xLoc)+')**2+(({y}-'+str(yLoc)+')**2))'+cond+str(rad) + if self['Combine']: + data['Location'] += ',' + circleStr + else: + data['Location'] = circleStr + ret.append(data) + return (ret, []) + def setLastOutput(self, output): + coutput = Behavior.deepCopyPacket(output) + for data in coutput: + data['Location'] = data['CenterLoc'] + return coutput diff --git a/behaviors/ModifyParam.py b/behaviors/ModifyParam.py index 0ef3a60..ebcb98f 100644 --- a/behaviors/ModifyParam.py +++ b/behaviors/ModifyParam.py @@ -30,6 +30,8 @@ class ModifyParam(Behavior): #TODO: move elsewhere paramOp = paramOp.replace('{y}', "behaviorInput['Location'][1]") paramOp = paramOp.replace('{x}', "behaviorInput['Location'][0]") + if eval(paramOp) == None: + import pdb; pdb.set_trace() behaviorInput[paramName] = eval(paramOp) if paramType == 'Sensor': #return accordingly return (searchSet, recursiveInputs) -- cgit v1.2.3 From 9f61ad1981febe1be8631c0ee24d8febd83db714 Mon Sep 17 00:00:00 2001 From: rcoh Date: Sun, 13 Feb 2011 18:14:01 -0500 Subject: Added TimeSwitch to switch between behaviors at set time intervals --- behaviors/Circle.py | 2 +- behaviors/TimeSwitch.py | 24 ++++++++++++++++++++++++ config/C5Sign.xml | 32 ++++++++++++++++++-------------- util/Config.py | 8 ++++---- 4 files changed, 47 insertions(+), 19 deletions(-) create mode 100644 behaviors/TimeSwitch.py (limited to 'behaviors') diff --git a/behaviors/Circle.py b/behaviors/Circle.py index 24d71f1..f3e103b 100644 --- a/behaviors/Circle.py +++ b/behaviors/Circle.py @@ -15,7 +15,7 @@ class Circle(Behavior): data[self['Id']+'Radius'] = self['Radius'] rad = data[self['Id']+'Radius'] cond = '>=' if self['Outside'] else '<=' - circleStr = 'math.sqrt(({x}-'+str(xLoc)+')**2+(({y}-'+str(yLoc)+')**2))'+cond+str(rad) + circleStr = 'math.sqrt(({x}-'+str(xLoc)+')**2+(({y}-'+str(yLoc)+')**2)*2)'+cond+str(rad) if self['Combine']: data['Location'] += ',' + circleStr else: diff --git a/behaviors/TimeSwitch.py b/behaviors/TimeSwitch.py new file mode 100644 index 0000000..2cedfcf --- /dev/null +++ b/behaviors/TimeSwitch.py @@ -0,0 +1,24 @@ +from operationscore.Behavior import * +import util.TimeOps as clock +import util.ComponentRegistry as compReg +from logger import main_log +class TimeSwitch(Behavior): + """TimeSwitch is a behavior that alternates between different behaviors for a set amount of time + (specify time in seconds. Specify in a python-style dict: + {'behaviorId1':60, 'behaviorId2':120} + Would alternate between the 2 behaviors, spending 1 minute on b1 and 2 minutes on b2. + """ + def behaviorInit(self): + self.keyIndex = 0 + self.currentBehaviorId = self['Behaviors'].keys()[self.keyIndex] + self.behaviorStart = clock.time() + + def processResponse(self, sensors, recurs): + if self.behaviorStart + self['Behaviors'][self.currentBehaviorId]*1000 <= clock.time(): + self.keyIndex += 1 + self.keyIndex = self.keyIndex % len(self['Behaviors']) + self.currentBehaviorId = self['Behaviors'].keys()[self.keyIndex] + self.behaviorStart = clock.time() + main_log.info('Switching behaviors') + return compReg.getComponent(self.currentBehaviorId).processResponse(sensors, recurs) + diff --git a/config/C5Sign.xml b/config/C5Sign.xml index 02bd0a2..12cf6e6 100644 --- a/config/C5Sign.xml +++ b/config/C5Sign.xml @@ -164,6 +164,7 @@ xymove ybounce xbounce + longrecursivedecay @@ -176,6 +177,17 @@ 4*math.sin({x}/float(40)) + + behaviors.TimeSwitch + + main + + center + + {'runcolordecay':10,'expandingcircles':10} + True + + behaviors.DebugBehavior @@ -194,19 +206,16 @@ 20 - + + behaviors/LoopAndDie.xml + + behaviors/LoopAndDie.xml - - 80 - behaviors.BehaviorChain runcolordecay - - pygameclick - colorchange mover @@ -311,18 +320,13 @@ behaviors.BehaviorChain - expandingcirlces - - pygameclick - center - + expandingcircles colorchange mover - decay + singleframe {'mover':'circle_expand'} - True diff --git a/util/Config.py b/util/Config.py index 25018a8..962aa25 100644 --- a/util/Config.py +++ b/util/Config.py @@ -26,8 +26,8 @@ def loadConfigFile(fileName): #TODO: error handling etc. resolveDocumentInheritances(config.getroot()) return config except Exception as inst: - main_log.error('Error loading config file ' + fileName)#, inst) TODO: log exception too - main_log.error(str(inst)) + main_log.info('Error loading config file ' + fileName)#, inst) TODO: log exception too + main_log.info(str(inst)) return None def getElement(el): """Takes an Element or an ElementTree. If it is a tree, it returns its root. Otherwise, just returns @@ -89,7 +89,7 @@ def fileToDict(fileName): for line in f: fileText += line.rstrip('\n').lstrip('\t') + ' ' except IOError: - exception_log.exception('Failure reading ' + fileName) + main_log.info('Failure reading ' + fileName) return {} if fileText == '': return {} @@ -98,7 +98,7 @@ def fileToDict(fileName): main_log.info(fileName + ' read and parsed') return resultDict except: - exception_log.info(fileName + ' is not a well formed python dict. Parsing failed') + main_log.exception(fileName + ' is not a well formed python dict. Parsing failed') return eval(fileText) def pullArgsFromItem(parentNode): -- cgit v1.2.3 From 7a4f06d15b0fe9bd22996af6a1ca2c3ca5ca3e3f Mon Sep 17 00:00:00 2001 From: dxiao Date: Sun, 13 Feb 2011 19:00:44 -0500 Subject: Added a vertical bars animation to C5Sign-dxiao --- behaviors/VerticalBar.py | 30 +++ config/C5Sign-dxiao.xml | 396 ++++++++++++++++++++++++++++++++++++++ config/C5Sign.xml | 2 +- inputs/ContinuousLocationInput.py | 19 ++ pixelmappers/C5SignMapper.py | 8 +- 5 files changed, 452 insertions(+), 3 deletions(-) create mode 100644 behaviors/VerticalBar.py create mode 100644 config/C5Sign-dxiao.xml create mode 100644 inputs/ContinuousLocationInput.py (limited to 'behaviors') diff --git a/behaviors/VerticalBar.py b/behaviors/VerticalBar.py new file mode 100644 index 0000000..e1a67fe --- /dev/null +++ b/behaviors/VerticalBar.py @@ -0,0 +1,30 @@ +from operationscore.Behavior import * +class VerticalBar(Behavior): + + def processResponse(self, inputs, recurs): + + ret = [] + for inputset in inputs: + #import pdb; pdb.set_trace() + + if 'xLoc' not in inputset: + inputset['xLoc'] = inputset['Location'][0] + xLoc = inputset['xLoc'] + + condition = '{x} == ' + str(xLoc) + + if self['Combine']: + inputset['Location'] += ',' + condition + else: + 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-dxiao.xml b/config/C5Sign-dxiao.xml new file mode 100644 index 0000000..38eb40c --- /dev/null +++ b/config/C5Sign-dxiao.xml @@ -0,0 +1,396 @@ + + + + + simplemap + + + + layouts/C5SignLayout.xml + + + + + pixelmappers.C5SignMapper + + c5signmapper + 20 + + + + + pixelmappers.SimpleMapper + + simplemap + 20 + + + + pixelmappers.GaussianMapper + + gaussmap + 30 + 0.1 + 7 + 1 + + + + + + renderers/C5Renderer.xml + + + renderers/Pygame.xml + + + + + + inputs.OSCInput + + osc + 1234 + 10 + + + + + inputs.UDPInput + + udp + 3344 + 50 + + + + inputs.ContinuousCenterInput + + center + 1800 + + + + + inputs.ContinuousLocationInput + + centerleft + left + center + 1800 + + + + + + + + + + touchosc + + behaviors.TouchOSC + + + behaviors/RandomColor.xml + + + + + + behaviors.BehaviorChain + + OSCTouchChase + + osc + + + touchosc + decay + + gaussmap + False + + + + behaviors/PixelDecay.xml + + + behaviors/SingleFrame.xml + + + + behaviors/PixelDecay.xml + + .001 + + + + + behaviors.XYMove + + xymove + 1 + 1 + + + + behaviors.RestrictLocation + + xbounce + {val}*-1 + XStep + {x}<2 or {x}>48 + + + + behaviors.RestrictLocation + + ybounce + {val}*-1 + YStep + {y}<2 or {y}>24 + + + + behaviors.BehaviorChain + + movebounce + + xymove + ybounce + xbounce + + + + + behaviors.ModifyParam + + ysin + YStep + Sensor + 4*math.sin({x}/float(40)) + + + + behaviors.DebugBehavior + + debug + 0 + + pygamekey + udp + + + + + behaviors.AllPixels + + square + 20 + + + + behaviors/LoopAndDie.xml + + 160 + + + + behaviors.BehaviorChain + + runcolordecay + + pygameclick + + + colorchange + mover + + decay + + {'mover':'movebounce'} + False + gaussmap + + + + behaviors.ResponseMover + + mover + + + + behaviors.RandomWalk + + randmovement + 2 + + + + behaviors/Accelerate.xml + + + behaviors.EchoBehavior + + echo + 0 + False + + + + behaviors.ColorShift + + colorshift + + + + behaviors.BehaviorChain + + mousechaser + + + + echo + innercircle + outercircle + singleframe + + False + + + + behaviors.Circle + + innercircle + 0 + True + + + + behaviors.Circle + + outercircle + 3 + True + + + + behaviors.ModifyParam + + incrinner + {val}+.3 + innercircleRadius + + + + behaviors.ModifyParam + + incrouter + {val}+.3 + outercircleRadius + + + + behaviors.BehaviorChain + + circle_expand + + innercircle + outercircle + incrinner + incrouter + recursivedecay + + + + + behaviors.BehaviorChain + + expandingcirlces + + centerleft + + + colorchange + mover + decay + + {'mover':'circle_expand'} + False + + + + + behaviors.ModifyParam + + incrVertBarLoc + xLoc + {val}+1 + + + + behaviors.VerticalBar + + vertBar + + + + behaviors.BehaviorChain + + bar_move + + vertBar + incrVertBarLoc + recursivedecay + + + + + behaviors.BehaviorChain + + scanningbars + + centerleft + + + colorchange + mover + slowdecay + + {'mover':'bar_move'} + True + + + + + behaviors/RunningBehavior.xml + + + diff --git a/config/C5Sign.xml b/config/C5Sign.xml index 02bd0a2..45e42de 100644 --- a/config/C5Sign.xml +++ b/config/C5Sign.xml @@ -10,7 +10,7 @@ - pixelmappers.SimpleMapper + pixelmappers.C5SignMapper simplemap 20 diff --git a/inputs/ContinuousLocationInput.py b/inputs/ContinuousLocationInput.py new file mode 100644 index 0000000..f39bd9b --- /dev/null +++ b/inputs/ContinuousLocationInput.py @@ -0,0 +1,19 @@ +import util.TimeOps as clock +import util.ComponentRegistry as compReg +import util.Strings as Strings +from operationscore.Input import * +class ContinuousLocationInput(Input): + '''Continuously returns one of nine positions on the screen as specified by the xloc + and yloc arguments, which can take values 'min', 'max', and 'center'. ''' + def inputInit(self): + xvals = {} + yvals = {} + xvals['left'], yvals['bottom'], xvals['right'], yvals['top'] = compReg.getComponent('Screen').getSize() + (xvals['center'], yvals['center']) = ((xvals['left']+xvals['right']) / 2, (yvals['top']+yvals['bottom']) / 2) + + self.location = (xvals[self['xloc']], yvals[self['yloc']]) + + def sensingLoop(self): + print (self.location) + self.respond({Strings.LOCATION: self.location}) + diff --git a/pixelmappers/C5SignMapper.py b/pixelmappers/C5SignMapper.py index 79ebe1a..24631c4 100644 --- a/pixelmappers/C5SignMapper.py +++ b/pixelmappers/C5SignMapper.py @@ -1,6 +1,7 @@ from operationscore.PixelMapper import * import util.Geo as Geo import sys +import math class C5SignMapper(PixelMapper): """C5SignMapper is a modification to SimpleMapper which maps events to the nearest Pixel. In addtion, it also maps sign artifacts (letters, logo, etc) @@ -99,7 +100,9 @@ class C5SignMapper(PixelMapper): [eventLocation, signPart] = eventLocSplit signParts = signPart.split('.') pixelLocs = signPosition[signParts[0]][signParts[1]] - screen = [p for p in screen if (p.location in pixelLocs)] + screenPixels = [p for p in screen if (p.location in pixelLocs)] + else: + screenPixels = [p for p in screen] #{x}>5,{y} Date: Mon, 14 Feb 2011 01:51:43 -0500 Subject: 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. --- LightInstallation.py | 6 +- behaviors/TimeSwitch.py | 11 +-- behaviors/VerticalBar.py | 11 +-- config/C5Sign.xml | 155 ++++++++++++++++++-------------------- inputs/ContinuousCenterInput.py | 3 +- inputs/ContinuousLocationInput.py | 2 + renderers/PygameRenderer.py | 2 +- util/ComponentRegistry.py | 17 +++-- 8 files changed, 100 insertions(+), 107 deletions(-) (limited to 'behaviors') 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 @@ 1 + + pixelmappers.C5SignMapper + + c5signmapper + 20 + + renderers/C5Renderer.xml - + renderers/Pygame.xml - inputs.PygameInput + inputs.ContinuousLocationInput - pygameclick - 10 - True + centerleft + left + center + 1800 @@ -72,20 +80,9 @@ inputs.ContinuousCenterInput center - 1800 + 700 - - - inputs/MouseFollower.xml - @@ -94,15 +91,56 @@ behaviors.TouchOSC - - behaviors/RandomColor.xml + + behaviors/PixelDecay.xml + + .001 + + + + behaviors.ModifyParam + + incrVertBarLoc + xLoc + {val}+1 + + + + behaviors.VerticalBar - + vertBar + + behaviors.BehaviorChain + + bar_move + + vertBar + incrVertBarLoc + recursivedecay + + + + + behaviors.BehaviorChain + + scanningbars + + centerleft + + + colorchange + mover + slowdecay + + {'mover':'bar_move'} + False + + + + behaviors/RandomColor.xml + behaviors.BehaviorChain @@ -115,7 +153,7 @@ decay gaussmap - True + False @@ -124,12 +162,6 @@ behaviors/SingleFrame.xml - - behaviors/PixelDecay.xml - - .01 - - behaviors.XYMove @@ -168,24 +200,18 @@ - - behaviors.ModifyParam - - ysin - YStep - Sensor - 4*math.sin({x}/float(40)) - - behaviors.TimeSwitch main + centerleft center - {'runcolordecay':10,'expandingcircles':10} - False + {'scanningbars':10,'runcolordecay':10,'expandingcircles':10} + {'scanningbars':'centerleft', 'runcolordecay':'center',\ + 'expandingcircles':'center'} + True @@ -206,10 +232,10 @@ 20 - + behaviors/LoopAndDie.xml - + behaviors/LoopAndDie.xml @@ -233,45 +259,12 @@ mover - - behaviors.RandomWalk - - randmovement - 2 - - - - behaviors/Accelerate.xml - - - behaviors.EchoBehavior - - echo - 0 - False - - behaviors.ColorShift colorshift - - behaviors.BehaviorChain - - mousechaser - - - - echo - innercircle - outercircle - singleframe - - False - - behaviors.Circle @@ -292,7 +285,7 @@ behaviors.ModifyParam incrinner - {val}+.3 + {val}+.6 innercircleRadius @@ -300,7 +293,7 @@ behaviors.ModifyParam incrouter - {val}+.3 + {val}+.6 outercircleRadius @@ -324,13 +317,11 @@ colorchange mover - singleframe + decay + {'mover':'circle_expand'} - - behaviors/RunningBehavior.xml - 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) -- cgit v1.2.3 From 2df9e408a0ff74539862c4a4e562a878cc11a329 Mon Sep 17 00:00:00 2001 From: rcoh Date: Wed, 16 Feb 2011 18:20:36 -0500 Subject: Code cleanup. Made Oval behavior (circle with h/w). --- LightInstallation.py | 1 - behaviors/Circle.py | 2 +- behaviors/ModifyParam.py | 3 --- behaviors/Oval.py | 36 ++++++++++++++++++++++++++++++++++++ behaviors/VerticalBar.py | 1 - config/C5Sign.xml | 6 +++--- operationscore/PixelAssembler.py | 4 ++-- pixelmappers/SimpleMapper.py | 4 ++-- util/ComponentRegistry.py | 3 +-- 9 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 behaviors/Oval.py (limited to 'behaviors') diff --git a/LightInstallation.py b/LightInstallation.py index 91be752..19d6c54 100755 --- a/LightInstallation.py +++ b/LightInstallation.py @@ -181,7 +181,6 @@ 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/Circle.py b/behaviors/Circle.py index f3e103b..24d71f1 100644 --- a/behaviors/Circle.py +++ b/behaviors/Circle.py @@ -15,7 +15,7 @@ class Circle(Behavior): data[self['Id']+'Radius'] = self['Radius'] rad = data[self['Id']+'Radius'] cond = '>=' if self['Outside'] else '<=' - circleStr = 'math.sqrt(({x}-'+str(xLoc)+')**2+(({y}-'+str(yLoc)+')**2)*2)'+cond+str(rad) + circleStr = 'math.sqrt(({x}-'+str(xLoc)+')**2+(({y}-'+str(yLoc)+')**2))'+cond+str(rad) if self['Combine']: data['Location'] += ',' + circleStr else: diff --git a/behaviors/ModifyParam.py b/behaviors/ModifyParam.py index ebcb98f..6f81383 100644 --- a/behaviors/ModifyParam.py +++ b/behaviors/ModifyParam.py @@ -1,6 +1,5 @@ from operationscore.Behavior import * import math -import pdb #Class to perform a given operation on some element of an argDict. Designed to be used a recursive hook, but can serve sensor-based functions as well. Specify ParamType (Sensor or Recurse), ParamName, and ParamOp, (a valid python statement with the old value represented as {val}) class ModifyParam(Behavior): """ModifyParam is a powerful class to perform an action on a specified key in the Argument @@ -30,8 +29,6 @@ class ModifyParam(Behavior): #TODO: move elsewhere paramOp = paramOp.replace('{y}', "behaviorInput['Location'][1]") paramOp = paramOp.replace('{x}', "behaviorInput['Location'][0]") - if eval(paramOp) == None: - import pdb; pdb.set_trace() behaviorInput[paramName] = eval(paramOp) if paramType == 'Sensor': #return accordingly return (searchSet, recursiveInputs) diff --git a/behaviors/Oval.py b/behaviors/Oval.py new file mode 100644 index 0000000..b7486f5 --- /dev/null +++ b/behaviors/Oval.py @@ -0,0 +1,36 @@ +from operationscore.Behavior import * +class Oval(Behavior): + def processResponse(self, sensors, recurs): + ret = [] + for data in sensors: + #import pdb; pdb.set_trace() + height = width = 1 + if 'Height' in self: + height = 1/float(self['Height']) + if 'Width' in self: + width = 1/float(self['Width']) + if 'CenterLoc' in data: + xLoc = data['CenterLoc'][0] + yLoc = data['CenterLoc'][1] + else: + data['CenterLoc'] = tuple(data['Location']) + xLoc = data['Location'][0] + yLoc = data['Location'][1] + if not self['Id']+'Radius' in data: + data[self['Id']+'Radius'] = self['Radius'] + rad = data[self['Id']+'Radius'] + cond = '>=' if self['Outside'] else '<=' + circleStr = \ + 'math.sqrt((({x}-%(xLoc)d))**2*%(width)d+(({y}-%(yLoc)d)**2)*%(height)d)%(cond)s%(rad)d' % \ + locals() + if self['Combine']: + data['Location'] += ',' + circleStr + else: + data['Location'] = circleStr + ret.append(data) + return (ret, []) + def setLastOutput(self, output): + coutput = Behavior.deepCopyPacket(output) + for data in coutput: + data['Location'] = data['CenterLoc'] + return coutput diff --git a/behaviors/VerticalBar.py b/behaviors/VerticalBar.py index 66c8e56..85960cb 100644 --- a/behaviors/VerticalBar.py +++ b/behaviors/VerticalBar.py @@ -5,7 +5,6 @@ class VerticalBar(Behavior): 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] diff --git a/config/C5Sign.xml b/config/C5Sign.xml index a05cb1e..024f0d8 100644 --- a/config/C5Sign.xml +++ b/config/C5Sign.xml @@ -208,7 +208,7 @@ centerleft center - {'scanningbars':10,'runcolordecay':10,'expandingcircles':10} + {'scanningbars':0,'runcolordecay':10,'expandingcircles':10} {'scanningbars':'centerleft', 'runcolordecay':'center',\ 'expandingcircles':'center'} True @@ -266,7 +266,7 @@ - behaviors.Circle + behaviors.Oval innercircle 0 @@ -274,7 +274,7 @@ - behaviors.Circle + behaviors.Oval outercircle 3 diff --git a/operationscore/PixelAssembler.py b/operationscore/PixelAssembler.py index 582b59d..8ae27c9 100644 --- a/operationscore/PixelAssembler.py +++ b/operationscore/PixelAssembler.py @@ -19,10 +19,10 @@ class PixelAssembler(SmootCoreObject): defined or improperly defined.') if Geo.dist(newLocation, locations[-1]) > \ self['pixelToPixelSpacing']: - import pdb; pdb.set_trace() raise Exception('Illegal pixel location. Distance \ between adjacent pixels must be less than \ - pixelToPixelSpacing.') + pixelToPixelSpacing. Illegal distance is between '+str(pixelIndex) + ' and'\ + + str(pixelIndex+1)) locations.append(newLocation) if self['Reverse']: locations.reverse() diff --git a/pixelmappers/SimpleMapper.py b/pixelmappers/SimpleMapper.py index 6603c98..1decdd1 100644 --- a/pixelmappers/SimpleMapper.py +++ b/pixelmappers/SimpleMapper.py @@ -44,7 +44,7 @@ class SimpleMapper(PixelMapper): if pixelValid: ret.append((pixel, 1)) except Exception as exp: - import pdb; pdb.set_trace() - raise Exception('Bad event condition') + exp.message += 'Bad Event Condition' + raise exp return ret diff --git a/util/ComponentRegistry.py b/util/ComponentRegistry.py index 3036138..1db5135 100644 --- a/util/ComponentRegistry.py +++ b/util/ComponentRegistry.py @@ -1,4 +1,3 @@ -import pdb import hashlib from logger import main_log import thread @@ -41,7 +40,7 @@ def registerComponent(component, cid=None): component['Id'] = cid main_log.debug(cid + 'automatically assigned') if cid in Registry: - import pdb; pdb.set_trace() + main_log.warn(cid + 'overwritten.') Registry[cid] = component return cid -- cgit v1.2.3