Main Content

writeSpeed

Write speed of PID motor

Since R2020a

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

Description

writeSpeed(pidObj,speed) drives the DC motor connected to the motor number corresponding to PID number of PID motor object in closed-loop control while receiving feedback from encoder channel corresponding to PID number at the specified speed.

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 speed control mode.

pidObj = pidMotor(mcObj,1);

Set the speed of the DC Motor M1 in closed-loop control with feedback from encoder channel 1 to 100 RPM

writeSpeed(pidObj,100);

Input Arguments

collapse all

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

Speed of the motor, specified in revolutions per minute (RPM).

Version History

Introduced in R2020a