~ni/nxt-python

c58968aa489da319f0d0d07d98509393b334a424 — Nicolas Schodet a month ago 203b639
Ran isort, black and flake8
2 files changed, 25 insertions(+), 10 deletions(-)

M examples/tutorial/stop_turning_motor.py
M nxt/motor.py
M examples/tutorial/stop_turning_motor.py => examples/tutorial/stop_turning_motor.py +12 -5
@@ 1,10 1,10 @@
#!/usr/bin/python3
import threading
import time

import nxt.locator
import nxt.motor

import time
import threading

with nxt.locator.find() as b:
    # Get the motor connected to the port A.
    mymotor: nxt.motor.BaseMotor = b.get_motor(nxt.motor.Port.A)


@@ 12,8 12,15 @@ with nxt.locator.find() as b:
    stop_motor = False  # controls wether the motor should stop turning

    # create thread that turns the motor
    t = threading.Thread(target=mymotor.turn, kwargs={
                         'power': 50, 'tacho_units': 360*4, 'brake': True, 'stop_turn': lambda: stop_motor})
    t = threading.Thread(
        target=mymotor.turn,
        kwargs={
            "power": 50,
            "tacho_units": 360 * 4,
            "brake": True,
            "stop_turn": lambda: stop_motor,
        },
    )
    t.start()

    # stop motor after 1sec (motor would turn approximately 3sec)

M nxt/motor.py => nxt/motor.py +13 -5
@@ 197,7 197,15 @@ def get_tacho_and_state(values):
class BaseMotor:
    """Base class for motors"""

    def turn(self, power, tacho_units, brake=True, timeout=1, emulate=True, stop_turn=lambda: False):
    def turn(
        self,
        power,
        tacho_units,
        brake=True,
        timeout=1,
        emulate=True,
        stop_turn=lambda: False,
    ):
        """Use this to turn a motor.

        :param int power: Value between -127 and 128 (an absolute value greater than 64


@@ 212,11 220,11 @@ class BaseMotor:
           If ``True``, a run() function equivalent is used. Warning: motors remember
           their positions and not using emulate may lead to strange behavior,
           especially with synced motors
        :param lambda: bool stop_turn: If stop_turn returns ``True`` the motor stops turning. 
           Depending on ``brake`` it stops by holding or not holding the motor.
        :param lambda: bool stop_turn: If stop_turn returns ``True`` the motor stops
           turning. Depending on ``brake`` it stops by holding or not holding the motor.

        The motor will not stop until it turns the desired distance or stop_turn is set to True. 
        Accuracy is much better over a USB connection than with bluetooth...
        The motor will not stop until it turns the desired distance or stop_turn returns
        True. Accuracy is much better over a USB connection than with bluetooth...
        """

        tacho_limit = tacho_units