# Sliding-Mode Observer (`smo`)

> Estimates the rotor angle and speed of a permanent-magnet motor without a position sensor.

![smo](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/img/smo.svg)

[Component reference](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/) · [繁體中文](https://voltecx-web.nguyenvanqui291.workers.dev/zh/docs/reference/control/smo/)

**Group:** Control · **Kind:** `{"block":"smo","kind":"control"}`

## When to use it

Use it to run a permanent-magnet motor without a position sensor. It needs back-EMF, so start open loop and hand over above a speed threshold.

## Pins

| Pin | Domain | Meaning |
|---|---|---|
| `valpha` | signal | Voltage command on the alpha axis, in V |
| `vbeta` | signal | Voltage command on the beta axis, in V |
| `ialpha` | signal | Measured current on the alpha axis, in A |
| `ibeta` | signal | Measured current on the beta axis, in A |
| `theta` | signal | Estimated rotor angle, in radians |
| `w` | signal | Estimated electrical speed, in rad/s |

## Common parameters

- `rs`: Stator resistance of the motor (Default: required)
- `ls`: Stator inductance of the motor (Default: required)
- `k`: Strength of the sliding correction (Default: required)
- `phi`: Width of the smooth zone around zero error (Default: 1)
- `fc`: Cutoff of the filter on the estimate (Default: 300)

## Parameters

| Key | Unit | Default | Typical range | Description |
|---|---|---|---|---|
| `rs` | Ω | required |  | Stator resistance of the motor |
| `ls` | H | required |  | Stator inductance of the motor |
| `k` | V | required |  | Strength of the sliding correction |
| `phi` | A | 1 |  | Width of the smooth zone around zero error |
| `fc` | Hz | 300 |  | Cutoff of the filter on the estimate |
| `fpll` | Hz | 100 |  | Speed of the loop that tracks the angle |

_Parameter descriptions are in English in both languages._

## Model

A model of the stator, L*d(ih)/dt = v - Rs*ih - z, runs beside the machine and is forced towards the measured current i by the switching term z = k*sat((ih - i)/phi), where sat is linear for a current error below phi (the boundary layer, which replaces the chattering sign) and ±1 beyond it. With k above the peak back-EMF the error stays in the layer and z settles at the back-EMF e = wr*psi_f*(-sin(theta), cos(theta)). A low-pass of cutoff fc filters z, and a phase-locked loop (PI, damping 1/sqrt(2), bandwidth fpll) on the filtered vector gives the speed and the angle, which avoids an atan2 of noisy signals. The output angle adds the phase lag of the low-pass and of the current observer, atan(w/(2*pi*fc)) + atan(w*L/(Rs + k/phi)), so it is exact at a constant speed. The current observer uses backward Euler and is stable for any step. The block has no direct feedthrough, so it can sit in the loop it feeds; it then reads the voltage of the previous step. The voltage inputs are the voltage the inverter is commanded to apply, for example the alpha output of Inverse Park Transform, and the current inputs come from Clarke Transform. theta is the d axis seen from phase a, and w is the mechanical speed times the pole pairs, negative when the machine turns backwards.

## Common mistakes

- k must be larger than the peak back-EMF, and about 1.5 times it is a good choice. Below that the estimate is wrong and the angle may lock late or not at all, while a very large k adds ripple that the low-pass has to remove.
- At low speed the back-EMF is lost in the ripple, so the estimate cannot start a motor from standstill. Start open loop up to a speed threshold, let w pass it, then switch the angle to theta; switching below that speed gives a wrong angle and the loop can run away.
- The voltage inputs must be the voltage the motor really gets, which is the reference after the inverse Park, not a duty cycle or a modulation index. Voltage lost to the DC link limit, dead time or switch drops shows up as an error in the estimate, and rs and ls must match the motor, which is assumed to have Ld equal to Lq.
- An input that is not connected reads 0, so an observer without current inputs sees a motor that draws no current and the angle drifts. Connect all four inputs, and take valpha and vbeta from the same stage that feeds the modulator.

Problems rules: `pin.unconnected`

## Datasheet and sources

There is no datasheet. rs and ls are the phase resistance and inductance of the motor, the same as in Surface PMSM. k is about 1.5 times psi_f times the highest electrical speed, and phi is a fraction of the rated current, 1 to 2 A for a 5 A motor. fc is a few times the highest electrical frequency and well below the switching frequency, and fpll is 50 to 200 Hz, below fc.

## Example

Open the example with the command `file.openExample` and the name `demo:smo`.

---
Generated by `cargo xtask reference` from the usage texts and parameter specs. Do not edit by hand.
