Main Content

writePosition

Write position of servo motor connected to MKR Motor Carrier or Nano Motor Carrier

Since R2020a

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

Description

example

writePosition(servoObj,position) sets the servo motor position to the specified value.

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 servo motor 1.

servoObj = servo(mcObj,1)
servoObj = 
  Servo with properties:

    MotorNumber: 1 (Servo1)

Rotate the motor shaft to 90 degrees or pi/2 radians.

writePosition(servoObj,0.5);

Input Arguments

collapse all

Connection to the servo motor on MKR Motor Carrier or Nano Motor Carrier, specified as an object.

Position of servo motor shaft specified as a number representing the normalized angle between 0 to 1 with 1 corresponding to 180 degrees or pi radians. 0 corresponds to the minimum angle of the motor shaft, 0 degrees or 0 radians

Version History

Introduced in R2020a