mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-12 01:24:17 +00:00
jedi: add new pybricks_jedi package
This package will be used in Pybricks Code to provide some intellesense operations.
This commit is contained in:
+13
-6
@@ -4,16 +4,23 @@
|
||||
"""Generic cross-platform module for typical devices like lights, displays,
|
||||
speakers, and batteries."""
|
||||
|
||||
from typing import Union, Iterable, overload, Optional, Tuple, Collection
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Union, Iterable, overload, Optional, Tuple, Collection, TYPE_CHECKING
|
||||
|
||||
from .geometry import Matrix, Axis
|
||||
from .parameters import Direction, Stop, Button, Port, Color, Side, Number
|
||||
from .parameters import Direction, Stop, Button, Port, Color, Side
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .parameters import Number
|
||||
|
||||
|
||||
class System:
|
||||
"""System control actions for a hub."""
|
||||
|
||||
def set_stop_button(self, button: Union[Button, Iterable[Button]]) -> None:
|
||||
def set_stop_button(
|
||||
self, button: Optional[Union[Button, Iterable[Button]]]
|
||||
) -> None:
|
||||
"""
|
||||
set_stop_button(button)
|
||||
|
||||
@@ -62,7 +69,7 @@ class System:
|
||||
"""
|
||||
|
||||
|
||||
class CommonDCMotor:
|
||||
class DCMotor:
|
||||
"""Generic class to control simple motors without rotation sensors, such
|
||||
as train motors."""
|
||||
|
||||
@@ -289,7 +296,7 @@ class Control:
|
||||
"""
|
||||
|
||||
|
||||
class CommonMotor(CommonDCMotor):
|
||||
class Motor(DCMotor):
|
||||
"""Generic class to control motors with built-in rotation sensors."""
|
||||
|
||||
control = Control()
|
||||
@@ -897,7 +904,7 @@ class IMU(Accelerometer):
|
||||
"""
|
||||
|
||||
def reset_heading(self, angle: Number) -> None:
|
||||
"""reset_heading(angle: Number)
|
||||
"""reset_heading(angle)
|
||||
|
||||
Resets the accumulated heading angle of the robot.
|
||||
|
||||
|
||||
+18
-11
@@ -5,18 +5,23 @@
|
||||
|
||||
from typing import Optional, Tuple, List
|
||||
|
||||
from ._common import CommonMotor
|
||||
from .parameters import Direction, Port, Color, Button
|
||||
from . import _common
|
||||
from .parameters import (
|
||||
Button as _Button,
|
||||
Color as _Color,
|
||||
Direction as _Direction,
|
||||
Port as _Port,
|
||||
)
|
||||
|
||||
|
||||
class Motor(CommonMotor):
|
||||
class Motor(_common.Motor):
|
||||
"""LEGO® MINDSTORMS® EV3 Motor."""
|
||||
|
||||
|
||||
class TouchSensor:
|
||||
"""LEGO® MINDSTORMS® EV3 Touch Sensor."""
|
||||
|
||||
def __init__(self, port: Port):
|
||||
def __init__(self, port: _Port):
|
||||
"""TouchSensor(port)
|
||||
|
||||
Arguments:
|
||||
@@ -37,14 +42,14 @@ class TouchSensor:
|
||||
class ColorSensor:
|
||||
"""LEGO® MINDSTORMS® EV3 Color Sensor."""
|
||||
|
||||
def __init__(self, port: Port):
|
||||
def __init__(self, port: _Port):
|
||||
"""ColorSensor(port)
|
||||
|
||||
Arguments:
|
||||
port (Port): Port to which the sensor is connected.
|
||||
"""
|
||||
|
||||
def color(self) -> Optional[Color]:
|
||||
def color(self) -> Optional[_Color]:
|
||||
"""color() -> Color
|
||||
|
||||
Measures the color of a surface.
|
||||
@@ -92,7 +97,7 @@ class ColorSensor:
|
||||
class InfraredSensor:
|
||||
"""LEGO® MINDSTORMS® EV3 Infrared Sensor and Beacon."""
|
||||
|
||||
def __init__(self, port: Port):
|
||||
def __init__(self, port: _Port):
|
||||
"""InfraredSensor(port)
|
||||
|
||||
Arguments:
|
||||
@@ -129,7 +134,7 @@ class InfraredSensor:
|
||||
a tuple of (``None``, ``None``) if no remote is detected.
|
||||
"""
|
||||
|
||||
def buttons(self, channel: int) -> List[Button]:
|
||||
def buttons(self, channel: int) -> List[_Button]:
|
||||
"""buttons(channel) -> List[Button]
|
||||
|
||||
Checks which buttons on the infrared remote are pressed.
|
||||
@@ -145,7 +150,7 @@ class InfraredSensor:
|
||||
|
||||
"""
|
||||
|
||||
def keypad(self) -> List[Button]:
|
||||
def keypad(self) -> List[_Button]:
|
||||
"""keypad() -> List[Button]
|
||||
|
||||
Checks which buttons on the infrared remote are pressed.
|
||||
@@ -163,7 +168,9 @@ class InfraredSensor:
|
||||
class GyroSensor:
|
||||
"""LEGO® MINDSTORMS® EV3 Gyro Sensor."""
|
||||
|
||||
def __init__(self, port: Port, positive_direction: Direction = Direction.CLOCKWISE):
|
||||
def __init__(
|
||||
self, port: _Port, positive_direction: _Direction = _Direction.CLOCKWISE
|
||||
):
|
||||
"""GyroSensor(port)
|
||||
|
||||
Arguments:
|
||||
@@ -207,7 +214,7 @@ class GyroSensor:
|
||||
class UltrasonicSensor:
|
||||
"""LEGO® MINDSTORMS® EV3 Ultrasonic Sensor."""
|
||||
|
||||
def __init__(self, port: Port):
|
||||
def __init__(self, port: _Port):
|
||||
"""UltrasonicSensor(port)
|
||||
|
||||
Arguments:
|
||||
|
||||
+47
-57
@@ -2,21 +2,11 @@
|
||||
# Copyright (c) 2018-2020 The Pybricks Authors
|
||||
|
||||
"""LEGO® Programmable Hubs."""
|
||||
from ._common import (
|
||||
Speaker,
|
||||
Battery,
|
||||
ColorLight,
|
||||
Keypad,
|
||||
LightMatrix,
|
||||
IMU,
|
||||
Charger,
|
||||
System,
|
||||
SimpleAccelerometer,
|
||||
)
|
||||
from .ev3dev._speaker import Speaker as EV3Speaker
|
||||
from .geometry import Axis
|
||||
from .media.ev3dev import Image
|
||||
from .parameters import Button
|
||||
from . import _common
|
||||
from .ev3dev import _speaker
|
||||
from .geometry import Axis as _Axis
|
||||
from .media.ev3dev import Image as _Image
|
||||
from .parameters import Button as _Button
|
||||
|
||||
|
||||
class EV3Brick:
|
||||
@@ -24,19 +14,19 @@ class EV3Brick:
|
||||
|
||||
# These class attributes are here for auto-documentation only.
|
||||
# In reality, they are instance attributes created by __init__.
|
||||
buttons = Keypad(
|
||||
(
|
||||
Button.LEFT,
|
||||
Button.RIGHT,
|
||||
Button.CENTER,
|
||||
Button.UP,
|
||||
Button.DOWN,
|
||||
)
|
||||
buttons = _common.Keypad(
|
||||
[
|
||||
_Button.LEFT,
|
||||
_Button.RIGHT,
|
||||
_Button.CENTER,
|
||||
_Button.UP,
|
||||
_Button.DOWN,
|
||||
]
|
||||
)
|
||||
screen = Image("_screen_")
|
||||
speaker = EV3Speaker()
|
||||
battery = Battery()
|
||||
light = ColorLight()
|
||||
screen = _Image("_screen_")
|
||||
speaker = _speaker.Speaker()
|
||||
battery = _common.Battery()
|
||||
light = _common.ColorLight()
|
||||
|
||||
|
||||
class MoveHub:
|
||||
@@ -44,11 +34,11 @@ class MoveHub:
|
||||
|
||||
# These class attributes are here for auto-documentation only.
|
||||
# In reality, they are instance attributes created by __init__.
|
||||
battery = Battery()
|
||||
light = ColorLight()
|
||||
imu = SimpleAccelerometer()
|
||||
system = System()
|
||||
button = Keypad((Button.CENTER,))
|
||||
battery = _common.Battery()
|
||||
light = _common.ColorLight()
|
||||
imu = _common.SimpleAccelerometer()
|
||||
system = _common.System()
|
||||
button = _common.Keypad([_Button.CENTER])
|
||||
|
||||
|
||||
class CityHub:
|
||||
@@ -56,10 +46,10 @@ class CityHub:
|
||||
|
||||
# These class attributes are here for auto-documentation only.
|
||||
# In reality, they are instance attributes created by __init__.
|
||||
battery = Battery()
|
||||
light = ColorLight()
|
||||
system = System()
|
||||
button = Keypad((Button.CENTER,))
|
||||
battery = _common.Battery()
|
||||
light = _common.ColorLight()
|
||||
system = _common.System()
|
||||
button = _common.Keypad([_Button.CENTER])
|
||||
|
||||
|
||||
class TechnicHub:
|
||||
@@ -67,13 +57,13 @@ class TechnicHub:
|
||||
|
||||
# These class attributes are here for auto-documentation only.
|
||||
# In reality, they are instance attributes created by __init__.
|
||||
battery = Battery()
|
||||
light = ColorLight()
|
||||
imu = IMU()
|
||||
system = System()
|
||||
button = Keypad((Button.CENTER,))
|
||||
battery = _common.Battery()
|
||||
light = _common.ColorLight()
|
||||
imu = _common.IMU()
|
||||
system = _common.System()
|
||||
button = _common.Keypad([_Button.CENTER])
|
||||
|
||||
def __init__(self, top_side: Axis = Axis.Z, front_side: Axis = Axis.X):
|
||||
def __init__(self, top_side: _Axis = _Axis.Z, front_side: _Axis = _Axis.X):
|
||||
"""TechnicHub(top_side=Axis.Z, front_side=Axis.X)
|
||||
|
||||
Initializes the hub. Optionally, specify how the hub is
|
||||
@@ -94,23 +84,23 @@ class PrimeHub:
|
||||
|
||||
# These class attributes are here for auto-documentation only.
|
||||
# In reality, they are instance attributes created by __init__.
|
||||
battery = Battery()
|
||||
buttons = Keypad(
|
||||
(
|
||||
Button.LEFT,
|
||||
Button.RIGHT,
|
||||
Button.CENTER,
|
||||
Button.BLUETOOTH,
|
||||
)
|
||||
battery = _common.Battery()
|
||||
buttons = _common.Keypad(
|
||||
[
|
||||
_Button.LEFT,
|
||||
_Button.RIGHT,
|
||||
_Button.CENTER,
|
||||
_Button.BLUETOOTH,
|
||||
]
|
||||
)
|
||||
charger = Charger()
|
||||
light = ColorLight()
|
||||
display = LightMatrix(5, 5)
|
||||
speaker = Speaker()
|
||||
imu = IMU()
|
||||
system = System()
|
||||
charger = _common.Charger()
|
||||
light = _common.ColorLight()
|
||||
display = _common.LightMatrix(5, 5)
|
||||
speaker = _common.Speaker()
|
||||
imu = _common.IMU()
|
||||
system = _common.System()
|
||||
|
||||
def __init__(self, top_side: Axis = Axis.Z, front_side: Axis = Axis.X):
|
||||
def __init__(self, top_side: _Axis = _Axis.Z, front_side: _Axis = _Axis.X):
|
||||
"""PrimeHub(top_side=Axis.Z, front_side=Axis.X)
|
||||
|
||||
Initializes the hub. Optionally, specify how the hub is
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
|
||||
from typing import Dict, Tuple, Optional, overload
|
||||
|
||||
from ._common import CommonDCMotor
|
||||
from .parameters import Port
|
||||
from . import _common
|
||||
from .parameters import Port as _Port
|
||||
|
||||
|
||||
class PUPDevice:
|
||||
"""Powered Up motor or sensor."""
|
||||
|
||||
def __init__(self, port: Port):
|
||||
def __init__(self, port: _Port):
|
||||
"""PUPDevice(port)
|
||||
|
||||
Arguments:
|
||||
@@ -55,7 +55,7 @@ class PUPDevice:
|
||||
class LUMPDevice:
|
||||
"""Devices using the LEGO UART Messaging Protocol."""
|
||||
|
||||
def __init__(self, port: Port):
|
||||
def __init__(self, port: _Port):
|
||||
"""LUMPDevice(port)
|
||||
|
||||
Arguments:
|
||||
@@ -75,7 +75,7 @@ class LUMPDevice:
|
||||
"""
|
||||
|
||||
|
||||
class DCMotor(CommonDCMotor):
|
||||
class DCMotor(_common.DCMotor):
|
||||
"""DC Motor for LEGO® MINDSTORMS EV3."""
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ class Ev3devSensor:
|
||||
port_index: int
|
||||
"""Index of the ev3dev sysfs `lego-port`_ class."""
|
||||
|
||||
def __init__(self, port: Port):
|
||||
def __init__(self, port: _Port):
|
||||
"""Ev3devSensor(port)
|
||||
|
||||
Arguments:
|
||||
@@ -111,7 +111,7 @@ class Ev3devSensor:
|
||||
class AnalogSensor:
|
||||
"""Generic or custom analog sensor."""
|
||||
|
||||
def __init__(self, port: Port):
|
||||
def __init__(self, port: _Port):
|
||||
"""AnalogSensor(port)
|
||||
|
||||
Arguments:
|
||||
@@ -167,7 +167,7 @@ class AnalogSensor:
|
||||
class I2CDevice:
|
||||
"""Generic or custom I2C device."""
|
||||
|
||||
def __init__(self, port: Port, address: int):
|
||||
def __init__(self, port: _Port, address: int):
|
||||
"""I2CDevice(port, address)
|
||||
|
||||
Arguments:
|
||||
@@ -205,7 +205,7 @@ class I2CDevice:
|
||||
class UARTDevice:
|
||||
"""Generic UART device."""
|
||||
|
||||
def __init__(self, port: Port, baudrate: int, timeout: Optional[int] = None):
|
||||
def __init__(self, port: _Port, baudrate: int, timeout: Optional[int] = None):
|
||||
"""UARTDevice(port, baudrate, timeout=None)
|
||||
|
||||
Arguments:
|
||||
|
||||
+60
-39
@@ -6,12 +6,33 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import Enum
|
||||
from typing import Union
|
||||
from typing import Union, TYPE_CHECKING
|
||||
import os
|
||||
|
||||
from .geometry import Matrix as _Matrix
|
||||
|
||||
from .geometry import Matrix
|
||||
if TYPE_CHECKING or os.environ["SPHINX_BUILD"] == "True":
|
||||
Number = Union[int, float]
|
||||
"""
|
||||
Numbers can be represented as integers or floating point values:
|
||||
|
||||
Number = Union[int, float]
|
||||
* Integers (:class:`int <ubuiltins.int>`) are whole numbers
|
||||
like ``15`` or ``-123``.
|
||||
* Floating point values (:class:`float <ubuiltins.float>`) are decimal
|
||||
numbers like ``3.14`` or ``-123.45``.
|
||||
|
||||
If you see :class:`Number` as the argument type, both
|
||||
:class:`int <ubuiltins.int>` and :class:`float <ubuiltins.float>` may be used.
|
||||
|
||||
For example, :func:`wait(15) <pybricks.tools.wait>` and
|
||||
:func:`wait(15.75) <pybricks.tools.wait>` are both allowed. In most functions,
|
||||
however, your input value will be truncated to a whole number anyway. In this
|
||||
example, either command makes the program pause for just 15 milliseconds.
|
||||
|
||||
.. warning::
|
||||
The BOOST Move hub doesn't support floating point numbers due to
|
||||
limited system resources, so only integers can be used on that hub.
|
||||
"""
|
||||
|
||||
|
||||
class _PybricksEnumMeta(type(Enum)):
|
||||
@@ -163,39 +184,39 @@ class Side(_PybricksEnum):
|
||||
|
||||
|
||||
class Icon:
|
||||
UP: Matrix
|
||||
DOWN: Matrix
|
||||
LEFT: Matrix
|
||||
RIGHT: Matrix
|
||||
ARROW_RIGHT_UP: Matrix
|
||||
ARROW_RIGHT_DOWN: Matrix
|
||||
ARROW_LEFT_UP: Matrix
|
||||
ARROW_LEFT_DOWN: Matrix
|
||||
ARROW_UP: Matrix
|
||||
ARROW_DOWN: Matrix
|
||||
ARROW_LEFT: Matrix
|
||||
ARROW_RIGHT: Matrix
|
||||
HAPPY: Matrix
|
||||
SAD: Matrix
|
||||
EYE_LEFT: Matrix
|
||||
EYE_RIGHT: Matrix
|
||||
EYE_LEFT_BLINK: Matrix
|
||||
EYE_RIGHT_BLINK: Matrix
|
||||
EYE_RIGHT_BROW: Matrix
|
||||
EYE_LEFT_BROW: Matrix
|
||||
EYE_LEFT_BROW_UP: Matrix
|
||||
EYE_RIGHT_BROW_UP: Matrix
|
||||
HEART: Matrix
|
||||
PAUSE: Matrix
|
||||
EMPTY: Matrix
|
||||
FULL: Matrix
|
||||
SQUARE: Matrix
|
||||
TRIANGLE_RIGHT: Matrix
|
||||
TRIANGLE_LEFT: Matrix
|
||||
TRIANGLE_UP: Matrix
|
||||
TRIANGLE_DOWN: Matrix
|
||||
CIRCLE: Matrix
|
||||
CLOCKWISE: Matrix
|
||||
COUNTERCLOCKWISE: Matrix
|
||||
TRUE: Matrix
|
||||
FALSE: Matrix
|
||||
UP: _Matrix
|
||||
DOWN: _Matrix
|
||||
LEFT: _Matrix
|
||||
RIGHT: _Matrix
|
||||
ARROW_RIGHT_UP: _Matrix
|
||||
ARROW_RIGHT_DOWN: _Matrix
|
||||
ARROW_LEFT_UP: _Matrix
|
||||
ARROW_LEFT_DOWN: _Matrix
|
||||
ARROW_UP: _Matrix
|
||||
ARROW_DOWN: _Matrix
|
||||
ARROW_LEFT: _Matrix
|
||||
ARROW_RIGHT: _Matrix
|
||||
HAPPY: _Matrix
|
||||
SAD: _Matrix
|
||||
EYE_LEFT: _Matrix
|
||||
EYE_RIGHT: _Matrix
|
||||
EYE_LEFT_BLINK: _Matrix
|
||||
EYE_RIGHT_BLINK: _Matrix
|
||||
EYE_RIGHT_BROW: _Matrix
|
||||
EYE_LEFT_BROW: _Matrix
|
||||
EYE_LEFT_BROW_UP: _Matrix
|
||||
EYE_RIGHT_BROW_UP: _Matrix
|
||||
HEART: _Matrix
|
||||
PAUSE: _Matrix
|
||||
EMPTY: _Matrix
|
||||
FULL: _Matrix
|
||||
SQUARE: _Matrix
|
||||
TRIANGLE_RIGHT: _Matrix
|
||||
TRIANGLE_LEFT: _Matrix
|
||||
TRIANGLE_UP: _Matrix
|
||||
TRIANGLE_DOWN: _Matrix
|
||||
CIRCLE: _Matrix
|
||||
CLOCKWISE: _Matrix
|
||||
COUNTERCLOCKWISE: _Matrix
|
||||
TRUE: _Matrix
|
||||
FALSE: _Matrix
|
||||
|
||||
+40
-38
@@ -3,25 +3,27 @@
|
||||
|
||||
"""LEGO® Powered Up motor, sensors, and lights."""
|
||||
|
||||
from typing import Collection, Optional, Union, overload, Tuple
|
||||
from __future__ import annotations
|
||||
|
||||
from ._common import (
|
||||
AmbientColorSensor,
|
||||
ColorLight,
|
||||
CommonColorSensor,
|
||||
CommonDCMotor,
|
||||
CommonMotor,
|
||||
Keypad,
|
||||
LightArray,
|
||||
from typing import TYPE_CHECKING, Collection, Optional, Union, overload, Tuple
|
||||
|
||||
from . import _common
|
||||
from .parameters import (
|
||||
Button as _Button,
|
||||
Color as _Color,
|
||||
Direction as _Direction,
|
||||
Port as _Port,
|
||||
)
|
||||
from .parameters import Button, Color, Direction, Port
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .parameters import Number as _Number
|
||||
|
||||
|
||||
class DCMotor(CommonDCMotor):
|
||||
class DCMotor(_common.DCMotor):
|
||||
"""LEGO® Powered Up motor without rotation sensors."""
|
||||
|
||||
|
||||
class Motor(CommonMotor):
|
||||
class Motor(_common.Motor):
|
||||
"""LEGO® Powered Up motor with rotation sensors."""
|
||||
|
||||
def reset_angle(self, angle: Optional[int]) -> None:
|
||||
@@ -40,21 +42,21 @@ class Motor(CommonMotor):
|
||||
class Remote:
|
||||
"""LEGO® Powered Up Bluetooth Remote Control."""
|
||||
|
||||
light = ColorLight()
|
||||
buttons = Keypad(
|
||||
light = _common.ColorLight()
|
||||
buttons = _common.Keypad(
|
||||
(
|
||||
Button.LEFT_MINUS,
|
||||
Button.RIGHT_MINUS,
|
||||
Button.LEFT,
|
||||
Button.CENTER,
|
||||
Button.RIGHT,
|
||||
Button.LEFT_PLUS,
|
||||
Button.RIGHT_PLUS,
|
||||
_Button.LEFT_MINUS,
|
||||
_Button.RIGHT_MINUS,
|
||||
_Button.LEFT,
|
||||
_Button.CENTER,
|
||||
_Button.RIGHT,
|
||||
_Button.LEFT_PLUS,
|
||||
_Button.RIGHT_PLUS,
|
||||
)
|
||||
)
|
||||
addresss: Union[str, None]
|
||||
|
||||
def __init__(self, name: str = None, timeout: int = 10000):
|
||||
def __init__(self, name: Optional[str] = None, timeout: int = 10000):
|
||||
"""Remote(name=None, timeout=10000)
|
||||
|
||||
When you instantiate this class, the hub will search for a remote
|
||||
@@ -92,7 +94,7 @@ class Remote:
|
||||
class TiltSensor:
|
||||
"""LEGO® Powered Up Tilt Sensor."""
|
||||
|
||||
def __init__(self, port: Port):
|
||||
def __init__(self, port: _Port):
|
||||
"""TiltSensor(port)
|
||||
|
||||
Arguments:
|
||||
@@ -109,10 +111,10 @@ class TiltSensor:
|
||||
"""
|
||||
|
||||
|
||||
class ColorDistanceSensor(CommonColorSensor):
|
||||
class ColorDistanceSensor(_common.CommonColorSensor):
|
||||
"""LEGO® Powered Up Color and Distance Sensor."""
|
||||
|
||||
light = ColorLight()
|
||||
light = _common.ColorLight()
|
||||
|
||||
def distance(self) -> int:
|
||||
"""distance() -> int: %
|
||||
@@ -133,8 +135,8 @@ class PFMotor(DCMotor):
|
||||
self,
|
||||
sensor: ColorDistanceSensor,
|
||||
channel: int,
|
||||
color: Color,
|
||||
positive_direction: Direction = Direction.CLOCKWISE,
|
||||
color: _Color,
|
||||
positive_direction: _Direction = _Direction.CLOCKWISE,
|
||||
):
|
||||
"""PFMotor(sensor, channel, color, positive_direction=Direction.CLOCKWISE)
|
||||
|
||||
@@ -152,18 +154,18 @@ class PFMotor(DCMotor):
|
||||
"""
|
||||
|
||||
|
||||
class ColorSensor(AmbientColorSensor):
|
||||
class ColorSensor(_common.AmbientColorSensor):
|
||||
"""LEGO® SPIKE Color Sensor."""
|
||||
|
||||
lights = LightArray(3)
|
||||
lights = _common.LightArray(3)
|
||||
|
||||
|
||||
class UltrasonicSensor:
|
||||
"""LEGO® SPIKE Color Sensor."""
|
||||
|
||||
lights = LightArray(3)
|
||||
lights = _common.LightArray(3)
|
||||
|
||||
def __init__(self, port: Port):
|
||||
def __init__(self, port: _Port):
|
||||
"""UltrasonicSensor(port)
|
||||
|
||||
Arguments:
|
||||
@@ -197,7 +199,7 @@ class UltrasonicSensor:
|
||||
class ForceSensor:
|
||||
"""LEGO® SPIKE Force Sensor."""
|
||||
|
||||
def __init__(self, port: Port):
|
||||
def __init__(self, port: _Port):
|
||||
"""ForceSensor(port)
|
||||
|
||||
Arguments:
|
||||
@@ -222,7 +224,7 @@ class ForceSensor:
|
||||
Movement up to approximately 8.00 mm.
|
||||
"""
|
||||
|
||||
def pressed(self, force=3) -> bool:
|
||||
def pressed(self, force: _Number = 3) -> bool:
|
||||
"""pressed(force=3) -> bool
|
||||
|
||||
Checks if the sensor button is pressed.
|
||||
@@ -253,7 +255,7 @@ class ColorLightMatrix:
|
||||
LEGO® SPIKE 3x3 Color Light Matrix.
|
||||
"""
|
||||
|
||||
def __init__(self, port: Port):
|
||||
def __init__(self, port: _Port):
|
||||
"""ColorLightMatrix(port)
|
||||
|
||||
Arguments:
|
||||
@@ -262,7 +264,7 @@ class ColorLightMatrix:
|
||||
"""
|
||||
...
|
||||
|
||||
def on(self, color: Union[Color, Collection[Color]]) -> None:
|
||||
def on(self, color: Union[_Color, Collection[_Color]]) -> None:
|
||||
"""on(colors)
|
||||
|
||||
Turns the lights on.
|
||||
@@ -286,7 +288,7 @@ class ColorLightMatrix:
|
||||
class InfraredSensor:
|
||||
"""LEGO® Powered Up Infrared Sensor."""
|
||||
|
||||
def __init__(self, port: Port):
|
||||
def __init__(self, port: _Port):
|
||||
"""InfraredSensor(port)
|
||||
|
||||
Arguments:
|
||||
@@ -326,14 +328,14 @@ class InfraredSensor:
|
||||
class Light:
|
||||
"""LEGO® Powered Up Light."""
|
||||
|
||||
def __init__(self, port: Port):
|
||||
def __init__(self, port: _Port):
|
||||
"""Light(port)
|
||||
|
||||
Arguments:
|
||||
port (Port): Port to which the device is connected.
|
||||
"""
|
||||
|
||||
def on(self, brightness: int = 100) -> None:
|
||||
def on(self, brightness: _Number = 100) -> None:
|
||||
"""on(brightness=100)
|
||||
|
||||
Turns on the light at the specified brightness.
|
||||
|
||||
+24
-17
@@ -3,10 +3,15 @@
|
||||
|
||||
"""Robotics module for the Pybricks API."""
|
||||
|
||||
from typing import Tuple, Optional, overload
|
||||
from __future__ import annotations
|
||||
|
||||
from ._common import Control, CommonMotor as Motor
|
||||
from .parameters import Stop, Number
|
||||
from typing import Tuple, Optional, overload, TYPE_CHECKING
|
||||
|
||||
from . import _common
|
||||
from .parameters import Stop as _Stop
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .parameters import Number as _Number
|
||||
|
||||
|
||||
class DriveBase:
|
||||
@@ -26,7 +31,7 @@ class DriveBase:
|
||||
|
||||
"""
|
||||
|
||||
distance_control = Control()
|
||||
distance_control = _common.Control()
|
||||
"""The traveled distance and drive speed are controlled by a PID
|
||||
controller. You can use this attribute to change its settings.
|
||||
See the :ref:`motor control <settings>` attribute for an overview of
|
||||
@@ -34,7 +39,7 @@ class DriveBase:
|
||||
functionality, but the settings apply to every millimeter driven by the
|
||||
drive base, instead of degrees turned by one motor."""
|
||||
|
||||
heading_control = Control()
|
||||
heading_control = _common.Control()
|
||||
"""The robot turn angle and turn rate are controlled by a PID
|
||||
controller. You can use this attribute to change its settings.
|
||||
See the :ref:`motor control <settings>` attribute for an overview of
|
||||
@@ -45,10 +50,10 @@ class DriveBase:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
left_motor: Motor,
|
||||
right_motor: Motor,
|
||||
wheel_diameter: Number,
|
||||
axle_track: Number,
|
||||
left_motor: _common.Motor,
|
||||
right_motor: _common.Motor,
|
||||
wheel_diameter: _Number,
|
||||
axle_track: _Number,
|
||||
):
|
||||
"""DriveBase(left_motor, right_motor, wheel_diameter, axle_track)
|
||||
|
||||
@@ -62,7 +67,7 @@ class DriveBase:
|
||||
both wheels touch the ground.
|
||||
"""
|
||||
|
||||
def drive(self, speed: Number, turn_rate: Number) -> None:
|
||||
def drive(self, speed: _Number, turn_rate: _Number) -> None:
|
||||
"""drive(speed, turn_rate)
|
||||
|
||||
Starts driving at the specified speed and turn rate. Both values are
|
||||
@@ -113,10 +118,10 @@ class DriveBase:
|
||||
@overload
|
||||
def settings(
|
||||
self,
|
||||
straight_speed: Optional[Number],
|
||||
straight_acceleration: Optional[Number],
|
||||
turn_rate: Optional[Number],
|
||||
turn_acceleration: Optional[Number],
|
||||
straight_speed: Optional[_Number],
|
||||
straight_acceleration: Optional[_Number],
|
||||
turn_rate: Optional[_Number],
|
||||
turn_acceleration: Optional[_Number],
|
||||
) -> None:
|
||||
...
|
||||
|
||||
@@ -142,7 +147,7 @@ class DriveBase:
|
||||
deceleration of the robot.
|
||||
"""
|
||||
|
||||
def straight(self, distance, then=Stop.HOLD, wait=True) -> None:
|
||||
def straight(self, distance: _Number, then=_Stop.HOLD, wait=True) -> None:
|
||||
"""straight(distance, then=Stop.HOLD, wait=True)
|
||||
|
||||
Drives straight for a given distance and then stops.
|
||||
@@ -154,7 +159,7 @@ class DriveBase:
|
||||
with the rest of the program.
|
||||
"""
|
||||
|
||||
def turn(self, angle, then=Stop.HOLD, wait=True) -> None:
|
||||
def turn(self, angle: _Number, then=_Stop.HOLD, wait=True) -> None:
|
||||
"""turn(angle, then=Stop.HOLD, wait=True)
|
||||
|
||||
Turns in place by a given angle and then stops.
|
||||
@@ -166,7 +171,9 @@ class DriveBase:
|
||||
with the rest of the program.
|
||||
"""
|
||||
|
||||
def curve(self, radius, angle, then=Stop.HOLD, wait=True) -> None:
|
||||
def curve(
|
||||
self, radius: _Number, angle: _Number, then=_Stop.HOLD, wait=True
|
||||
) -> None:
|
||||
"""curve(radius, angle, then=Stop.HOLD, wait=True)
|
||||
|
||||
Drives an arc along a circle of a given radius, by a given angle.
|
||||
|
||||
@@ -25,14 +25,6 @@ This module implements pseudo-random number generators.
|
||||
from typing import Any, Optional, Sequence, overload
|
||||
|
||||
|
||||
[
|
||||
"random",
|
||||
"uniform",
|
||||
]
|
||||
|
||||
# bookkeeping
|
||||
|
||||
|
||||
def seed(a: Optional[int] = None) -> None:
|
||||
"""
|
||||
Initialize the random number generator.
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
This module provides a subset of the standard Python ``sys`` module.
|
||||
"""
|
||||
|
||||
from uio import FileIO
|
||||
from uio import FileIO as _FileIO
|
||||
|
||||
# REVISIT: most functions are excluded since they aren't useful for Pybricks
|
||||
|
||||
stdin: FileIO = FileIO()
|
||||
stdin: _FileIO = _FileIO()
|
||||
"""
|
||||
Stream object (:class:`uio.FileIO`) that receives input from a connected
|
||||
terminal, if any.
|
||||
@@ -25,7 +25,7 @@ Also see :func:`micropython.kbd_intr` to disable ``KeyboardInterrupt`` if you
|
||||
are passing binary data via ``stdin``.
|
||||
"""
|
||||
|
||||
stdout: FileIO = FileIO()
|
||||
stdout: _FileIO = _FileIO()
|
||||
"""
|
||||
Stream object (:class:`uio.FileIO`) that sends output to a connected terminal,
|
||||
if any.
|
||||
@@ -34,7 +34,7 @@ Reading may modify newline characters. Use ``usys.stdout.buffer`` instead if
|
||||
this is undesirable.
|
||||
"""
|
||||
|
||||
stderr: FileIO = FileIO()
|
||||
stderr: _FileIO = _FileIO()
|
||||
"""
|
||||
Alias for :data:`stdout`.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user