diff options
author | rcoh <rcoh@mit.edu> | 2011-02-16 18:29:41 -0500 |
---|---|---|
committer | rcoh <rcoh@mit.edu> | 2011-02-16 18:29:41 -0500 |
commit | fffc14c4672294d9bbf8c60edfe8c309f0d54698 (patch) | |
tree | 19057b2e98735cc30fa1e0b3932d416946f8d705 /behaviors/Circle.py | |
parent | 24aa31808de6a4dc06a651076e5b292aebd9240d (diff) | |
parent | 2df9e408a0ff74539862c4a4e562a878cc11a329 (diff) |
Merge branch 'conner5' of https://github.com/dxiao/SmootLight into dxiao-conner5
Conflicts:
config/C5Sign.xml
layouts/SpecifiedLayout.py
Diffstat (limited to 'behaviors/Circle.py')
-rw-r--r-- | behaviors/Circle.py | 29 |
1 files changed, 29 insertions, 0 deletions
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 |