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 #
- Input Reading and Initialization:
l
andr
are the inductance and resistance of the motor, respectively. They are ensured to be positive.- The voltage measurements
ud
anduq
are updated using a delay line (ud2
,uq2
,ud1
,uq1
,ud
,uq
). - The current measurements
id
andiq
are read from the input pins.
- Gain Clamping:
- The gains
kb
,ki
, andkl
are clamped to ensure they stay within valid ranges.
- Low-Pass Filtering of Current Changes:
- The changes in currents
delta_id
anddelta_iq
are calculated using a low-pass filter. This helps to smooth out noise in the current measurements. - The previous current values
old_id
andold_iq
are updated to the current measurements.
- Back EMF Calculation:
- The back EMF (
ed
andeq
) 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;
- 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;
- 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);
- Velocity Limiting:
- The estimated velocity is limited to ensure it does not exceed the maximum allowed value (
max_vel
).
- 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).
- Output Updates:
- The estimated back EMF (
ed
andeq
), velocity (vel
), and position (pos
) are updated on the output pins.
Pins #
Name | Description |
---|---|
r | parameter, Resistance of the motor (R) |
l | parameter, Inductance of the motor (L) |
ki | parameter, Integral gain for velocity compensation |
kb | parameter, Back EMF gain |
kl | parameter, Low-pass filter gain for current changes |
min_vel | parameter, Minimum velocity threshold for startup boost |
vel_boost | parameter, Velocity boost factor for startup |
max_vel | parameter, Maximum allowed velocity |
id | input, D-axis current |
iq | input, Q-axis current |
ud | input, D-axis voltage (current measurement) |
uq | input, Q-axis voltage (current measurement) |
ud1 | internal, Delayed D-axis voltage (one sample delay) |
uq1 | internal, Delayed Q-axis voltage (one sample delay) |
ud2 | internal, Delayed D-axis voltage (two sample delays) |
uq2 | internal, Delayed Q-axis voltage (two sample delays) |
vel | output, Estimated velocity of the motor |
pos | output, Estimated position of the motor |
ed | output, D-axis back EMF |
eq | output, Q-axis back EMF |
old_id | Previous D-axis current |
old_iq | Previous Q-axis current |
delta_id | output, Change in D-axis current |
delta_iq | output, Change in Q-axis current |
References #
Source: .c File