From 28ecc060b72091472e9803ec8e3883c6d05e8077 Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Fri, 7 Apr 2023 20:28:33 +0200 Subject: [PATCH] pybricks._common.IMU: Change settings setter. --- CHANGELOG.md | 2 +- doc/main/hubs/essentialhub.rst | 4 +-- doc/main/hubs/primehub.rst | 4 +-- doc/main/hubs/technichub.rst | 4 +-- jedi/tests/test_complete_essential_hub.py | 2 +- jedi/tests/test_complete_prime_hub.py | 2 +- jedi/tests/test_complete_technic_hub.py | 2 +- src/pybricks/_common.py | 41 ++++++++++++++++------- 8 files changed, 38 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 805a30d..dad9546 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ - Documented ``Motor.model``. This can be used to view the estimated motor state and change its settings. - Added `rotation`, `orientation`, `ready`, `stationary` - and `set_stationary_thresholds` methods to `IMU` class. + and `settings` methods to `IMU` class. ### Changed - Change implementation status of `IMU.heading` and `IMU.reset_heading`. They diff --git a/doc/main/hubs/essentialhub.rst b/doc/main/hubs/essentialhub.rst index 9f27ccc..a24ac1d 100644 --- a/doc/main/hubs/essentialhub.rst +++ b/doc/main/hubs/essentialhub.rst @@ -29,8 +29,6 @@ Essential Hub .. automethod:: pybricks.hubs::EssentialHub.imu.stationary - .. automethod:: pybricks.hubs::EssentialHub.imu.set_stationary_thresholds - .. automethod:: pybricks.hubs::EssentialHub.imu.up .. automethod:: pybricks.hubs::EssentialHub.imu.tilt @@ -47,6 +45,8 @@ Essential Hub .. automethod:: pybricks.hubs::EssentialHub.imu.orientation + .. automethod:: pybricks.hubs::EssentialHub.imu.settings + .. rubric:: Using the battery .. automethod:: pybricks.hubs::EssentialHub.battery.voltage diff --git a/doc/main/hubs/primehub.rst b/doc/main/hubs/primehub.rst index 3787b0d..1390f9a 100644 --- a/doc/main/hubs/primehub.rst +++ b/doc/main/hubs/primehub.rst @@ -63,8 +63,6 @@ Prime Hub / Inventor Hub .. automethod:: pybricks.hubs::PrimeHub.imu.stationary - .. automethod:: pybricks.hubs::PrimeHub.imu.set_stationary_thresholds - .. automethod:: pybricks.hubs::PrimeHub.imu.up .. automethod:: pybricks.hubs::PrimeHub.imu.tilt @@ -81,6 +79,8 @@ Prime Hub / Inventor Hub .. automethod:: pybricks.hubs::PrimeHub.imu.orientation + .. automethod:: pybricks.hubs::PrimeHub.imu.settings + .. rubric:: Using the speaker .. automethod:: pybricks.hubs::PrimeHub.speaker.volume diff --git a/doc/main/hubs/technichub.rst b/doc/main/hubs/technichub.rst index 91baf1a..ab6c115 100644 --- a/doc/main/hubs/technichub.rst +++ b/doc/main/hubs/technichub.rst @@ -25,8 +25,6 @@ Technic Hub .. automethod:: pybricks.hubs::TechnicHub.imu.stationary - .. automethod:: pybricks.hubs::TechnicHub.imu.set_stationary_thresholds - .. automethod:: pybricks.hubs::TechnicHub.imu.up .. automethod:: pybricks.hubs::TechnicHub.imu.tilt @@ -43,6 +41,8 @@ Technic Hub .. automethod:: pybricks.hubs::TechnicHub.imu.orientation + .. automethod:: pybricks.hubs::TechnicHub.imu.settings + .. rubric:: Using the battery .. automethod:: pybricks.hubs::TechnicHub.battery.voltage diff --git a/jedi/tests/test_complete_essential_hub.py b/jedi/tests/test_complete_essential_hub.py index 8fc2d11..37d9d9d 100644 --- a/jedi/tests/test_complete_essential_hub.py +++ b/jedi/tests/test_complete_essential_hub.py @@ -83,7 +83,7 @@ def test_hub_dot_imu_dot(): "ready", "reset_heading", "rotation", - "set_stationary_thresholds", + "settings", "stationary", "tilt", "up", diff --git a/jedi/tests/test_complete_prime_hub.py b/jedi/tests/test_complete_prime_hub.py index 2075cd9..7f76064 100644 --- a/jedi/tests/test_complete_prime_hub.py +++ b/jedi/tests/test_complete_prime_hub.py @@ -101,7 +101,7 @@ def test_hub_dot_imu_dot(): "ready", "reset_heading", "rotation", - "set_stationary_thresholds", + "settings", "stationary", "tilt", "up", diff --git a/jedi/tests/test_complete_technic_hub.py b/jedi/tests/test_complete_technic_hub.py index dc58388..2eb03ef 100644 --- a/jedi/tests/test_complete_technic_hub.py +++ b/jedi/tests/test_complete_technic_hub.py @@ -71,7 +71,7 @@ def test_hub_dot_imu_dot(): "ready", "reset_heading", "rotation", - "set_stationary_thresholds", + "settings", "stationary", "tilt", "up", diff --git a/src/pybricks/_common.py b/src/pybricks/_common.py index bcd5852..cf1cad0 100644 --- a/src/pybricks/_common.py +++ b/src/pybricks/_common.py @@ -1012,27 +1012,42 @@ class IMU(Accelerometer): moving. """ - def set_stationary_thresholds( - self, angular_velocity: float, acceleration: float + @overload + def settings( + self, + angular_velocity_threshold: float = None, + acceleration_threshold: float = None, ) -> None: - """set_stationary_thresholds(angular_velocity, acceleration) + ... - When the angular velocity and acceleration measurements are below the - given threshold values for at least one second, the sensor is - considered stationary. This is when the sensor recalibrates itself. + @overload + def settings(self) -> Tuple[float, float]: + ... - If you are in a noisy room with high ambient vibrations (such as a - robot competition hall), it is recommended to increase these values - slightly to give your robot the chance to calibrate properly. + def settings(self, *args): + """ + settings(angular_velocity_threshold, acceleration_threshold) + settings() -> Tuple[float, float] - To verify that your settings are working, test that + Configures the IMU settings. If no arguments are given, + this returns the current values. + + The ``angular_velocity_threshold`` and ``acceleration_threshold`` + define when the hub is considered stationary. If all + measurements stay below these thresholds for one second, the IMU + will recalibrate itself. + + In a noisy room with high ambient vibrations (such as a + competition hall), it is recommended to increase the thresholds + slightly to give your robot the chance to calibrate. + To verify that your settings are working as expected, test that the ``stationary()`` method gives ``False`` if your robot is moving, and ``True`` if it is sitting still for at least a second. Arguments: - angular_velocity (Number, deg/s): The threshold for angular - velocity. The default value is 1.5 deg/s. - acceleration (Number, mm/s²): The threshold for angular + angular_velocity_threshold (Number, deg/s): The threshold for + angular velocity. The default value is 1.5 deg/s. + acceleration_threshold (Number, mm/s²): The threshold for angular velocity. The default value is 250 mm/s². """