From a80d5cf91e0ddae98583f1d42efe855aa8e9bfca Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Mon, 30 May 2022 09:46:00 +0200 Subject: [PATCH] pybricks.common.Accelerometer: Add typing. Also remove tapped and shaken, which are not implemented. --- src/pybricks/_common.py | 78 ++++++++++++++-------------------------- src/pybricks/_common.pyi | 15 -------- 2 files changed, 27 insertions(+), 66 deletions(-) diff --git a/src/pybricks/_common.py b/src/pybricks/_common.py index b81b6f7..6035fbf 100644 --- a/src/pybricks/_common.py +++ b/src/pybricks/_common.py @@ -6,7 +6,7 @@ speakers, and batteries.""" from .parameters import Direction, Stop, Button, Port, Color, Side -from .geometry import Matrix +from .geometry import Matrix, Axis from typing import Union, Iterable, overload, Optional, Tuple, Collection @@ -868,22 +868,24 @@ class Charger: class SimpleAccelerometer: """Get measurements from an accelerometer.""" - def acceleration(self): - """Gets the acceleration of the device. + def acceleration(self) -> Tuple[int, int, int]: + """acceleration() -> Tuple[int, int, int]: mm/s/s + + Gets the acceleration of the device. Returns: Acceleration along all three axes. """ pass - def up(self): - """Checks which side of the hub currently faces upward. + def up(self) -> Side: + """up() -> Side - :returns: + Checks which side of the hub currently faces upward. + + Returns: ``Side.TOP``, ``Side.BOTTOM``, ``Side.LEFT``, ``Side.RIGHT``, ``Side.FRONT`` or ``Side.BACK``. - :rtype: :class:`Side` - """ pass @@ -891,30 +893,25 @@ class SimpleAccelerometer: class Accelerometer(SimpleAccelerometer): """Get measurements from an accelerometer.""" - def neutral(self, top, front): - """Configures the neutral orientation of the device or hub. You do this - by specifying how it is mounted on your design, in terms of the - :ref:`robot reference frame `. + @overload + def acceleration(self) -> Matrix: + ... - In this given neutral orientation, the tilt and heading will then be - zero. + @overload + def acceleration(self, axis: Axis) -> float: + ... - Arguments: - top (Axis): Which direction the top of the device faces in the - neutral orientation. For example, you can - choose ``top=-Axis.Z`` if you mounted it such that the - neutral orientation is upside down. - front (Axis): Which direction the front of the device faces in the - neutral orientation. + def acceleration(self, *args): """ - pass + acceleration(axis) -> float: mm/s/s + acceleration() -> vector: mm/s/s - def acceleration(self, axis=None): - """Gets the acceleration of the device along a given axis in the + + Gets the acceleration of the device along a given axis in the :ref:`robot reference frame `. Arguments: - axis (Axis): Axis along which the acceleration is + axis (Axis): Axis along which the acceleration should be measured. Returns: Acceleration along the specified axis. If you specify no axis, @@ -922,8 +919,10 @@ class Accelerometer(SimpleAccelerometer): """ pass - def tilt(self): - """Gets the pitch and roll angles. This is relative to the + def tilt(self) -> Tuple[int, int]: + """tilt() -> Tuple[int, int] + + Gets the pitch and roll angles. This is relative to the :ref:`user-specified neutral orientation `. The order of rotation is pitch-then-roll. This is equivalent to a @@ -931,30 +930,7 @@ class Accelerometer(SimpleAccelerometer): along the x-axis. Returns: - (:ref:`angle`, :ref:`angle`): Pitch and roll angles. - - """ - pass - - def tapped(self): - """Checks if the device or hub was tapped. - - Returns: - bool: - ``True`` if tapped since this method was last called. ``False`` - otherwise. - - """ - pass - - def shaken(self): - """Checks if the device or hub was shaken. - - Returns: - bool: - ``True`` if shaken since this method was last called. ``False`` - otherwise. - + Tuple of pitch and roll angles. """ pass diff --git a/src/pybricks/_common.pyi b/src/pybricks/_common.pyi index f87a73a..fd0037f 100644 --- a/src/pybricks/_common.pyi +++ b/src/pybricks/_common.pyi @@ -6,21 +6,6 @@ from typing import Collection, Iterable, Optional, Tuple, Union, overload from .geometry import Axis, Matrix, vector from .parameters import Button, Color, Direction, Side, Stop, Port -class SimpleAccelerometer: - def acceleration(self) -> Tuple[int, int, int]: ... - def up(self) -> Side: ... - -class Accelerometer: - def neutral(self, top: Axis, front: Axis) -> None: ... - @overload - def acceleration(self) -> vector[float, float, float]: ... - @overload - def acceleration(self, axis: Axis) -> int: ... - def tilt(self) -> Tuple[int, int]: ... - def tapped(self) -> bool: ... - def shaken(self) -> bool: ... - def up(self) -> Side: ... - class IMU(Accelerometer): def heading(self) -> int: ... def reset_heading(self, angle): ...