aboutsummaryrefslogtreecommitdiff
path: root/behaviors
diff options
context:
space:
mode:
authorGravatar rcoh <rcoh@mit.edu>2011-02-13 16:03:39 -0500
committerGravatar rcoh <rcoh@mit.edu>2011-02-13 16:03:39 -0500
commit6e0e6869a5ee1e4963071a18f24aa4dfdd442689 (patch)
tree59dfe233e69f331afe3be9137fe5638f359e1f56 /behaviors
parentf6dd5ab92949843d2fb163e2d84f19e824a291dc (diff)
Added a circle behavior to make circles. Added ContinuousCenterInput to do what it says. Modified
SimpleMapper a bit.
Diffstat (limited to 'behaviors')
-rw-r--r--behaviors/Circle.py29
-rw-r--r--behaviors/ModifyParam.py2
2 files changed, 31 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
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)