gyroSensor

Create connection to gyroscopic sensor

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.

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

Input Arguments

collapse all

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

Example: myev3

Data Types: char

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

Example: 1

Data Types: double

Output Arguments

collapse all

Connection to gyroscopic sensor, returned as an object handle.