From ef1abfa913498e02a4ece3be4be45d2f03e47d05 Mon Sep 17 00:00:00 2001 From: rcoh Date: Fri, 28 Jan 2011 15:19:21 -0500 Subject: Lots of stuff INCOMPLETE --- behaviors/ExpandingColorZones.py | 7 ++++--- behaviors/MITDoors.py | 1 + behaviors/RiseFall.py | 6 ++++++ behaviors/SmootWind.py | 24 +++++++++++++++++------- 4 files changed, 28 insertions(+), 10 deletions(-) (limited to 'behaviors') diff --git a/behaviors/ExpandingColorZones.py b/behaviors/ExpandingColorZones.py index 345851e..75be761 100644 --- a/behaviors/ExpandingColorZones.py +++ b/behaviors/ExpandingColorZones.py @@ -2,13 +2,14 @@ from operationscore.Behavior import * from logger import main_log class ExpandingColorZones(Behavior): def behaviorInit(self): - self.mapping = {'r':[(132,0),(255,0,0)], 'g':[(400,0), (0,255,0)], - 'b':[(668,0), + self.mapping = {'s001':[(132,0),(255,0,0)], 's002':[(400,0), (0,255,0)], + 's003':[(668,0), (0,0,255)]} - self.mappingkey = 'KeyChar' + self.mappingkey = 'data' def processResponse(self, sensorInputs, recursiveInputs): ret = [] for data in sensorInputs: + print data data = dict(data) if self.mappingkey in data: try: diff --git a/behaviors/MITDoors.py b/behaviors/MITDoors.py index 03bef6d..cee47f0 100644 --- a/behaviors/MITDoors.py +++ b/behaviors/MITDoors.py @@ -23,5 +23,6 @@ class MITDoors(Behavior): data['Left'], data['Right'] = bounds data['Bottom'] = self['Bottom'] data['Location'] = (sum(bounds) / 2., self['Bottom']) + data['Oscillate'] = False ret.append(data) return (ret, []) diff --git a/behaviors/RiseFall.py b/behaviors/RiseFall.py index 109cd10..eea2283 100644 --- a/behaviors/RiseFall.py +++ b/behaviors/RiseFall.py @@ -29,7 +29,13 @@ class RiseFall(Behavior): data['Right'] = data['Location'][0]+data['Width']/2. currentTime = timeOps.time() deltaTime = currentTime-data['StartTime'] + #if data['Oscillate'] == True: data['Height'] = data['MaxHeight']*math.sin(deltaTime/data['Period']*(math.pi*2)) + #else: + # data['Height'] = data['MaxHeight'] + #if (currentTime-data['StartTime']) > data['Period']: + # del data['StartTime'] + data['Location'] = "{x}>"+str(data['Left']) + ", " +\ "{x}<"+str(data['Right'])+", {y}<" + str(data['Bottom']) + ",\ {y}>"+str(data['Bottom']-data['Height']) diff --git a/behaviors/SmootWind.py b/behaviors/SmootWind.py index 347e2fc..804183c 100755 --- a/behaviors/SmootWind.py +++ b/behaviors/SmootWind.py @@ -22,12 +22,22 @@ class SmootWind(Behavior): for sensory in sensorInputs: print sensory # input[0] is windspeed, [1] is dir - windSpeed = sensory[0] - windDir = sensory[1] + if 0 in sensory and 1 in sensory: + windSpeed = sensory[0] + windDir = sensory[1] + #print self.mapper.argDict + self.mapper.argDict['Width'] = self.mapper.argDict['Width']+float(windSpeed)*2+20 + self.xFor.argDict['ParamOp'] = self.xFor.argDict['ParamOp']+float(windSpeed)*3+10*random.random(); + #print 'Width: ' + str(self.mapper.argDict['Width']) + #print 'xFor: ' + str(self.xFor.argDict['ParamOp']) + + elif 'Key' in sensory: + if sensory['Key'] == 273: + self.mapper.argDict['Width'] = self.mapper.argDict['Width']+10; + self.xFor.argDict['ParamOp'] = self.xFor.argDict['ParamOp']+5; + + elif sensory['Key'] == 274: + self.mapper.argDict['Width'] = self.mapper.argDict['Width']-10; + self.xFor.argDict['ParamOp'] = self.xFor.argDict['ParamOp']-5; - #print self.mapper.argDict - self.mapper.argDict['Width'] = float(windSpeed)*2+20 - self.xFor.argDict['ParamOp'] = float(windSpeed)*3+10*random.random(); - #print 'Width: ' + str(self.mapper.argDict['Width']) - #print 'xFor: ' + str(self.xFor.argDict['ParamOp']) return (sensorInputs, recursiveInputs) -- cgit v1.2.3 From 3cf7f82b2c88181925e01c2736e13d8be7574ab9 Mon Sep 17 00:00:00 2001 From: eugue Date: Fri, 28 Jan 2011 15:19:40 -0500 Subject: get string data instead of int --- behaviors/MobileShakeBehavior.py | 29 +++++++++++++++++++---------- behaviors/MoveBehavior.py | 18 ++++++++++-------- config/MobileTest.xml | 28 ++++++++++++---------------- inputs/TCPInput.py | 2 ++ 4 files changed, 43 insertions(+), 34 deletions(-) (limited to 'behaviors') diff --git a/behaviors/MobileShakeBehavior.py b/behaviors/MobileShakeBehavior.py index e25e929..b05cb5f 100644 --- a/behaviors/MobileShakeBehavior.py +++ b/behaviors/MobileShakeBehavior.py @@ -1,17 +1,26 @@ from operationscore.Behavior import * +import util.ComponentRegistry as compReg import util.Strings as Strings class MobileShakeBehavior(Behavior): + def behaviorInit(self): + self.mapper = None + def processResponse(self, sensorInputs, recursiveInputs): + if self.mapper == None: + try: + self.mapper = compReg.getComponent('mobilegaussmap') + except KeyError: + pass + #print sensorInputs - ret = [] for sInput in sensorInputs: - outDict = dict(sInput) - if 'type' in sInput and sInput['type'] == 2: - outDict['Location'] = '{x}>' + str(0) + ',{y}>' + str(0) - outDict['Color'] = [sInput['r'], sInput['g'], sInput['b']] - else: # dumb invisible pixel - outDict['Location'] = (-1, -1) - outDict['Color'] = [0, 0, 0] - ret.append(outDict) - return (ret, recursiveInputs) + if 'Shake' in sInput and sInput['Shake'] == 1: + #print 'increase!' + self.mapper.argDict['Width'] += 30 + #self.mapper.argDict['CutoffDist'] += 20 + sInput['Shake'] = 0 + print 'Width:' + str(compReg.getComponent('mobilegaussmap').argDict['Width']) + #print 'CutoffDist: '+ str(compReg.getComponent('mobilegaussmap').argDict['CutoffDist']) + + return (sensorInputs, recursiveInputs) diff --git a/behaviors/MoveBehavior.py b/behaviors/MoveBehavior.py index e504ca9..6f57437 100644 --- a/behaviors/MoveBehavior.py +++ b/behaviors/MoveBehavior.py @@ -13,20 +13,22 @@ class MoveBehavior(Behavior): else: currRecLocs = [{'Location' : (5, 5), 'Color' : [255, 255, 255]}] + #print sensorInputs if sensorInputs: # if input exists, change location ret = [] for currRecLoc in currRecLocs: currDict = dict(currRecLoc) for sensorInput in sensorInputs: - if 'type' in sensorInput and sensorInput['type'] == 1: - currDict['Location'] = (currDict['Location'][0] - sensorInput['x'] * self['XStep'], \ - currDict['Location'][1] + sensorInput['y'] * self['YStep']) - currDict['Color'] = [sensorInput['r'], sensorInput['g'], sensorInput['b']] - #elif sensorInput['type'] == 2: - # currDict['Shake'] = 1 - # currDict['Force'] = sensorInput['force'] + if 'type' in sensorInput and int(sensorInput['type']) == 1: + #currDict['Shake'] = 0 + currDict['Location'] = (currDict['Location'][0] - int(sensorInput['x']) * self['XStep'], \ + currDict['Location'][1] + int(sensorInput['y']) * self['YStep']) + currDict['Color'] = [int(sensorInput['r']), int(sensorInput['g']), int(sensorInput['b'])] + elif int(sensorInput['type']) == 2: + #print sensorInput + currDict['Shake'] = 1 + #currDict['Force'] = sensorInput['force'] ret.append(currDict) - #print ret return (ret, ret) else: # if not, return current recursive location. diff --git a/config/MobileTest.xml b/config/MobileTest.xml index af94c25..63c3b47 100644 --- a/config/MobileTest.xml +++ b/config/MobileTest.xml @@ -26,6 +26,16 @@ 1 + + pixelmappers.GaussianMapper + + mobilegaussmap + 30 + 0.1 + 10 + 1 + + @@ -227,26 +237,12 @@ move + mobileshake decay True - gaussmap + mobilegaussmap - - behaviors.BehaviorChain - - shakeanddecay - - tcp - - - mobileshake - slowdecay - - True - simplemap - - diff --git a/inputs/TCPInput.py b/inputs/TCPInput.py index 17ea7e6..2d8ab4d 100644 --- a/inputs/TCPInput.py +++ b/inputs/TCPInput.py @@ -38,6 +38,8 @@ class TCPInput(Input): for datagroup in data.split('\n'): if datagroup != None and datagroup != '': dataDict = json.loads(datagroup) + #if dataDict['type'] != 1: + #print dataDict self.respond(dataDict) except Exception as exp: print str(exp) -- cgit v1.2.3 From 51b0d5f0cd4524a977e0bf48ca6f643d85d05d00 Mon Sep 17 00:00:00 2001 From: eugue Date: Fri, 28 Jan 2011 16:10:58 -0500 Subject: reverted the effort to take string inputs. --- behaviors/MoveBehavior.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'behaviors') diff --git a/behaviors/MoveBehavior.py b/behaviors/MoveBehavior.py index 6f57437..6e7fc6a 100644 --- a/behaviors/MoveBehavior.py +++ b/behaviors/MoveBehavior.py @@ -13,22 +13,21 @@ class MoveBehavior(Behavior): else: currRecLocs = [{'Location' : (5, 5), 'Color' : [255, 255, 255]}] - #print sensorInputs if sensorInputs: # if input exists, change location ret = [] for currRecLoc in currRecLocs: currDict = dict(currRecLoc) for sensorInput in sensorInputs: - if 'type' in sensorInput and int(sensorInput['type']) == 1: - #currDict['Shake'] = 0 - currDict['Location'] = (currDict['Location'][0] - int(sensorInput['x']) * self['XStep'], \ - currDict['Location'][1] + int(sensorInput['y']) * self['YStep']) - currDict['Color'] = [int(sensorInput['r']), int(sensorInput['g']), int(sensorInput['b'])] - elif int(sensorInput['type']) == 2: - #print sensorInput + if 'type' in sensorInput and sensorInput['type'] == 1: + currDict['Shake'] = 0 + currDict['Location'] = (currDict['Location'][0] - sensorInput['x'] * self['XStep'], \ + currDict['Location'][1] + sensorInput['y'] * self['YStep']) + currDict['Color'] = [sensorInput['r'], sensorInput['g'], sensorInput['b']] + elif sensorInput['type'] == 2: currDict['Shake'] = 1 #currDict['Force'] = sensorInput['force'] ret.append(currDict) + #print ret return (ret, ret) else: # if not, return current recursive location. -- cgit v1.2.3 From b67a37ad06fa4c97dcdb32cecc71c7f492b12840 Mon Sep 17 00:00:00 2001 From: rcoh Date: Fri, 28 Jan 2011 16:29:36 -0500 Subject: Picking up some files that were lost. --- behaviors/ControllerOSC.py | 67 +++++++++++++++++++++++++++++++++++++++++++ behaviors/Sink.py | 42 +++++++++++++++++++++++++++ behaviors/SynchTest.py | 12 ++++++++ config/SynchTest.xml | 39 +++++++++++++++++++++++++ pixelevents/SynchTestEvent.py | 15 ++++++++++ 5 files changed, 175 insertions(+) create mode 100644 behaviors/ControllerOSC.py create mode 100644 behaviors/Sink.py create mode 100644 behaviors/SynchTest.py create mode 100644 config/SynchTest.xml create mode 100644 pixelevents/SynchTestEvent.py (limited to 'behaviors') diff --git a/behaviors/ControllerOSC.py b/behaviors/ControllerOSC.py new file mode 100644 index 0000000..ce2cf26 --- /dev/null +++ b/behaviors/ControllerOSC.py @@ -0,0 +1,67 @@ +from operationscore.Behavior import * +from logger import main_log +#import util.ColorOps as color +import colorsys +from numpy import array +import pdb +import util.ComponentRegistry as compReg + +speedfactor = 15 +vel_decay = .00 + +def constrainLocation(v,c): + if v[0] > c[0]: + v[0] = c[0] + elif v[0]<0: + v[0] = 0 + + if v[1] > c[1]: + v[1] = c[1] + elif v[1]<0: + v[1] = 0 + + return v + +class ControllerOSC(Behavior): + def behaviorInit(self): + self.xy = array((0,0)) + self.v_xy = array((0,0)) + self.v_decay = vel_decay + + self.start_hsv = [0,1,1] + self.dest_hsv = [0,1,1] + self.ssize = compReg.getComponent('Screen').getSize()[-2:] #896 x 310 + + def processResponse(self, sensorInputs, recursiveInputs): + ret = [] + if sensorInputs: + data = sensorInputs[-1]#for data in sensorInputs: + if data['Path'] == '/sixaxis/xy': + #try: + x = data['Value'][0] + y = data['Value'][1] + main_log.error(str(x)) + if y < 0: + self.start_hsv[1] = 1.0+y #s + else: + self.start_hsv[2] = 1.0-y + self.start_hsv[0] = (x+1) * 180.0 + elif data['Path'] == '/sixaxis/lrud': + val=data['Value'] + vy = val[3]-val[2] + vx = val[1]-val[0] + #pdb.set_trace() + #self.v_xy = (val[1]*ssize[0], (1.0-val[0])*ssize[1]) + self.v_xy = array((vx, vy)) * speedfactor + else: + main_log.error('Sensor Inputs: ' + str(sensorInputs)) + self.xy = self.xy + self.v_xy + constrainLocation(self.xy,self.ssize) + self.v_xy -= self.v_decay + if self.v_xy[0] < 0: + self.v_xy[0] = 0 + if self.v_xy[1] < 0: + self.v_xy[1] = 0 + ret.append({'Color':[i*255 for i in colorsys.hsv_to_rgb(*self.start_hsv)],'Location':(int(self.xy[0]), int(self.xy[1]))}) + + return (ret, []) diff --git a/behaviors/Sink.py b/behaviors/Sink.py new file mode 100644 index 0000000..52d0be2 --- /dev/null +++ b/behaviors/Sink.py @@ -0,0 +1,42 @@ + +from operationscore.Behavior import * +import math +import util.TimeOps as timeOps +#Required Args: +#Period (ms), MaxHeight, Width +class Sink(Behavior): + """RiseFall is a behavior that creates a rising and falling column of light. Specify: + -- the maximum height that it rises to. + -- the width of the column OR and + -- the period of oscillation in ms + + Designed to be used as part of a recursive hook. + """ + + def processResponse(self, sensorInputs, recurInputs): + ret = [] + for data in sensorInputs: + #first time with behavior: + data = dict(data) + if not 'StartTime' in data: + data['StartTime'] = timeOps.time() + data['Period'] = self['Period'] + data['MaxHeight'] = self['MaxHeight'] #Consider just using += + if not 'Bottom' in data: + data['Bottom'] = data['Location'][1] + if 'Width' in self: #TODO: improve + data['Width'] = self['Width'] + data['Left'] = data['Location'][0]-data['Width']/2. + data['Right'] = data['Location'][0]+data['Width']/2. + currentTime = timeOps.time() + deltaTime = currentTime-data['StartTime'] + data['Height'] = data['MaxHeight']*math.cos(deltaTime/data['Period']*(math.pi*2)) + + data['Location'] = "{x}>"+str(data['Left']) + ", " +\ + "{x}<"+str(data['Right'])+", {y}<" + str(data['Bottom']) + ",\ + {y}>"+str(data['Bottom']-data['Height']) + + ret.append(data) + return (ret, []) + + diff --git a/behaviors/SynchTest.py b/behaviors/SynchTest.py new file mode 100644 index 0000000..e7b8acc --- /dev/null +++ b/behaviors/SynchTest.py @@ -0,0 +1,12 @@ +from operationscore.Behavior import * +from pixelevents.SynchTestEvent import * +import pdb +class SynchTest(Behavior): + def behaviorInit(self): + self.rendered = False + def processResponse(self, sensorInputs, recurs): + if not self.rendered: + self.rendered = True + print 'here1' + return ([{'Location':'True', 'PixelEvent':SynchTestEvent({'Color':(255,0,0)})}], []) + return ([], []) diff --git a/config/SynchTest.xml b/config/SynchTest.xml new file mode 100644 index 0000000..fcb8293 --- /dev/null +++ b/config/SynchTest.xml @@ -0,0 +1,39 @@ + + + + + simplemap + + + + layouts/60StripLayout.xml + + + + pixelmappers.SimpleMapper + + simplemap + 20 + + + + + + renderers/60StripSeq.xml + + + renderers/Pygame.xml + + + + + + + behaviors.SynchTest + + synch + True + + + + diff --git a/pixelevents/SynchTestEvent.py b/pixelevents/SynchTestEvent.py new file mode 100644 index 0000000..3e7ed0c --- /dev/null +++ b/pixelevents/SynchTestEvent.py @@ -0,0 +1,15 @@ +from operationscore.PixelEvent import * +class SynchTestEvent(PixelEvent): + """SynchTestEvent is an event to test the synchronization of the power supplies""" + def initEvent(self): + self.eventstate = 0 + self.cachedDelay = 0 + def state(self, timeDelay): + if timeDelay != self.cachedDelay: + self.eventstate += 1 + self.cachedDelay = timeDelay + color = [0]*3 + color[self.eventstate % 3] = 150 + if self.eventstate > 500: + self.eventstate = 0 + return color -- cgit v1.2.3