Main Content

readAngularPosition

Read angular position of DC Motor in closed-loop control

Description

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

[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.

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.

[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.

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.

Introduced in R2020a