readRotation

Read rotation from motor

Description

example

rotation = readRotation(mymotor) reads the total amount of rotation since the creation of the connection to the motor, and returns the measurement in degrees. You can use the resetRotation function to reset this value to zero.

Examples

collapse all

Control a motor, measure the wheel rotation of the motor in degrees, and clear the measurement.

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 a motor. Specify the letter of the EV3 output port that connects to the motor.

mymotor = motor(myev3,'A')
mymotor = 

  motor with properties:

    OutputPort: 'A'
         Speed: 0

By default, the speed is zero.

Configure the motor to reverse at half speed.

mymotor.Speed = -50
mymotor = 

  motor with properties:

    OutputPort: 'A'
         Speed: -50

Start the motor.

start(mymotor)

Read the rotation value, in degrees, of the motor.

rotation = readRotation(mymotor)
ans =

       -1489

Reset the rotation value of the motor to zero.

resetRotation(mymotor)

Input Arguments

collapse all

Connection to a motor, specified as a string that represents the object created using motor.

Example: mymotor

Data Types: char

Output Arguments

collapse all

Rotation of motor in degrees, returned as an int32 value. Creating a connection to a motor initializes this value to zero. To reset this value to zero, use resetRotation.