Skip to content

brian.sensors.EV3.GyroSensorEV3

brian.sensors.EV3

GyroSensorEV3 class objects

class GyroSensorEV3(Sensor)

Class for interacting with EV3 gyro sensor.

Sensor is automatically registered in the constructor of the base class and un-registered in its destructor. It can also be unregistered with the GyroSensorEV3.close_sensor() function.

There can be at most one instance at any given time, of any sensor class per port in the entire program.

__init__

def __init__(port: SensorPort)

Initialize a EV3 gyro sensor at the given port.

Arguments:

  • port: Sensor port to which the sensor is attached.

Mode class objects

class Mode(Enum)

ANGLE

SPEED

SPEED_COARSE

ANGLE_AND_SPEED

TILT_SPEED

TILT_ANGLE

set_mode

def set_mode(mode: Mode) -> None

This function sets the sensor to the desired mode. While it’s not mandatory, it is recommended to call this

function before accessing values from the sensor in a specific mode to prevent SensorIsNotReady exceptions.

Arguments:

  • mode: desired mode to be set

angle

def angle() -> int

Sets the sensor mode to ANGLE and returns the last value.

Raises:

  • brian.sensors.SensorIsNotReadyError: If the sensor is not ready. ANGLE mode: Measures the tilt angle and returns the value in degrees in range -32768 to 32767.

Clockwise is positive when looking at the side of the sensor with the arrows.

If you spin around too many times in ANGLE,ANGLE_AND_SPEED or TILT_ANGLE mode, it will get stuck at 32767 or overflow through -32768 depending on when the sensor was manufactured.

Returns:

angle (int) in degrees (-32768 to 32768).

speed

def speed() -> int

Sets the sensor mode to SPEED and returns the last value.

Raises:

  • brian.sensors.SensorIsNotReadyError: If the sensor is not ready. SPEED mode: Measures angular speed and returns the value in degrees/second in range -500 to 500.

Clockwise is positive when looking at the side of the sensor with the arrows.

Returns:

angular speed in degrees/s (-500 to 500).

tilt_speed

def tilt_speed() -> int

Sets the sensor mode to Modes::TILT_SPEED and returns the last value.

Raises:

  • brian.sensors.SensorIsNotReadyError: If the sensor is not ready. TILT_SPEED mode: Measures angular speed around a second axis and returns the value in degrees/second in range -500 to 500 Clockwise is positive when looking at the side of the sensor opposite the cable jack.

Returns:

angular speed in degrees/s (-500 to 500).

tilt_angle

def tilt_angle() -> int

Sets the sensor mode to TILT_ANGLE and returns the last value.

Raises:

  • brian.sensors.SensorIsNotReadyError: If the sensor is not ready. TILT_ANGLE mode: Measures the tilt angle around a second axis and returns the value in degrees in range -32768 to 32767.

This mode is not present in older sensors (date code ending with 2 or 3). Clockwise is positive when looking at the side of the sensor opposite the cable jack.

If you spin around too many times in "ANGLE", "ANGLE_AND_SPEED" or "TILT_ANGLE" mode, it will get stuck at 32767 or overflow through -32768 depending on when the sensor was manufactured.

Returns:

angle (int) in degrees (-32768 to 32768).

coarse_speed

def coarse_speed() -> int

Sets the sensor mode to SPEED_COARSE and returns the last value.

Raises:

  • brian.sensors.SensorIsNotReadyError: If the sensor is not ready. SPEED_COARSE mode: Measures angular speed and returns the value in degrees/second in range -1464 to 1535. Lower resolution, but wider range than the "SPEED" mode.

Clockwise is positive when looking at the side of the sensor with the arrows.

Returns:

angular speed in degrees/s (-1464 to 1535).

angle_and_speed

def angle_and_speed() -> Tuple[int, int]

Sets the sensor mode to ANGLE_AND_SPEED and returns the last value.

Raises:

  • brian.sensors.SensorIsNotReadyError: If the sensor is not ready. ANGLE_AND_SPEED mode: Measures the tilt angle and angular speed and returns the value in degrees in range -32768 to 32767 for angle and -500 to 500 for speed.

Clockwise is positive when looking at the side of the sensor with the arrows. If you spin around too many times in "ANGLE", "ANGLE_AND_SPEED" or "TILT_ANGLE" mode, it will get stuck at 32767 or overflow through -32768 depending on when the sensor was manufactured.

Returns:

Tuple consisting of two integers: - The first integer represents the angle (deg) measurement. - The second integer represents the speed (deg/s) measurement.

set_zero_point

def set_zero_point() -> None

Adjusts the angle readings to create new zero point angle.

Adjusts angle only in "ANGLE", "ANGLE_AND_SPEED" and "TILT_ANGLE" modes. Does not fix drift (for drift fixing, reboot the sensor using the reboot() function).

Raises:

  • brian.sensors.SensorIsNotReadyError: If the sensor is not ready.

reboot

def reboot() -> None

Reboots the sensor to force recalibration.

During the recalibration, keep the sensor steady to minimize drifting.

Reboot Turn off power to the port and turn it back on. This will forcibly reboot the sensor.

The powered-down state lasts about 100ms. In case of some (mostly digital) sensors, there can be some additional time (~1s or more) to boot up and process connection handshake with Brian.