Main Content

writeAngularPosition

Rotate DC motor by specified angle in closed loop position control

Since R2020a

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

Description

writeAngularPosition(pidObj,position) rotates the DC motor shaft with feedback from the encoder in closed loop position control by the position specified in radians.

example

writeAngularPosition(pidObj,position,mode) rotates the DC motor shaft with feedback from the encoder in closed loop position control by the position specified in radians, and the specified mode.

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 PID Motor in position control mode.

pidObj = pidMotor(mcObj,1,'position');

Rotate the motor by 45 radians with respect to initial position with feedback from encoder 1 in closed-loop control.

writeAngularPosition(pidObj,45);

Create a connection to the Nano Motor Carrier.

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

Create a connection to the PID Motor in position control mode.

pidObj = pidMotor(mcObj,1,'position');

Rotate the motor by 45 radians with respect to initial position with feedback from encoder 1 in closed-loop control.

writeAngularPosition(pidObj,45,'abs');

Input Arguments

collapse all

Connection to the PID motor on MKR Motor Carrier or Nano Motor Carrier in the position control mode, specified as an object.

Position of DC motor shaft, specified in radians.

Mode of calculation of angle of rotation, specified as abs or rel. In both the abs and rel mode, the angle of rotation of motor shaft is calculated based on current count of the encoder register. In the abs mode, the motor rotates by a difference in the angle between the current and desired position. In the rel mode, the motor rotates by the angle that is input.

Version History

Introduced in R2020a