Add Position Controll on MC SDK 5.x

Preface

In MC SDK 5.x, there are two control loops, the current loop and the speed (torque) loop. Some applications require the use of a position loop, such as motor control for UAV gimbal or subway gates. This article will explain how to add a simple position loop on top of the existing ST motor control library to enable 3-loop control for improved stability

Theoretical basis

If there is a gearbox motor, a speed loop needs to be added to reach the desired position faster, that is, three-loop control: position loop + speed loop + current loop, and the framework is the same as follows:

Implementation steps

Adding a DAC module to the MCSDK. If the MCU does not have a DAC module, the TIMER+RC filtering circuit can be used to simulate the DAC output. The following diagram shows the configuration for using a DAC, which requires configuring the user-defined DAC1/2.

Add the following variables or functions for position control:

  1. Position loop PID structure: PID_Handle_t PIDAngleHandle_M1
  2. Position control structure: Position_Handle_t
  3. Position error in angle: Position_GetErrorAngle
  4. Calculation of reference speed for position loop: Position_CalcSpeedReferrence
  5. Calculation of reference torque for position loop: Position_CalcTorqueReferrence

Refer to mc_position.h and mc_position.c for reference.

mc_task.c file modification
mc_task.c Add header files to the middleware.
MCboot() Add angle PID initialization function in the function
Reset the initial measured angle after positioning.
Add DAC output function
Add DAC output signal in TSK_HighFrequencyTask()
Add position control algorithm

In the medium frequency task function TSK_MediumFrequencyTaskM1 in mc_task.c, add position error calculation. Based on the error calculation, if the error is above a threshold, perform speed control, otherwise perform torque control.

Modify the reference current calculation
If the difference is reduced to a certain range, perform torque control.
Motor cumulative turns calculation

Test

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart