Main Content

readSpeed

Read current rotational speed of DC Motor in closed loop control

Description

[speed] = readSpeed(pidObj) returns the current rotational speed of the DC motor in closed-loop control as read by the quadrature encoder connected to encoder channel number corresponding to PID motor number.

[speed,timestamp] = readSpeed(pidObj) returns the current rotational speed of the DC motor in closed-loop control as read by the quadrature encoder connected to encoder channel number corresponding to PID motor number, and the timestamp in datetime format.

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,'speed');

Read the current rotational speed.

speed = readSpeed(pidObj);

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,'speed');

Read the current rotational speed.

[speed,timestamp] = readSpeed(pidObj);

Input Arguments

collapse all

PID motor object connected to MKR Motor Carrier or Nano Motor Carrier specified as an object.

Output Arguments

collapse all

Current rotational speed in RPM of the DC Motor as read by the encoder, returned as a double.

Time at which MATLAB® reads speed data, specified as a datetime.

Introduced in R2020a