Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Francis <francis@sugarlabs.org>2012-06-16 19:24:37 (GMT)
committer Daniel Francis <francis@sugarlabs.org>2012-06-16 19:24:37 (GMT)
commit434aba8ebc5c13f1dd72901a0cd65cc70e918c51 (patch)
tree89d7673b68ed92d021a646f80c1e3e8097b8273c
parent5da2f00e12120ad8da99e2c51517cff884754026 (diff)
command interpreter
-rwxr-xr-xLegoJAM.py2
-rw-r--r--TODO4
-rw-r--r--interpreter.py74
3 files changed, 77 insertions, 3 deletions
diff --git a/LegoJAM.py b/LegoJAM.py
index 7a49ea7..d9536cd 100755
--- a/LegoJAM.py
+++ b/LegoJAM.py
@@ -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
diff --git a/TODO b/TODO
index cb6e24d..1650a70 100644
--- a/TODO
+++ b/TODO
@@ -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)