Main Content

readAngularPosition

Read angular position of DC Motor in closed-loop control

Since R2020a

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

Description

position = readAngularPosition(pidObj) returns the angular position of the DC motor shaft, in closed-loop control with the rotary encoder in radians.

example

[position,timestamp] = readAngularPosition(pidObj) returns the angular position of the DC motor shaft, in closed-loop control with the rotary encoder, in radians and the timestamp in the datetime format.

example

position = readAngularPosition(pidObj,'Reset',reset) returns the angular position of the DC motor shaft in radians and resets the encoder count to zero after reading its current value.

example

[position,timestamp] = readAngularPosition(pidObj,'Reset',reset) returns the angular position of the DC motor shaft in radians; timestamp in datetime format and resets the encoder count to zero after reading its current value.

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 angular position with feedback from encoder 1 in closed-loop control.

position = readAngularPosition(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 position control mode.

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

Rotate the angular position with feedback from encoder 1 in closed-loop control.

[position,timestamp] = readAngularPosition(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 position control mode.

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

Rotate the angular position with feedback from encoder 1 in closed-loop control.

position = readAngularPosition(pidObj,'Reset',true);

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 angular position with feedback from encoder 1 in closed-loop control along with the timestamp.

[position,timestamp] = readAngularPosition(pidObj,'Reset',true);

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.

Setting reset to true resets the counter to zero for subsequent read. This is an optional argument.

Output Arguments

collapse all

Angular position of the DC motor shaft obtained from the count of the encoder since the last reset.

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

Version History

Introduced in R2020a