Sensorless

SENSORLESS #

Brief #

The sensorless component is responsible for estimating the motor’s velocity and position in real-time using electrical measurements. It applies low-pass filtering, back EMF calculation, velocity compensation, and position integration to achieve this.

Description #

  1. Input Reading and Initialization:
  • l and r are the inductance and resistance of the motor, respectively. They are ensured to be positive.
  • The voltage measurements ud and uq are updated using a delay line (ud2, uq2, ud1, uq1, ud, uq).
  • The current measurements id and iq are read from the input pins.
  1. Gain Clamping:
  • The gains kb, ki, and kl are clamped to ensure they stay within valid ranges.
  1. Low-Pass Filtering of Current Changes:
  • The changes in currents delta_id and delta_iq are calculated using a low-pass filter. This helps to smooth out noise in the current measurements.
  • The previous current values old_id and old_iq are updated to the current measurements.
  1. Back EMF Calculation:
  • The back EMF (ed and eq) is estimated using the motor’s electrical equations. The back EMF is the voltage generated by the motor due to its rotation.
  • The equations used are:
ed = ud - r * id - PIN(delta_id) * l / period + vel * l * iq * kb;
eq = uq - r * iq - PIN(delta_iq) * l / period - vel * l * id * kb;
  1. Velocity Compensation:
  • The estimated velocity vel is adjusted to compensate for the back EMF. The goal is to make the d-axis back EMF (ed) approach zero, which helps in stabilizing the control.
  • The compensation is done using the following equation:
vel -= SIGN2(eq, 1.0) * ed * ki * period;
  1. Startup Boost:
  • If the absolute value of the estimated velocity is below a minimum threshold (min_vel), a boost is added to help the motor start up more reliably.
  • The boost is applied using the following equation:
vel += SIGN2(id * iq, 0.1) * PIN(vel_boost);
  1. Velocity Limiting:
  • The estimated velocity is limited to ensure it does not exceed the maximum allowed value (max_vel).
  1. Position Update:
  • The estimated position pos is updated by integrating the estimated velocity over time.
  • The position is wrapped using the mod function to ensure it stays within a valid range (e.g., 0 to 2π for angular position).
  1. Output Updates:
  • The estimated back EMF (ed and eq), velocity (vel), and position (pos) are updated on the output pins.

Pins #

NameDescription
rparameter, Resistance of the motor (R)
lparameter, Inductance of the motor (L)
kiparameter, Integral gain for velocity compensation
kbparameter, Back EMF gain
klparameter, Low-pass filter gain for current changes
min_velparameter, Minimum velocity threshold for startup boost
vel_boostparameter, Velocity boost factor for startup
max_velparameter, Maximum allowed velocity
idinput, D-axis current
iqinput, Q-axis current
udinput, D-axis voltage (current measurement)
uqinput, Q-axis voltage (current measurement)
ud1internal, Delayed D-axis voltage (one sample delay)
uq1internal, Delayed Q-axis voltage (one sample delay)
ud2internal, Delayed D-axis voltage (two sample delays)
uq2internal, Delayed Q-axis voltage (two sample delays)
veloutput, Estimated velocity of the motor
posoutput, Estimated position of the motor
edoutput, D-axis back EMF
eqoutput, Q-axis back EMF
old_idPrevious D-axis current
old_iqPrevious Q-axis current
delta_idoutput, Change in D-axis current
delta_iqoutput, Change in Q-axis current

References #

Source: .c File