From a223608dda0751551c6e8688c0c0e1c9a1d4e69c Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Fri, 21 Jan 2011 00:57:14 -0500 Subject: Added a new config file to run the upstairs lights. Modified PixelMapper to track cache hits. Added 60-strip layouts and renderer configs. --- Profile.py | 2 +- behaviors/Accelerate.xml | 2 +- behaviors/RunningBehavior.py | 1 + config/6thFloor.xml | 208 ++++++++++++++++++++++++++++++++++++++++++ layouts/60StripLayout.xml | 182 ++++++++++++++++++++++++++++++++++++ operationscore/PixelMapper.py | 6 ++ pixelcore/Pixel.py | 8 +- pixelcore/Screen.py | 4 +- pixelevents/DecayEvent.py | 6 +- renderers/60StripSeq.xml | 130 ++++++++++++++++++++++++++ renderers/IndoorRenderer.py | 6 +- renderers/PygameRenderer.py | 2 +- util/Config.py | 14 ++- 13 files changed, 551 insertions(+), 20 deletions(-) create mode 100644 config/6thFloor.xml create mode 100644 layouts/60StripLayout.xml create mode 100644 renderers/60StripSeq.xml diff --git a/Profile.py b/Profile.py index 45ccc35..2f180c9 100644 --- a/Profile.py +++ b/Profile.py @@ -1,4 +1,4 @@ import cProfile from LightInstallation import main -command = """main(['', 'config/Outdoor.xml'])""" +command = """main(['', 'config/6thFloor.xml'])""" cProfile.runctx(command, globals(), locals(), filename="smootlight.profile") diff --git a/behaviors/Accelerate.xml b/behaviors/Accelerate.xml index c78195b..f9de077 100644 --- a/behaviors/Accelerate.xml +++ b/behaviors/Accelerate.xml @@ -3,6 +3,6 @@ Sensor StepSize - {val}*1.01 + {val}*1.1 diff --git a/behaviors/RunningBehavior.py b/behaviors/RunningBehavior.py index 92db69b..5eb33f7 100644 --- a/behaviors/RunningBehavior.py +++ b/behaviors/RunningBehavior.py @@ -15,6 +15,7 @@ class RunningBehavior(Behavior): outDict['StepSize'] = self['StepSize'] outDict['Location']= Geo.addLocations(outDict['Location'], (outDict['StepSize']*outDict['Dir'],0)) + if not Geo.pointWithinBoundingBox(outDict['Location'], \ compReg.getComponent('Screen').getSize()): outDict['Dir'] *= -1 diff --git a/config/6thFloor.xml b/config/6thFloor.xml new file mode 100644 index 0000000..9c5f77e --- /dev/null +++ b/config/6thFloor.xml @@ -0,0 +1,208 @@ + + + + + simplemap + + + + layouts/60StripLayout.xml + + + + pixelmappers.SimpleMapper + + simplemap + 20 + + + + pixelmappers.GaussianMapper + + gaussmap + 30 + 0.1 + 10 + 1 + + + + + + renderers/60StripSeq.xml + + + renderers/Pygame.xml + + + + + inputs.PygameInput + + pygame + 10 + + + + + inputs/MouseFollower.xml + + + inputs.RandomLocs + + randomLoc + + + + + + behaviors.EchoBehavior + + echo + 0 + False + + + + behaviors/RedShift.xml + + + behaviors/RandomColor.xml + + + behaviors/PixelDecay.xml + + + behaviors/PixelDecay.xml + + .01 + + + + behaviors.DebugBehavior + + debug + 0 + + pygame + + + + + behaviors.AllPixelsLeft + + pixelsleft + + + + behaviors.Square + + square + 20 + + + + behaviors/LoopAndDie.xml + + 50 + + + + behaviors.BehaviorChain + + runcolordecay + + pygame + + + colorchange + running + decay + + {'running':'acceleratedie'} + True + gaussmap + + + + behaviors.BehaviorChain + + randomwalk + + pygame + + + colorchange + mover + decay + + {'mover':'redwalk'} + True + gaussmap + + + + behaviors.ResponseMover + + mover + + + + behaviors.BehaviorChain + + redwalk + + randmovement + redshift + + + + + behaviors.RandomWalk + + randmovement + 2 + + + + behaviors/Accelerate.xml + + + behaviors.BehaviorChain + + acceleratedie + + accelerate + recursivedecay + + + + + behaviors.BehaviorChain + + mousechaser + + followmouse + tcp + + + echo + redshift + square + slowdecay + + True + + + + behaviors/RunningBehavior.xml + + + diff --git a/layouts/60StripLayout.xml b/layouts/60StripLayout.xml new file mode 100644 index 0000000..30f51c5 --- /dev/null +++ b/layouts/60StripLayout.xml @@ -0,0 +1,182 @@ + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + + layouts/50PixelStrip.xml + + diff --git a/operationscore/PixelMapper.py b/operationscore/PixelMapper.py index e3f2515..1f94fa5 100644 --- a/operationscore/PixelMapper.py +++ b/operationscore/PixelMapper.py @@ -3,8 +3,14 @@ import pdb class PixelMapper(SmootCoreObject): def init(self): self.mem = {} #Dictionary of all seen events + self.totalCalls = 0 + self.cachehits = 0 def mapEvent(self, eventLocation, screen): + self.totalCalls += 1 + if self.totalCalls % 100 == 0: + print self['Id'], self.cachehits / float(self.totalCalls) if eventLocation in self.mem: + self.cachehits += 1 return self.mem[eventLocation] else: self.mem[eventLocation] = self.mappingFunction(eventLocation, screen) diff --git a/pixelcore/Pixel.py b/pixelcore/Pixel.py index b9fc07f..7260e56 100644 --- a/pixelcore/Pixel.py +++ b/pixelcore/Pixel.py @@ -29,10 +29,10 @@ class Pixel: #arg #Add a pixelEvent to the list of active events - def processInput(self,pixelEvent,zindex, currentTime=None): #consider migrating arg to dict + def processInput(self,pixelEvent,zindex, scale=1,currentTime=None): #consider migrating arg to dict if currentTime == None: currentTime = timeops.time() - self.events[currentTime] = (zindex, pixelEvent) + self.events[currentTime] = (zindex,scale, pixelEvent) def clearAllEvents(self): self.events = {} @@ -49,10 +49,10 @@ class Pixel: resultingColor = (0,0,0) colors = [] for eventTime in self.events: #TODO: right color weighting code - (zindex,event) = self.events[eventTime] + (zindex,scale,event) = self.events[eventTime] eventResult = event.state(currentTime-eventTime) if eventResult != None: - colors.append(eventResult) + colors.append(color.multiplyColor(eventResult,scale)) else: deadEvents.append(eventTime) diff --git a/pixelcore/Screen.py b/pixelcore/Screen.py index 6666235..cfadee8 100644 --- a/pixelcore/Screen.py +++ b/pixelcore/Screen.py @@ -73,6 +73,7 @@ class Screen: maxY = max(y, maxY) self.size = (0,0, maxX, maxY) self.sizeValid = True + print self.size return (0, 0, maxX+100, maxY+100) #TODO: cleaner #private @@ -88,8 +89,7 @@ class Screen: #if type(mapper) != type(PixelMapper): # raise Exception('No default mapper specified.') pixelWeightList = mapper.mapEvent(responseInfo['Location'], self) - PixelEvent.addPixelEventIfMissing(responseInfo) currentTime = timeops.time() for (pixel, weight) in pixelWeightList: - pixel.processInput(responseInfo['PixelEvent'].scale(weight), 0, currentTime) #TODO: z-index + pixel.processInput(responseInfo['PixelEvent'], 0,weight, currentTime) #TODO: z-index diff --git a/pixelevents/DecayEvent.py b/pixelevents/DecayEvent.py index 3767729..f8d5ef0 100644 --- a/pixelevents/DecayEvent.py +++ b/pixelevents/DecayEvent.py @@ -4,12 +4,12 @@ from util.ColorOps import * import util.Geo as Geo class DecayEvent(PixelEvent): def initEvent(self): - self.coefficient = float(abs(self['Coefficient'])) - if self['DecayType'] == 'Exponential': + self.coefficient = float(abs(self.Coefficient)) + if self.DecayType == 'Exponential': self.decayType = 1 else: self.decayType = 2 - self.color = self['Color'] + self.color = self.Color #SUBVERTING DESIGN FOR THE SAKE OF EFFICIENCY -- RUSSELL COHEN (2011-01-03-23:18) def state(self,timeDelay): diff --git a/renderers/60StripSeq.xml b/renderers/60StripSeq.xml new file mode 100644 index 0000000..3f5255f --- /dev/null +++ b/renderers/60StripSeq.xml @@ -0,0 +1,130 @@ + + renderers.IndoorRenderer + + indoorRenderer + + 10.32.0.0 + {'strip0.1':1, 'strip0.2':2} + + + 10.32.0.1 + {'strip1.1':1, 'strip1.2':2} + + + 10.32.0.2 + {'strip2.1':1, 'strip2.2':2} + + + 10.32.0.3 + {'strip3.1':1, 'strip3.2':2} + + + 10.32.0.4 + {'strip4.1':1, 'strip4.2':2} + + + 10.32.0.5 + {'strip5.1':1, 'strip5.2':2} + + + 10.32.0.6 + {'strip6.1':1, 'strip6.2':2} + + + 10.32.0.7 + {'strip7.1':1, 'strip7.2':2} + + + 10.32.0.8 + {'strip8.1':1, 'strip8.2':2} + + + 10.32.0.9 + {'strip9.1':1, 'strip9.2':2} + + + 10.32.0.10 + {'strip10.1':1, 'strip10.2':2} + + + 10.32.0.11 + {'strip11.1':1, 'strip11.2':2} + + + 10.32.0.12 + {'strip12.1':1, 'strip12.2':2} + + + 10.32.0.13 + {'strip13.1':1, 'strip13.2':2} + + + 10.32.0.14 + {'strip14.1':1, 'strip14.2':2} + + + 10.32.0.15 + {'strip15.1':1, 'strip15.2':2} + + + 10.32.0.16 + {'strip16.1':1, 'strip16.2':2} + + + 10.32.0.17 + {'strip17.1':1, 'strip17.2':2} + + + 10.32.0.18 + {'strip18.1':1, 'strip18.2':2} + + + 10.32.0.19 + {'strip19.1':1, 'strip19.2':2} + + + 10.32.0.20 + {'strip20.1':1, 'strip20.2':2} + + + 10.32.0.21 + {'strip21.1':1, 'strip21.2':2} + + + 10.32.0.22 + {'strip22.1':1, 'strip22.2':2} + + + 10.32.0.23 + {'strip23.1':1, 'strip23.2':2} + + + 10.32.0.24 + {'strip24.1':1, 'strip24.2':2} + + + 10.32.0.25 + {'strip25.1':1, 'strip25.2':2} + + + 10.32.0.26 + {'strip26.1':1, 'strip26.2':2} + + + 10.32.0.27 + {'strip27.1':1, 'strip27.2':2} + + + 10.32.0.28 + {'strip28.1':1, 'strip28.2':2} + + + 10.32.0.29 + {'strip29.1':1, 'strip29.2':2} + + + 10.32.0.30 + {'strip30.1':1, 'strip30.2':2} + + + diff --git a/renderers/IndoorRenderer.py b/renderers/IndoorRenderer.py index 5f8546a..76ec172 100644 --- a/renderers/IndoorRenderer.py +++ b/renderers/IndoorRenderer.py @@ -21,7 +21,7 @@ class IndoorRenderer(Renderer): self.stripLocations[stripId] = (ip, \ stripsInPowerSupply[stripId]) def render(self, lightSystem, currentTime=timeops.time()): - try: + #try: for pixelStrip in lightSystem.pixelStrips: stripId = pixelStrip.argDict['Id'] (ip, port) = self.stripLocations[stripId] @@ -30,6 +30,6 @@ class IndoorRenderer(Renderer): self.sockets[ip] = network.getConnectedSocket(ip,sock_port) packet = composer.composePixelStripPacket(pixelStrip, port, currentTime) self.sockets[ip].send(packet, 0x00) - except Exception as inst: - print inst + #except Exception as inst: + # print inst diff --git a/renderers/PygameRenderer.py b/renderers/PygameRenderer.py index 24b2d08..9582a03 100644 --- a/renderers/PygameRenderer.py +++ b/renderers/PygameRenderer.py @@ -6,7 +6,7 @@ import pdb class PygameRenderer(Renderer): def initRenderer(self): pygame.init() - self.screen = pygame.display.set_mode((1300,50)) + self.screen = pygame.display.set_mode((1300,500)) self.background = pygame.Surface(self.screen.get_size()) self.background = self.background.convert() self.background.fill(Color('Black')) diff --git a/util/Config.py b/util/Config.py index 1e20cde..c2d8806 100644 --- a/util/Config.py +++ b/util/Config.py @@ -99,12 +99,19 @@ def fileToDict(fileName): def pullArgsFromItem(parentNode): attribArgs = {} for arg in parentNode.attrib: #automatically pull attributes into the argdict - attribArgs[arg] = parentNode.attrib[arg] + attribArgs[arg] = attemptEval(parentNode.attrib[arg]) argNode = parentNode.find('Args') args = generateArgDict(argNode) for key in attribArgs: args[key] = attribArgs[key] return args + +def attemptEval(val): + try: + val = eval(val) + except (NameError, SyntaxError): + val = str(val) + return val def generateArgDict(parentNode, recurse=False): args = {} for arg in parentNode.getchildren(): @@ -113,10 +120,7 @@ def generateArgDict(parentNode, recurse=False): value = generateArgDict(arg, True) else: #convert into python if possible, otherwise don't - try: - value = eval(arg.text) - except (NameError,SyntaxError): - value = str(arg.text) + value = attemptEval(arg.text) if key in args: #build of lists of like-elements if type(args[key]) != type([]): args[key] = [args[key]] -- cgit v1.2.3