From 8d014f88994c5c5d616aca790bf80b7abb2c5198 Mon Sep 17 00:00:00 2001 From: mdan Date: Thu, 27 Jan 2011 17:57:47 -0500 Subject: Mirrors fix from main branch. --- renderers/PygameRenderer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/renderers/PygameRenderer.py b/renderers/PygameRenderer.py index 9582a03..220f861 100644 --- a/renderers/PygameRenderer.py +++ b/renderers/PygameRenderer.py @@ -9,11 +9,11 @@ class PygameRenderer(Renderer): 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')) + self.background.fill(Color(0,0,0)) self.stopwatch = timeops.Stopwatch() self.stopwatch.start() def render(self, lightSystem, currentTime=timeops.time()): - self.background.fill(Color('Black')) + self.background.fill(Color(0,0,0)) #print 'drawing color:',light.color for light in lightSystem: pygame.draw.circle(self.background, light.state(currentTime), light.location, \ -- cgit v1.2.3 From 44659801073c059aeac5a992dc241648263c74b6 Mon Sep 17 00:00:00 2001 From: mdan Date: Thu, 27 Jan 2011 17:58:47 -0500 Subject: Modifies OSC configuration and behavior. --- behaviors/TouchOSC.py | 3 ++- config/6thFloorOSC.xml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/behaviors/TouchOSC.py b/behaviors/TouchOSC.py index 1c41b5e..354b845 100644 --- a/behaviors/TouchOSC.py +++ b/behaviors/TouchOSC.py @@ -12,7 +12,8 @@ class TouchOSC(Behavior): self.xy = (-1,-1) def processResponse(self, sensorInputs, recursiveInputs): ret = [] - for data in sensorInputs: + if sensorInputs: + data = sensorInputs[-1]#for data in sensorInputs: if data['Path'] == '/1/fader1': try: self.h = data['Value'][0]*360.0 diff --git a/config/6thFloorOSC.xml b/config/6thFloorOSC.xml index 792fd0c..d3f0e6f 100644 --- a/config/6thFloorOSC.xml +++ b/config/6thFloorOSC.xml @@ -42,7 +42,7 @@ osc 12345 - 10 + 20 -- cgit v1.2.3 From b8bb5e82a2e8802b9adb1258463d4198f974dbd1 Mon Sep 17 00:00:00 2001 From: mdan Date: Fri, 28 Jan 2011 09:19:11 -0500 Subject: added behavior for sixaxis controller over OSC-- untested --- behaviors/ControllerOSC.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 behaviors/ControllerOSC.py diff --git a/behaviors/ControllerOSC.py b/behaviors/ControllerOSC.py new file mode 100644 index 0000000..6e3e814 --- /dev/null +++ b/behaviors/ControllerOSC.py @@ -0,0 +1,62 @@ +from operationscore.Behavior import * +from logger import main_log +#import util.ColorOps as color +import colorsys +from numpy import arrray +import pdb +import util.ComponentRegistry as compReg + +def constrain(v,c): + if v[0] > c[1]: + v[0] = c[1] + elif v[0]<0 + v[0] = 0 + + if v[1] > c[0]: + v[1] = c[0] + elif v[1]<0 + v[1] = 0 + + return v + +class TouchOSC(Behavior): + def behaviorInit(self): + self.xy = array((0,0)) + self.v_xy = array((0,0)) + self.v_decay = .1 + + self.start_hsv = (0,1,1) + self.dest_hsv = (0,1,1) + + 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] + if y < 0: + self.start_hsv[1] = 1+y #s + else: + self.start_hsv[2] = y + self.h += x +#self.h = x * 360. + + except: + pdb.set_trace() + elif data['Path'] == '/sixaxis/lrud': + val=data['Value'] + ssize = compReg.getComponent('Screen').getSize()[-2:] #896 x 310 + vx = -val[3] if val[3] else val[2] + vy = -val[0] if val[0] else val[1] + #self.v_xy = (val[1]*ssize[0], (1.0-val[0])*ssize[1]) + self.v_xy = array((vx, vy)) + else: + main_log.error('Sensor Inputs: ' + str(sensorInputs)) + self.xy = self.xy + self.v_xy + constrain(self.xy,ssize) + self.v_xy -= self.v_decay + ret.append({'Color':[i*256 for i in colorsys.hsv_to_rgb(*self.start_hsv)],'Location':tuple(self.xy)}) + + return (ret, []) -- cgit v1.2.3 From fac2f8373cd0e63a34a39cb77c0c7276d1d88b65 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 28 Jan 2011 15:25:21 -0500 Subject: Fixed Problems with controller --- behaviors/ControllerOSC.py | 61 ++++++++++++++++++++++++++++------------------ oscserver.py | 36 --------------------------- testosc.py | 36 --------------------------- 3 files changed, 37 insertions(+), 96 deletions(-) delete mode 100755 oscserver.py delete mode 100755 testosc.py diff --git a/behaviors/ControllerOSC.py b/behaviors/ControllerOSC.py index 6e3e814..0dd1b12 100644 --- a/behaviors/ControllerOSC.py +++ b/behaviors/ControllerOSC.py @@ -2,61 +2,74 @@ from operationscore.Behavior import * from logger import main_log #import util.ColorOps as color import colorsys -from numpy import arrray +from numpy import array import pdb import util.ComponentRegistry as compReg -def constrain(v,c): - if v[0] > c[1]: - v[0] = c[1] - elif v[0]<0 +speedfactor = 15 +vel_decay = .01 + +def constrainLocation(v,c): + if v[0] > c[0]: + v[0] = c[0] + elif v[0]<0: v[0] = 0 - if v[1] > c[0]: - v[1] = c[0] - elif v[1]<0 + if v[1] > c[1]: + v[1] = c[1] + elif v[1]<0: v[1] = 0 return v -class TouchOSC(Behavior): +class ControllerOSC(Behavior): def behaviorInit(self): self.xy = array((0,0)) self.v_xy = array((0,0)) - self.v_decay = .1 + self.v_decay = vel_decay - self.start_hsv = (0,1,1) - self.dest_hsv = (0,1,1) + 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: + #try: x = data['Value'][0] y = data['Value'][1] if y < 0: - self.start_hsv[1] = 1+y #s + self.start_hsv[1] = 1.0+y #s else: - self.start_hsv[2] = y - self.h += x + self.start_hsv[2] = 1.0-y + self.start_hsv[0] = (x+1) * 180.0 +# if self.start_hsv[0] >= 360: +# self.start_hsv[0] = 0 +# if self.start_hsv[0] <=0: +# self.start_hsv[0] = 360 #self.h = x * 360. - except: - pdb.set_trace() + #except(e): + # pdb.set_trace() elif data['Path'] == '/sixaxis/lrud': val=data['Value'] - ssize = compReg.getComponent('Screen').getSize()[-2:] #896 x 310 - vx = -val[3] if val[3] else val[2] - vy = -val[0] if val[0] else val[1] + vy = val[3] if val[3] else -val[2] + vx = -val[0] if val[0] else val[1] + #pdb.set_trace() #self.v_xy = (val[1]*ssize[0], (1.0-val[0])*ssize[1]) - self.v_xy = array((vx, vy)) + self.v_xy = array((vx, vy)) * speedfactor else: main_log.error('Sensor Inputs: ' + str(sensorInputs)) self.xy = self.xy + self.v_xy - constrain(self.xy,ssize) + constrainLocation(self.xy,self.ssize) self.v_xy -= self.v_decay - ret.append({'Color':[i*256 for i in colorsys.hsv_to_rgb(*self.start_hsv)],'Location':tuple(self.xy)}) + 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*256 for i in + colorsys.hsv_to_rgb(*self.start_hsv)],'Location':(int(self.xy[0]), int(self.xy[1]))}) return (ret, []) diff --git a/oscserver.py b/oscserver.py deleted file mode 100755 index 6763f41..0000000 --- a/oscserver.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python - -import liblo, sys - -# create server, listening on port 1234 -try: - server = liblo.Server(1234) -except liblo.ServerError, err: - print str(err) - sys.exit() - -def foo_bar_callback(path, args): - i, f = args - print "received message '%s' with arguments '%d' and '%f'" % (path, i, f) - -def foo_baz_callback(path, args, types, src, data): - print "received message '%s'" % path - print "blob contains %d bytes, user data was '%s'" % (len(args[0]), data) - -def fallback(path, args, types, src): - print "got unknown message '%s' from '%s'" % (path, src.get_url()) - for a, t in zip(args, types): - print "argument of type '%s': %s" % (t, a) - -# register method taking an int and a float -server.add_method("/foo/bar", 'if', foo_bar_callback) - -# register method taking a blob, and passing user data to the callback -server.add_method("/foo/baz", 'b', foo_baz_callback, "blah") - -# register a fallback for unhandled messages -server.add_method(None, None, fallback) - -# loop and dispatch messages every 100ms -while True: - server.recv(100) diff --git a/testosc.py b/testosc.py deleted file mode 100755 index cea03f4..0000000 --- a/testosc.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python - -import liblo, sys - -# create server, listening on port 1234 -try: - server = liblo.Server(12345) -except liblo.ServerError, err: - print str(err) - sys.exit() - -def foo_bar_callback(path, args): - i, f = args - print "received message '%s' with arguments '%d' and '%f'" % (path, i, f) - -def foo_baz_callback(path, args, types, src, data): - print "received message '%s'" % path - print "blob contains %d bytes, user data was '%s'" % (len(args[0]), data) - -def fallback(path, args, types, src): - print "got unknown message '%s' from '%s'" % (path, src.get_url()) - for a, t in zip(args, types): - print "argument of type '%s': %s" % (t, a) - -# register method taking an int and a float -server.add_method("/foo/bar", 'if', foo_bar_callback) - -# register method taking a blob, and passing user data to the callback -server.add_method("/foo/baz", 'b', foo_baz_callback, "blah") - -# register a fallback for unhandled messages -server.add_method(None, None, fallback) - -# loop and dispatch messages every 100ms -while True: - server.recv(100) -- cgit v1.2.3 From f95eff2616f8e7c952a31756f079aef87f28a1d4 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 28 Jan 2011 16:15:26 -0500 Subject: readded testosc in tests directory --- tests/testosc.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 tests/testosc.py diff --git a/tests/testosc.py b/tests/testosc.py new file mode 100755 index 0000000..6763f41 --- /dev/null +++ b/tests/testosc.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +import liblo, sys + +# create server, listening on port 1234 +try: + server = liblo.Server(1234) +except liblo.ServerError, err: + print str(err) + sys.exit() + +def foo_bar_callback(path, args): + i, f = args + print "received message '%s' with arguments '%d' and '%f'" % (path, i, f) + +def foo_baz_callback(path, args, types, src, data): + print "received message '%s'" % path + print "blob contains %d bytes, user data was '%s'" % (len(args[0]), data) + +def fallback(path, args, types, src): + print "got unknown message '%s' from '%s'" % (path, src.get_url()) + for a, t in zip(args, types): + print "argument of type '%s': %s" % (t, a) + +# register method taking an int and a float +server.add_method("/foo/bar", 'if', foo_bar_callback) + +# register method taking a blob, and passing user data to the callback +server.add_method("/foo/baz", 'b', foo_baz_callback, "blah") + +# register a fallback for unhandled messages +server.add_method(None, None, fallback) + +# loop and dispatch messages every 100ms +while True: + server.recv(100) -- cgit v1.2.3 From 61d3da8be78c093384b7f87c854c09c255f6384e Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 28 Jan 2011 17:26:53 -0500 Subject: Finished merge of fridaydemo, restored fixed ControllerOSC.py --- behaviors/ControllerOSC.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 behaviors/ControllerOSC.py diff --git a/behaviors/ControllerOSC.py b/behaviors/ControllerOSC.py new file mode 100644 index 0000000..05d2e7d --- /dev/null +++ b/behaviors/ControllerOSC.py @@ -0,0 +1,62 @@ +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 = .9 + +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] + 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)/2. + 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 + 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, []) -- cgit v1.2.3