Hauptinhalt

readPosition

R2026b

Read servo motor position

Description

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

position = readPosition(s) reads the position of the motor shaft and returns the value of the position in ratio to the maximum angle of the specified servomotor.

example

Examples

collapse all

Create servo object.

a = arduino('COM4','Uno','Libraries','Servo');
s = servo(a,'D4');

Read the position of the servo.

position = readPosition(s)
position = 
0.5200

Input Arguments

collapse all

Servo object connected to Arduino® hardware specified as an object.

Output Arguments

collapse all

Position of the servo motor specified as a number representing the angle from 0 to 1.

Alternative Functionality

App

Use the Arduino Explorer to interactively configure servo motors and read the shaft position of the servo motor connected to Arduino or any other supported hardware in MATLAB® and MATLAB Online™.

Version History

Introduced in R2014b