aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcusw2011-02-18 02:10:40 +0000
committermarcusw2011-02-18 02:10:40 +0000
commitb23ed7ccffd22ff921d24b4fc7cc6601ec5548da (patch)
treed902ca3c40934a593996fbee641617ec1a124ec4
parentc8c17470a0fc0211628a2b5b87c82a86990e4525 (diff)
Added move_to() function to motcont module. Note that the tacho count is reset when the MotorControl program is restarted.
-rw-r--r--nxt/motcont.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/nxt/motcont.py b/nxt/motcont.py
index 1457e70..a0ba9d9 100644
--- a/nxt/motcont.py
+++ b/nxt/motcont.py
@@ -56,8 +56,6 @@ b.stop_program().
self.is_ready_lock = Lock()
self.last_is_ready = time.time()-1
self.last_cmd = {}
- #TODO: Timing code (15ms between cmds for different motors; 10ms for anything after is_ready)
- #TODO: Check timing code
def cmd(self, port, power, tacholimit, speedreg=1, smoothstart=0, brake=0):
'''
@@ -78,6 +76,18 @@ place (DIFFERENT from the nxt.motor.turn() function's brake arg).'''
self.brick.message_write(1, command)
self.last_cmd[port] = time.time()
+ def move_to(self, port, power, tachocount, speedreg=1, smoothstart=0, brake=0):
+ '''
+Same as cmd(), except that the tachocount is subtracted from the motor's
+current position and that value is used to turn the motor. Power is
+-100-100, but the sign is rewritten as needed.'''
+ tacho = nxt.Motor(self.brick, port).get_tacho().block_tacho_count
+ tacho = tachocount-tacho
+ tsign = int(tacho >= 0) * 2 - 1
+ tacho = abs(tacho)
+ power = abs(power)*tsign
+ self.cmd(port, power, tacho, speedreg, smoothstart, brake)
+
def reset_tacho(self, port):
'''
Sends a "RESET_ERROR_CORRECTION" to MotorControl, which causes it to