File: motcont.py

package info (click to toggle)
nxt-python 3.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 812 kB
  • sloc: python: 6,857; xml: 22; makefile: 20; sh: 4
file content (32 lines) | stat: -rw-r--r-- 742 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
"""NXT-Python example to use Linus Atorf's MotorControl.

You need to have MotorControl22 program installed on the brick, you can find it here:

https://github.com/schodet/MotorControl

Build it and install it with nxc, or upload the precompiled version (MotorControl22.rxe
file).
"""
import time

import nxt.locator
import nxt.motcont
import nxt.motor

with nxt.locator.find() as b:
    mc = nxt.motcont.MotCont(b)

    def wait():
        while not mc.is_ready(nxt.motor.Port.A) or not mc.is_ready(nxt.motor.Port.B):
            time.sleep(0.5)

    mc.start()

    mc.cmd((nxt.motor.Port.A, nxt.motor.Port.B), 50, 360)
    wait()

    mc.cmd((nxt.motor.Port.A, nxt.motor.Port.B), -50, 360)
    wait()

    mc.stop()