gyroSensor

Connection to gyroscopic sensor

Description

This object represents a connection to a single-axis EV3 Gyro Sensor (item number 45505). To measure total rotation or rate of rotation, use this object with the functions listed in Object Functions.

Creation

Syntax

mygyrosensor = gyroSensor(myev3)
mygyrosensor = gyroSensor(myev3,inputport)

Description

example

mygyrosensor = gyroSensor(myev3) creates a connection to a gyroscopic sensor. You can use this connection with the functions listed in Object Functions to measure the rotation rate or rotation angle of the sensor, and reset the rotation rate measurement to zero.

If multiple gyroscopic sensors are attached to the EV3 brick, this function chooses the sensor that is attached to the EV3 input port with the lowest number.

example

mygyrosensor = gyroSensor(myev3,inputport) creates a connection to a gyroscopic sensor that uses a specific EV3 input port by the InputPort property.

Input Arguments

expand all

Connection to EV3 brick, specified as a string that represents the object created using legoev3.

Example: myev3

Data Types: char

Output Arguments

expand all

Connection to gyroscopic sensor, returned as an object handle.

Properties

expand all

This property is read-only.

Number of the EV3 input port that the sensor uses, returned as a double.

Example: 1

Data Types: double

Object Functions

readRotationAngleRead rotation angle from gyroscopic sensor
readRotationRateRead rotation rate from gyroscopic sensor
resetRotationAngleReset rotation angle to zero

Examples

collapse all

Get rotation measurements from a gyroscopic sensor.

Create a connection to the EV3 brick called myev3.

myev3 = legoev3
myev3 = 

  legoev3 with properties:

      FirmwareVersion: 'V1.03E'
           HardwareID: []
            IPAddress: []
    CommunicationType: 'USB'
         BatteryLevel: 100
     ConnectedSensors: {'touch'  'gyro'  'color'  'sonic'}

The sensor appears in the list of connected sensors.

Create a connection to the gyroscopic sensor called mygyrosensor.

mygyrosensor = gyroSensor(myev3)
mygyrosensor = 

  gyroSensor with properties:

    InputPort: 2

Measure the rotation, in degrees, since the creation of the connection to the sensor.

angle = readRotationAngle(mygyrosensor)
ans =

           59

The sensor has rotated 59 degrees clockwise.

Reset the measurement to zero.

resetRotationAngle(mygyrosensor)

Measure the current rate of rotation, in degrees per second.

rate = readRotationRate(mygyrosensor)
ans =

           12