def run(self): waitTime, success = self.interpreter.evaluateExpression(self.parameters['time']) # Split the wait into incriments of 0.1 seconds each, and check if the thread has been stopped at each incriment if success: wait(waitTime, self.interpreter.isExiting) return True else: printf("Commands| ERROR: Expression ", self.parameters['time'], " failed to evaluate correctly!") return False
def run(self): waitTime, success = self.interpreter.evaluateExpression( self.parameters['time']) # Split the wait into incriments of 0.1 seconds each, and check if the thread has been stopped at each incriment if success: wait(waitTime, self.interpreter.isExiting) return True else: printf("Commands| ERROR: Expression ", self.parameters['time'], " failed to evaluate correctly!") return False
def run(self): frequency, fSuccess = self.interpreter.evaluateExpression(self.parameters['frequency']) duration, dSuccess = self.interpreter.evaluateExpression(self.parameters['time']) # Check if evaluation worked if fSuccess and dSuccess: # Send buzzer command self.robot.setBuzzer(frequency, duration) # If the user wants to sleep while the buzzer is running, then sleep. if self.parameters["waitForBuzzer"]: wait(duration, self.interpreter.isExiting) return True else: printf("Commands| ERROR: ", self.parameters['frequency'], " or ", self.parameters["time"], "failed to evaluate correctly!") return False
def run(self): frequency, fSuccess = self.interpreter.evaluateExpression( self.parameters['frequency']) duration, dSuccess = self.interpreter.evaluateExpression( self.parameters['time']) # Check if evaluation worked if fSuccess and dSuccess: # Send buzzer command self.robot.setBuzzer(frequency, duration) # If the user wants to sleep while the buzzer is running, then sleep. if self.parameters["waitForBuzzer"]: wait(duration, self.interpreter.isExiting) return True else: printf("Commands| ERROR: ", self.parameters['frequency'], " or ", self.parameters["time"], "failed to evaluate correctly!") return False
def cleanNamespace(self): """ This function resets the self.variables namespace, and creates a variable called self.execBuiltins which holds the python builtin functions that are allowed in the Script command. It also adds several things as builtins. Extra Builtins - robot - vision - settings - resources - vStream Excluded Builtins - setattr - dir - next - id - object - staticmethod - eval - open - exec - format - getattr - memoryview - compile - classmethod - repr - property - hasattr - help - input """ # Reset self.__variables with the default values/functions # safeList = ['acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'floor', 'fmod', 'frexp', 'hypot', 'ldexp', 'log', 'log10', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh'] variables = dict([(k, getattr(math, k)) for k in safeList]) variables['math'] = math robot = self.env.getRobot() vision = self.env.getVision() settings = self.env.getSettings() resources = self.env.getObjectManager() vStream = self.env.getVStream() newSleep = lambda time: wait(time, self.isExiting) isExiting = self.isExiting # Add Python builtins, and also the extra ones (above) execBuiltins = { "abs": abs, "dict": dict, "__import__": __import__, "all": all, "hex": hex, "slice": slice, "any": any, "divmod": divmod, "sorted": sorted, "ascii": ascii, "enumerate": enumerate, "range": range, "bin": bin, "int": int, "str": str, "bool": bool, "isinstance": isinstance, "ord": ord, "bytearray": bytearray, "filter": filter, "issubclass": issubclass, "bytes": bytes, "float": float, "iter": iter, "callable": callable, "len": len, "type": type, "chr": chr, "frozenset": frozenset, "list": list, "locals": locals, "zip": zip, "vars": vars, "globals": globals, "map": map, "reversed": reversed, "complex": complex, "max": max, "round": round, "delattr": delattr, "hash": hash, "set": set, "min": min, "oct": oct, "sum": sum, "pow": pow, "super": super, "print": printf, "tuple": tuple, "robot": robot, "resources": resources, "vision": vision, "settings": settings, "vStream": vStream, "sleep": newSleep, "isStopping": isExiting, "classmethod": classmethod, "object": object, "__build_class__": __build_class__, "__name__": "__main__"} execBuiltins = {"__builtins__": execBuiltins, "variables": variables, "__author__": "Alexander Thiel"} self.nameSpace = execBuiltins
def cleanNamespace(self): """ This function resets the self.variables namespace, and creates a variable called self.execBuiltins which holds the python builtin functions that are allowed in the Script command. It also adds several things as builtins. Extra Builtins - robot - vision - settings - resources - vStream Excluded Builtins - setattr - dir - next - id - object - staticmethod - eval - open - exec - format - getattr - memoryview - compile - repr - property - hasattr - help - input """ # Reset self.__variables with the default values/functions # safeList = [ 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'cosh', 'degrees', 'log10', 'e', 'exp', 'fabs', 'floor', 'fmod', 'frexp', 'hypot', 'ldexp', 'log', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh' ] variables = dict([(k, getattr(math, k)) for k in safeList]) variables['math'] = math customPrint = lambda *args: printf("Output| ", *args) robot = self.env.getRobot() vision = self.env.getVision() settings = self.env.getSettings() resources = self.env.getObjectManager() vStream = self.env.getVStream() newSleep = lambda time: wait(time, self.isExiting) isExiting = self.isExiting # Add Python builtins, and also the extra ones (above) builtins = { "abs": abs, "dict": dict, "__import__": __import__, "all": all, "hex": hex, "slice": slice, "any": any, "divmod": divmod, "sorted": sorted, "ascii": ascii, "enumerate": enumerate, "range": range, "bin": bin, "int": int, "str": str, "bool": bool, "isinstance": isinstance, "ord": ord, "bytearray": bytearray, "filter": filter, "issubclass": issubclass, "bytes": bytes, "float": float, "iter": iter, "callable": callable, "len": len, "type": type, "chr": chr, "frozenset": frozenset, "list": list, "locals": locals, "zip": zip, "vars": vars, "globals": globals, "map": map, "reversed": reversed, "complex": complex, "max": max, "round": round, "delattr": delattr, "hash": hash, "set": set, "min": min, "oct": oct, "sum": sum, "pow": pow, "super": super, "print": customPrint, "tuple": tuple, "robot": robot, "resources": resources, "vision": vision, "settings": settings, "vStream": vStream, "sleep": newSleep, "scriptStopping": isExiting, "classmethod": classmethod, "object": object, "__build_class__": __build_class__, "__name__": "__main__", "env": self.env, "interpreter": self } namespace = {} namespace.update(commandClasses) namespace.update(eventClasses) namespace.update(variables) namespace.update(builtins) namespace.update({"__author__": "Alexander Thiel"}) self.nameSpace = namespace