From d273a5fea957fa7dfecccdf2e17724b5dcd16fe0 Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Tue, 29 Jan 2019 11:38:56 +0100 Subject: [PATCH] bricks/ev3dev: make gyro api same as motor and add calibrate and reset_angle methods speed, angle, reset_angle and direction are now the same as in a motor --- pybricks/ev3devices.py | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/pybricks/ev3devices.py b/pybricks/ev3devices.py index 5ce84dd..0fb4476 100644 --- a/pybricks/ev3devices.py +++ b/pybricks/ev3devices.py @@ -417,38 +417,49 @@ class GyroSensor(): """ def __init__(self, port): - """GyroSensor(port) + """GyroSensor(port, direction=Direction.clockwise) Arguments: port (Port): Port to which the sensor is connected. + direction (Direction): Positive rotation direction when looking at the red dot on top of the sensor. (*Default*: Direction.clockwise). """ pass - def reset(self): - """Force sensor to reset as if disconnecting and reconnecting it. - - This can take up to 3 seconds. - """ - pass - - def rate(self): - """Measure the angular velocity of the sensor. + def speed(self): + """Get the speed (angular velocity) of the sensor. Returns: - :ref:`speed`: Angular velocity (degrees per second). + :ref:`speed`: Sensor angular velocity. """ - return self.value(1) + pass def angle(self): """Get the accumulated angle of the sensor. Returns: - :ref:`angle`: Rotation angle (degrees) since initialization or last reset. + :ref:`angle`: Rotation angle. """ - return self.value(0) + pass + + def reset_angle(self, angle=0): + """Set the rotation angle of the sensor to a desired value. + + Arguments: + angle (:ref:`angle`): Value to which the angle should be reset (*Default*: 0). + """ + pass + + def calibrate(self): + """Calibrate the sensor. This process sets the speed and angle to zero and ensures that the angle value does not drift. + + Make sure that the sensor does not move while calibrating. + + This process can take up to 15 seconds. + """ + pass class UltrasonicSensor():