diff options
author | Daniel Francis <francis@sugarlabs.org> | 2012-06-16 19:24:37 (GMT) |
---|---|---|
committer | Daniel Francis <francis@sugarlabs.org> | 2012-06-16 19:24:37 (GMT) |
commit | 434aba8ebc5c13f1dd72901a0cd65cc70e918c51 (patch) | |
tree | 89d7673b68ed92d021a646f80c1e3e8097b8273c | |
parent | 5da2f00e12120ad8da99e2c51517cff884754026 (diff) |
command interpreter
-rwxr-xr-x | LegoJAM.py | 2 | ||||
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | interpreter.py | 74 |
3 files changed, 77 insertions, 3 deletions
@@ -108,7 +108,7 @@ class Pancho(): def set_up(self): try: - self.robot = nxt.locator.find_one_brick() + self.robot = nxt.locator.find_one_brick(debug=True) for funcion in dir(self.robot): self.funciones.append(funcion) print funcion @@ -1,8 +1,8 @@ New functions / Nuevas Funciones: - + Bugs / Bichos: Fixes / Mejoras: - + Use (usar) listview Ready / Listo: Pep8 (e)standard. diff --git a/interpreter.py b/interpreter.py new file mode 100644 index 0000000..d95b01d --- /dev/null +++ b/interpreter.py @@ -0,0 +1,74 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import sys +sys.path.append("nxt_plugin") + +# Import the API functions +# Importamos las funciones de la API +import nxt +from nxt import Motor + + +class Robot(): + def __init__(self): + self.nombre = 'Pancho' + self.motors = [] + self.funciones = [] + self.ready = False + self.speed = 127 + + def setup(self): + try: + self.robot = nxt.locator.find_one_brick() + for funcion in dir(self.robot): + self.funciones.append(funcion) + print funcion + print self.robot.get_device_info() + except: + print "El Robot se Encuentra Desconectado o Apagado" + return False + self.motors.append(Motor(self.robot, nxt.PORT_A)) + self.motors.append(Motor(self.robot, nxt.PORT_B)) + self.motors.append(Motor(self.robot, nxt.PORT_C)) + self.ready = True + return True + + def run_motor(self, motor): + self.motors[motor].run(power=127, regulated=False) + + def stop_motor(self, motor): + self.motors[motor].brake() + + #self.turn(power = 100, tacho_units = 360, emulate = True) + #self.turn( + #power = 100, + #tacho_units= 0, brake = True, timeout = 1, emulate = True) + #self.run(power = 100, regulated=False) + + +class NotLoadedError(Exception): + def __init__(self): + self.msg = "There is not a robot loaded" + +robot = Robot() + + +def parse_line(line): + if line == 'load' and not robot.ready: + robot.setup() + return + elif line == 'exit': + exit() + keywords = line.split() + if keywords[0] == 'motor': + if keywords[1] == 'run': + print keywords + robot.run_motor(int(keywords[2])) + elif keywords[1] == 'stop': + robot.stop_motor(int(keywords[2])) + + +while True: + line = raw_input('> ') + parse_line(line) |