# 位置感測器 (`positionSensor`)

> 把軸的機械角與電氣角讀成訊號。

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

[元件參考](https://voltecx-web.nguyenvanqui291.workers.dev/zh/docs/reference/) · [English](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/mechanical/positionSensor/)

**分類:** 機械 · **種類:** `{"element":"positionSensor","kind":"mechanical"}`

## 何時使用

用於把轉子角度送入磁場導向控制或 Park 轉換。要計數時用增量式編碼器，要 sin 與 cos 時用旋轉變壓器，六步驅動用霍爾感測器。

## 接腳

| 接腳 | 訊號域 | 意義 |
|---|---|---|
| `shaft` | 機械 | 軸端子，讀取轉速，不加負載 |
| `out` | 訊號 | 機械角，單位 rad，每轉折回 |
| `elec` | 訊號 | 電氣角，單位 rad，每個電氣週期折回 |

## 常用參數

- `poles`: Number of poles of the machine (預設值: 2)
- `theta0`: Shaft angle at the start (預設值: 0)

## 參數

| 鍵 | 單位 | 預設值 | 典型範圍 | 說明 |
|---|---|---|---|---|
| `poles` | — | 2 |  | Number of poles of the machine |
| `theta0` | rad | 0 |  | Shaft angle at the start |

_參數說明在兩種語言中都是英文。_

## 模型

感測器從 theta0 開始以梯形法則對軸轉速積分，所以角度並非直接讀自馬達。輸出為 out = 折回到 [0, 2π) 的角度，以及 elec = (poles/2)·角度，折回方式相同。感測器是理想的，沒有量化、偏移與雜訊。

## 常見錯誤

- 感測器的角度從自己的 theta0（機械弧度）開始，而馬達的 theta0 是電氣角。對永磁馬達，請把感測器的 theta0 設為馬達 theta0 除以極對數，否則 dq 座標系會被旋轉這個差值。
- poles 必須等於馬達的極數，而不是極對數，且必須是偶數。不一致會使電氣角的變化速率錯誤，奇數則會被拒絕。
- 輸出每轉會折回一次。Park 轉換可以接受折回的角度，但需要連續角度的控制器必須自己對轉速積分。

Problems 規則: `compile.error`

## 規格書與來源

poles 取自軸上馬達規格書的極數。theta0 是模擬開始時的轉子角度（機械弧度），是必須與馬達起始位置一致的設計值。

## 範例

以指令 `file.openExample` 開啟範例，名稱為 `demo:positionSensor`.

---
由 `cargo xtask reference` 依使用說明文字與參數規格產生，請勿手動編輯。
