Main Content

readSpeed

Read current rotational speed of motor from rotary encoder

Since R2020a

Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.

Description

[speed] = readSpeed(encoder) returns the current rotational speed measured by the rotary encoder in revolutions per minute (RPM).

example

[speed,timestamp] = readSpeed(encoder) returns the current rotational speed measured by the rotary encoder in revolutions per minute (RPM) and timestamp in datetime format.

example

Examples

collapse all

Create a connection to the Nano Motor Carrier.

arduinoObj = arduino('/dev/ttyACM0','Nano33IoT','Libraries','MotorCarrier');
mcObj = motorCarrier(arduinoObj);

Create a connection to the rotary encoder.

encoder = rotaryEncoder(mcObj,1);

Read the current rotational speed.

speed = readSpeed(encoder);

Create a connection to the Nano Motor Carrier.

arduinoObj = arduino('/dev/ttyACM0','Nano33IoT','Libraries','MotorCarrier');
mcObj = motorCarrier(arduinoObj);

Create a connection to the rotary encoder.

encoder = rotaryEncoder(mcObj,1);

Read the current rotational speed.

[speed,timestamp] = readSpeed(encoder);

Input Arguments

collapse all

Connection to the rotary encoder on MKR Motor Carrier or Nano Motor Carrier, specified as an object.

Output Arguments

collapse all

Current rotational speed as measured by the rotary encoder in revolutions per minute (RPM).

Data Types: double

Time at which MATLAB® reads the speed data from the board.

Data Types: datetime

Version History

Introduced in R2020a