~ni/nxt-python

ref: b1c5d6f75580306c253f0cada36ef57dd6a40435 nxt-python/examples/motcont.py -rw-r--r-- 681 bytes
b1c5d6f7Nicolas Schodet Update freebsd tests 5 months ago
                                                                                
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
#!/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.
"""
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()