This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

readRotationAngle

Read rotation angle from gyroscopic sensor

Syntax

angle = readRotationAngle(mygyrosensor)

Description

example

angle = readRotationAngle(mygyrosensor) reads the total amount of rotation since the creation of the connection to the sensor, and returns the measurement in degrees. You can use the resetRotationAngle function to reset this value to zero.

Examples

collapse all

Measure angle of rotation using 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)

Input Arguments

collapse all

Connection to gyroscopic sensor, specified as a string that represents the object created using gyroSensor.

Example: mygyrosensor

Data Types: double

Output Arguments

collapse all

Angle of rotation in degrees, returned as an int32 value. With the sensor upright, positive values indicate clockwise rotation. Negative values indicate counterclockwise rotation.