Simulink Control Motors
matlab/simulink-agentic-toolkit
Build motor control solutions using Motor Control Blockset for PMSM, induction motors, BLDC, and SynRM.
FOC磁场定向控制深度指南 | 深入讲解FOC原理、SVPWM、MTPA、弱磁控制、龙贝格观测器,配合实测案例、C代码和PI整定脚本
$ npx skills add LeoYeAI/openclaw-master-skills --skill motor-foc-control -a claude-codeProject install by default; add -g for ~/.claude/skills/.
$ gh skill install LeoYeAI/openclaw-master-skills motor-foc-control --agent claude-codeProject scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).
$ git clone --depth 1 https://github.com/LeoYeAI/openclaw-master-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/motor-foc-control .claude/skills/motor-foc-control && rm -rf skills-srcUse ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.
Claude Code skills documentation · loads skills from .claude/skills/
Install the "motor-foc-control" agent skill from https://github.com/LeoYeAI/openclaw-master-skills/tree/main/skills/motor-foc-control into .claude/skills/motor-foc-control/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "motor-foc-control", then confirm the skill loads.Claude Code copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$skill-installer install https://github.com/LeoYeAI/openclaw-master-skills/tree/main/skills/motor-foc-controlType this inside Codex. $skill-installer <name> installs a curated skill from openai/skills. The installer writes to $CODEX_HOME/skills (default ~/.codex/skills). Restart Codex if the skill does not show up.
$ npx skills add LeoYeAI/openclaw-master-skills --skill motor-foc-control -a codexProject install goes to .agents/skills/; add -g for ~/.codex/skills/.
$ gh skill install LeoYeAI/openclaw-master-skills motor-foc-control --agent codexProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/LeoYeAI/openclaw-master-skills.git skills-src && mkdir -p .agents/skills && cp -r skills-src/skills/motor-foc-control .agents/skills/motor-foc-control && rm -rf skills-srcUse ~/.agents/skills/ instead of .agents/skills for a personal install.
Codex skills documentation · loads skills from .agents/skills/
Install the "motor-foc-control" agent skill from https://github.com/LeoYeAI/openclaw-master-skills/tree/main/skills/motor-foc-control into .agents/skills/motor-foc-control/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "motor-foc-control", then confirm the skill loads.Codex copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add LeoYeAI/openclaw-master-skills --skill motor-foc-control -a cursorProject install goes to .agents/skills/; add -g for ~/.cursor/skills/.
$ gh skill install LeoYeAI/openclaw-master-skills motor-foc-control --agent cursorProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/LeoYeAI/openclaw-master-skills.git skills-src && mkdir -p .cursor/skills && cp -r skills-src/skills/motor-foc-control .cursor/skills/motor-foc-control && rm -rf skills-srcUse ~/.cursor/skills/ instead of .cursor/skills for a personal install.
Cursor skills documentation · loads skills from .cursor/skills/, .agents/skills/, .claude/skills/, .codex/skills/
Install the "motor-foc-control" agent skill from https://github.com/LeoYeAI/openclaw-master-skills/tree/main/skills/motor-foc-control into .cursor/skills/motor-foc-control/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "motor-foc-control", then confirm the skill loads.Cursor copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gemini skills install https://github.com/LeoYeAI/openclaw-master-skills.git --path skills/motor-foc-control--scope user (default) or --scope workspace; --path is the subfolder of the repo that holds the skill; --consent skips the security confirmation prompt.
$ npx skills add LeoYeAI/openclaw-master-skills --skill motor-foc-control -a gemini-cliProject install goes to .agents/skills/; add -g for ~/.gemini/skills/.
$ gh skill install LeoYeAI/openclaw-master-skills motor-foc-control --agent gemini-cliProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/LeoYeAI/openclaw-master-skills.git skills-src && mkdir -p .gemini/skills && cp -r skills-src/skills/motor-foc-control .gemini/skills/motor-foc-control && rm -rf skills-srcUse ~/.gemini/skills/ instead of .gemini/skills for a personal install, then run /skills reload.
Gemini CLI skills documentation · loads skills from .gemini/skills/, .agents/skills/
Install the "motor-foc-control" agent skill from https://github.com/LeoYeAI/openclaw-master-skills/tree/main/skills/motor-foc-control into .gemini/skills/motor-foc-control/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "motor-foc-control", then confirm the skill loads.Gemini CLI copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gh skill install LeoYeAI/openclaw-master-skills motor-foc-controlInstalls for Copilot at project scope by default; add --scope user for a personal install. Preview a skill first with gh skill preview. Needs GitHub CLI 2.90.0 or later (public preview).
$ npx skills add LeoYeAI/openclaw-master-skills --skill motor-foc-control -a github-copilotProject install goes to .agents/skills/; add -g for ~/.copilot/skills/.
$ git clone --depth 1 https://github.com/LeoYeAI/openclaw-master-skills.git skills-src && mkdir -p .github/skills && cp -r skills-src/skills/motor-foc-control .github/skills/motor-foc-control && rm -rf skills-srcUse ~/.copilot/skills/ instead of .github/skills for a personal install. Commit .github/skills so cloud agent and code review can use it.
GitHub Copilot skills documentation · loads skills from .github/skills/, .claude/skills/, .agents/skills/
Install the "motor-foc-control" agent skill from https://github.com/LeoYeAI/openclaw-master-skills/tree/main/skills/motor-foc-control into .github/skills/motor-foc-control/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "motor-foc-control", then confirm the skill loads.GitHub Copilot copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add LeoYeAI/openclaw-master-skills --skill motor-foc-control -a opencodeOpenCode documents no install command of its own. Project install goes to .agents/skills/; add -g for ~/.config/opencode/skills/.
$ gh skill install LeoYeAI/openclaw-master-skills motor-foc-control --agent opencodeProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/LeoYeAI/openclaw-master-skills.git skills-src && mkdir -p .opencode/skills && cp -r skills-src/skills/motor-foc-control .opencode/skills/motor-foc-control && rm -rf skills-srcUse ~/.config/opencode/skills/ instead of .opencode/skills for a personal install.
OpenCode skills documentation · loads skills from .opencode/skills/, .claude/skills/, .agents/skills/
Install the "motor-foc-control" agent skill from https://github.com/LeoYeAI/openclaw-master-skills/tree/main/skills/motor-foc-control into .opencode/skills/motor-foc-control/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "motor-foc-control", then confirm the skill loads.OpenCode copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
motor-foc-controlFOC磁场定向控制深度指南 | 深入讲解FOC原理、SVPWM、MTPA、弱磁控制、龙贝格观测器,配合实测案例、C代码和PI整定脚本
Motor Foc Control is an agent skill from LeoYeAI/openclaw-master-skills. FOC磁场定向控制深度指南 | 深入讲解FOC原理、SVPWM、MTPA、弱磁控制、龙贝格观测器,配合实测案例、C代码和PI整定脚本
Its SKILL.md is about 3.5k tokens, which your agent loads only when the skill is triggered. The skill folder holds 5 other files, including scripts and reference files (for example `_meta.json`, `references/foc-quick-ref.md` and `scripts/foc_pi_tuner.py`).
The repository describes itself as: 🧠 Curated collection of 1209+ best OpenClaw skills — weekly updated by MyClaw.ai. The licence is MIT.
9 steps, taken from the first numbered list in SKILL.md.
Read from SKILL.md and the folder at commit e5199b5. It shows what the files ask for, not the result of running them.
Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.
From allowed-tools in the SKILL.md frontmatter.
Ships 1 file in scripts/ (Python), which the agent can run.
Shell commands in SKILL.md call:
pythonFrom the folder's file list and the shell code blocks in SKILL.md.
No URLs in SKILL.md.
From URLs in SKILL.md, links to its own repository left out.
Names no API keys, tokens, secrets or passwords.
From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.
Motor Foc Control loads about 3.5k tokens when it runs, and up to ~4.5k if it reads all its reference files. Until then it costs about 21 tokens; SKILL.md has 174 words of instructions outside code blocks.
Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.
The automated check found no risky patterns in SKILL.md.
Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); the scripts in this folder are not scanned.
The full file from LeoYeAI/openclaw-master-skills at commit e5199b5, republished under its MIT licence (© LeoYeAI). 174 words, ~3,537 tokens.
.claude/skills/motor-foc-control/SKILL.md (or your agent's skills folder). This skill also uses 3 other files; get the full folder from GitHub.面向电机工程实践,系统讲解 FOC 磁场定向控制的原理、实现、调参要点。 新增:PI自动整定脚本、弱磁深度控制、故障诊断完整流程。
三相静止坐标系 (ABC)
↓ Clarke 变换
两相静止坐标系 (α, β)
↓ Park 变换
两相旋转坐标系 (d, q)
关键公式:
Clarke: Iα = Ia
Iβ = (Ia + 2Ib)/√3
Park: Id = Iα·cos(θ) + Iβ·sin(θ)
Iq = -Iα·sin(θ) + Iβ·cos(θ)
逆变换:
Iα = Id·cos(θ) - Iq·sin(θ)
Iβ = Id·sin(θ) + Iq·cos(θ)
三相重构:
Ia = Iα
Ib = -Iα/2 + Iβ·√3/2
Ic = -Iα/2 - Iβ·√3/2 ┌──────────────────────────────────────────┐
│ │
Iq_ref ──→ ┌────┐ ┌────┐ ┌────┐ ┌─────┐ │
│ PI │───→│ SVPWM │──→│ 逆变器 │──→│ 电机 │ │
└────┘ └────┘ └─────┘ │ │ │
↑ PI ↑ ↑ │ │
Id_ref ───→┌────┐ │ │ ↓ ↓
│ PI │────┘ │ ┌────────┐ │
└────┘ │ │ 三相输出 │ │
↑ │ └────────┘ │
0 ───→┌────┐ │ ↑ │
┌─→│ −ωLqIq │←───────┘ │ │
│ └────┘ │ │
┌────┐│ │ │
θe ←│ PLL│←─────────────────────────────────┘ │
└────┘ │
(磁链观测器) │
│
←←←←←← 转速环 ←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←// 8个基本空间矢量(6个非零 + 2个零矢量)
// U0(000): 000, U1(100): 100, U2(110): 110, ...
// U3(010): 010, U4(011): 011, U5(001): 001
// U6(101): 101, U7(111): 111
typedef struct {
float alpha;
float beta;
} SpaceVector;
// 合成任意方向电压矢量
SpaceVector sv_ref = {
.alpha = Uref * cos(theta_e),
.beta = Uref * sin(theta_e)
};// 判断参考电压矢量所在扇区
int sv_sector(SpaceVector *sv) {
float a = sv->beta;
float b = sv->alpha * 0.866 - sv->beta * 0.5;
float c = -sv->alpha * 0.866 - sv->beta * 0.5;
int N = 0;
if (a > 0) N |= 1;
if (b > 0) N |= 2;
if (c > 0) N |= 4;
// N → 扇区号 (1~6)
const int sector_table[8] = {0, 2, 6, 1, 4, 3, 5, 0};
return sector_table[N];
}// 在扇区 k 中,计算相邻矢量作用时间
// T0 = (T - Ta - Tb) / 2
// Ta, Tb 根据扇区查表
typedef struct {
float Ualpha;
float Ubeta;
float T; // PWM周期
float Udc; // 母线电压
} SVPWM_Handle;
void svpwm_calc(SVPWM_Handle *h, float *Ta, float *Tb) {
float X = h->Ubeta;
float Y = h->Ualpha * 0.866 + h->Ubeta * 0.5;
float Z = -h->Ualpha * 0.866 + h->Ubeta * 0.5;
int sector = sv_sector((SpaceVector*)h);
switch(sector) {
case 1: *Ta = Z; *Tb = Y; break;
case 2: *Ta = Y; *Tb = -X; break;
case 3: *Ta = -Z; *Tb = X; break;
case 4: *Ta = -X; *Tb = Z; break;
case 5: *Ta = X; *Tb = -Y; break;
case 6: *Ta = -Y; *Tb = -Z; break;
}
// 过调制处理
float T_sum = *Ta + *Tb;
if (T_sum > h->T) {
*Ta = *Ta * h->T / T_sum;
*Tb = *Tb * h->T / T_sum;
}
// 零矢量分配(7段式对称PWM)
float T0 = (h->T - *Ta - *Tb) / 2;
float T7 = T0;
// 计算三相占空比
// DPA, DPB, DPC 存入比较寄存器
}// 各扇区占空比计算
// Tcm1, Tcm2, Tcm3 → 对应 ABC 三相比较值
void svpwm_duty(SVPWM_Handle *h, float *Tcm) {
float Ta, Tb;
svpwm_calc(h, &Ta, &Tb);
float T0 = (h->T - Ta - Tb) / 2;
int sector = sv_sector((SpaceVector*)h);
switch(sector) {
case 1: // U4(100), U6(110), U0(000)
Tcm[0] = (h->T + Ta + Tb) / 2; // A: 先断后通
Tcm[1] = (h->T - Ta + Tb) / 2; // B
Tcm[2] = (h->T - Ta - Tb) / 2; // C
break;
case 2: // U6(110), U2(010), U0(000)
Tcm[0] = (h->T - Ta + Tb) / 2;
Tcm[1] = (h->T + Ta + Tb) / 2;
Tcm[2] = (h->T - Ta - Tb) / 2;
break;
case 3: // U2(010), U3(011), U0(000)
Tcm[0] = (h->T - Ta - Tb) / 2;
Tcm[1] = (h->T + Ta + Tb) / 2;
Tcm[2] = (h->T + Ta - Tb) / 2;
break;
case 4: // U3(011), U1(001), U0(000)
Tcm[0] = (h->T - Ta - Tb) / 2;
Tcm[1] = (h->T - Ta + Tb) / 2;
Tcm[2] = (h->T + Ta + Tb) / 2;
break;
case 5: // U1(001), U5(101), U0(000)
Tcm[0] = (h->T + Ta - Tb) / 2;
Tcm[1] = (h->T - Ta - Tb) / 2;
Tcm[2] = (h->T + Ta + Tb) / 2;
break;
case 6: // U5(101), U4(100), U0(000)
Tcm[0] = (h->T + Ta + Tb) / 2;
Tcm[1] = (h->T - Ta - Tb) / 2;
Tcm[2] = (h->T + Ta - Tb) / 2;
break;
}
}对于内嵌式 PMSM(IPMSM),存在 d轴磁阻转矩,利用 MTPA 可在相同电流下获得更大转矩。
电磁转矩方程:
T = 1.5 × np × [Ψm × Iq + (Ld - Lq) × Id × Iq]
定义电流幅值:
|I| = √(Id² + Iq²)
MTPA 轨迹:固定 |I|,寻找使 T 最大的 (Id, Iq) 组合令 ∂T/∂Id = 0,约束条件 |I| = constant
拉格朗日函数:L = T - λ(√(Id²+Iq²) - I_ref)
∂L/∂Id = 1.5×np×[(Ld-Lq)×Iq] - λ×Id/|I| = 0
∂L/∂Iq = 1.5×np×[Ψm + (Ld-Lq)×Id] - λ×Iq/|I| = 0
联立求解(化简后):
Id_MTPA = -(Ψm / (2×ΔL)) + √[(Ψm/(2ΔL))² + Iq²]
其中 ΔL = Lq - Ld > 0
当 ΔL 很小时(表贴式),Id_MTPA ≈ 0 → 退化为 Id=0 控制// MTPA 查表法(实时性最好)
// 预计算 MTPA 曲线,运行时查表 + 线性插值
static const float mtpa_table_Iq[] = {
0.0, 2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 15.0, 18.0, 20.0
};
static const float mtpa_table_Id[] = {
0.0, -0.5, -1.1, -1.8, -2.5, -3.2, -4.0, -5.3, -6.6, -7.8
};
float mtpa_interpolate(float Iq) {
int n = sizeof(mtpa_table_Iq) / sizeof(mtpa_table_Iq[0]);
// 边界
if (Iq <= mtpa_table_Iq[0]) return mtpa_table_Id[0];
if (Iq >= mtpa_table_Iq[n-1]) return mtpa_table_Id[n-1];
// 查表
for (int i = 0; i < n-1; i++) {
if (Iq >= mtpa_table_Iq[i] && Iq < mtpa_table_Iq[i+1]) {
float t = (Iq - mtpa_table_Iq[i]) /
(mtpa_table_Iq[i+1] - mtpa_table_Iq[i]);
return mtpa_table_Id[i] + t * (mtpa_table_Id[i+1] - mtpa_table_Id[i]);
}
}
return 0;
}
// MTPA 解析公式法(适合在线计算)
float mtpa_Id_formula(float Iq, float Psi_m, float Ld, float Lq) {
float delta_L = Lq - Ld;
if (delta_L < 1e-6) return 0; // 表贴式,无 MTPA 效益
float k = Psi_m / (2.0f * delta_L);
float Id = -k + sqrtf(k * k + Iq * Iq);
return -Id; // Id 必须为负(去磁)
}当转速超过基速时,反电动势 E > Vdc,电压饱和。弱磁通过增加 Id(去磁电流)来降低有效磁链,从而在恒功率区扩展转速。
电压极限椭圆(d-q 平面):
Vd² + Vq² ≤ Vdc² / 2 (SVPWM线性调制区最大输出)
反电动势约束:
V = ω_e × (Ψm - Ld×Id) ≈ ω_e × Ψm_eff
弱磁的本质:在电压极限椭圆内重新分配 Id、Iq| 等级 | Id 比例 | 适用转速范围 | 特性 |
|---|---|---|---|
| 轻度弱磁 | -0.3×Imax | 1~1.5× 基速 | 转矩下降少 |
| 中度弱磁 | -0.5×Imax | 1.5~2× 基速 | 恒功率区主力 |
| 深度弱磁 | -0.7×Imax | 2~3× 基速 | 转矩大幅下降 |
| 六步方波 | 全部去磁 | >3× 基速 | 最大转速,扭矩波动大 |
typedef enum {
MTPA_MODE, // 最大转矩电流比
FW_MODE, // 弱磁模式
SIXSTEP_MODE // 六步方波
} FluxMode;
typedef struct {
float Vdc; // 母线电压
float V_lim; // 电压极限(Vdc/sqrt(2))
float V_th; // 弱磁启动阈值(建议 0.9×V_lim)
float Id_fw_min; // 最大去磁电流(负值)
float gamma; // 弱磁PI积分系数
float Kp_fw; // 弱磁比例增益
float Ki_fw; // 弱磁积分增益
} FluxWeaken_Handle;
void flux_weaken_update(FluxWeaken_Handle *h,
float V_mag, float Id_ref,
float *Id_fw_out) {
// V_mag = sqrt(Vd² + Vq²)
// Id_ref = MTPA 给定的 Id
static float integral = 0;
float error = V_mag - h->V_lim * 0.95; // 提前 5% 介入
if (error > 0) {
// 电压饱和,启动弱磁
integral += h->gamma * error;
integral = fminf(integral, 0); // Id_fw 为负,积分限幅
*Id_fw_out = h->Id_fw_min; // 直接给最大去磁
} else {
// 电压裕量足够,逐渐减小弱磁
integral *= 0.95; // 缓慢衰减
*Id_fw_out = Id_ref + integral;
}
// 与 MTPA 叠加
*Id_fw_out = fmaxf(*Id_fw_out, h->Id_fw_min);
}float select_Id_ref(float Id_MTPA, float Id_FW, float V_mag,
float V_lim, float speed) {
float Id_ref;
if (V_mag < V_lim * 0.85) {
// 电压充裕,MTPA 控制
Id_ref = Id_MTPA;
} else if (V_mag < V_lim * 0.95) {
// 电压接近饱和,过渡区
float alpha = (V_mag - V_lim * 0.85) / (V_lim * 0.1);
Id_ref = Id_MTPA + alpha * (Id_FW - Id_MTPA);
} else {
// 深度弱磁
Id_ref = Id_FW;
}
return Id_ref;
}typedef struct {
float I_alpha;
float I_beta;
float Ia;
float Ib;
float Ic;
float R;
float L;
float emf_alpha;
float emf_beta;
float angle;
float speed;
float prev_angle;
float k_gain; // 滑模增益
float filter_bw; // 低通截止频率 rad/s
} SMO_Handle;
// sign 函数(连续近似,避免抖振)
float sign_f(float x, float delta) {
if (x > delta) return 1.0f;
if (x < -delta) return -1.0f;
return x / delta; // |x|<delta: 线性近似
}
#define K_SMO 0.5f // 滑模增益(过大=抖振,过小=延迟)
void smo_update(SMO_Handle *smo, float V_alpha, float V_beta,
float Ia, float Ib, float Ic, float dt) {
float e_alpha = smo->I_alpha - Ia;
float e_beta = smo->I_beta - Ib;
// 滑模控制量
float z_alpha = smo->k_gain * sign_f(e_alpha, 0.05f);
float z_beta = smo->k_gain * sign_f(e_beta, 0.05f);
// 电流更新(欧拉法)
smo->I_alpha += dt * (-smo->R * Ia + V_alpha - z_alpha) / smo->L;
smo->I_beta += dt * (-smo->R * Ib + V_beta - z_beta ) / smo->L;
// 反电动势提取(低通滤波)
float alpha_lpf = 2.0f * M_PI * smo->filter_bw;
smo->emf_alpha += dt * alpha_lpf * (z_alpha - smo->emf_alpha);
smo->emf_beta += dt * alpha_lpf * (z_beta - smo->emf_beta);
// 角度提取
smo->angle = atan2f(smo->emf_alpha, -smo->emf_beta);
// 速度计算(微分)
float d_angle = smo->angle - smo->prev_angle;
// 角度归一化(处理 -π 到 +π 跳变)
if (d_angle > M_PI) d_angle -= 2.0f * M_PI;
if (d_angle < -M_PI) d_angle += 2.0f * M_PI;
smo->speed = d_angle / dt;
smo->prev_angle = smo->angle;
}// 对 SMO 估算的反电动势做 PLL
// emf_d = -ω_e × Ψm × sin(Δθ) ≈ -ω_e × Ψm × Δθ(小角度时)
// emf_q = ω_e × Ψm × cos(Δθ) ≈ ω_e × Ψm
typedef struct {
float Kp;
float Ki;
float integral;
float angle;
float speed;
float lock_threshold; // 锁定阈值 rad/s
int locked; // 锁定标志
} PLL_Handle;
void pll_update(PLL_Handle *pll, float emf_d, float emf_q, float dt) {
// d轴反电动势应接近0(正确对齐时)
// q轴反电动势 = ω_e × Ψm
float error = emf_d; // PLL 误差
// PI 积分
pll->integral += pll->Ki * error * dt;
// 积分限幅
pll->integral = fmaxf(fminf(pll->integral, 1000.0f), -1000.0f);
pll->speed = pll->Kp * error + pll->integral;
pll->angle += pll->speed * dt;
// 角度归一化 0~2π
while (pll->angle < 0) pll->angle += 2.0f * M_PI;
while (pll->angle > 2.0f*M_PI) pll->angle -= 2.0f * M_PI;
// 锁定判断
if (fabsf(error) < pll->lock_threshold && fabsf(pll->speed) > 10.0f) {
pll->locked = 1;
}
}# 自动计算 PI 参数
python scripts/foc_pi_tuner.py --R 1.23 --L 5.6e-3 --J 1e-3 --Kt 0.15
# 交互模式(引导输入)
python scripts/foc_pi_tuner.py --mode interactive
# 指定目标带宽
python scripts/foc_pi_tuner.py --R 2.1 --L 8e-3 --target_bw 150
# 指定采样周期 + 生成Bode图
python scripts/foc_pi_tuner.py --R 1.23 --L 5.6e-3 --Ts_us 62.5 --plot目标:带宽 ωbw = R/L × 0.5(典型因子 0.3~0.6)
Kp = L × ωbw
Ki = R / L
示例:
R = 1.23Ω, L = 5.6mH, ωbw = 1.23/0.0056 × 0.5 ≈ 110 rad/s
Kp = 0.0056 × 110 ≈ 0.616
Ki = 1.23/0.0056 ≈ 220 (需根据 Ts 离散化修正)目标:带宽 ≈ 电流环带宽 / 10
Kp_speed ≈ J × ωbw_speed
Ki_speed ≈ Kp_speed / Tm
示例:
J = 0.001 kg·m²
ωbw_speed = 11 rad/s (电流环1/10)
Kp_speed = 0.001 × 11 = 0.011
Tm = J × R / Kt² = 0.001 × 1.23 / 0.15² ≈ 0.055 s
Ki_speed = 0.011 / 0.055 ≈ 0.2给定采样周期 Ts:
Kp_d = Kp
Ki_d = Ki × Ts / 2
示例:Ts = 62.5μs (16kHz)
Ki_d = 220 × 31.25e-6 = 0.006875
实现(位置式):
integral += Ki_d × error
output = Kp_d × error + integral
限幅:output ∈ [-Vmax, Vmax]详见
references/foc-quick-ref.md
| 参数 | 典型值 | 说明 |
|---|---|---|
| 电流环带宽 | 100~500 Hz | 转速决定上限 |
| 速度环带宽 | 10~50 Hz | 电流环的1/5~1/10 |
| 开关频率 | 8~25 kHz | 载波比 >100 |
| 死区时间 | 200~800 ns | 电压越高,死区越大 |
| 电流采样延迟 | ≤1×Ts | 影响带宽 |
| 编码器分辨率 | ≥2500线 | 直接影响角度精度 |
| PWM分辨率 | ≥11-bit | 决定电流精度 |
| 现象 | 原因 | 解决 |
|---|---|---|
| 启动抖动 | 初始角度错误/Hall错位 | 检查初始角校准程序 |
| 高速失步 | 弱磁不足/电压裕量不足 | 增强弱磁,提高Vdc |
| 低速蠕动 | 编码器分辨率低/速度环带宽低 | 提高速度环带宽,更换编码器 |
| 电流振荡 | 电流环带宽过高/采样延迟大 | 减小 Kp,减小 Ts |
| 温升快 | 铜损过高/换向重叠角小 | 检查开关死区,降低电流 |
| 振动噪音 | PWM载波比低/共振频率激发 | 提高PWM频率,加陷波滤波 |
| 反电动势波形畸变 | 磁钢充磁不均/磁饱和 | Maxwell仿真确认 |
| 启动转速超调 | 速度环积分Windup | 加积分清零/抗积分饱和 |
| 换向时有台阶 | Hall传感器滞后/角度误差 | 检查Hall安装相位 |
启动抖动?
├─ 初始角度问题 → 重新做初始角辨识(脉冲法/预定位)
├─ Hall错位 → 校正Hall安装位置
└─ 电流环带宽不足 → 提高电流环 Kp
高速失步?
├─ 弱磁不足 → 增强 Id_fw,验证 V_mag > 0.95×V_lim
├─ 母线电压不足 → 提高 Vdc 或加升压
└─ 反电动势估算错误 → 检查速度观测器
振动噪音?
├─ 开关频率共振 → 提高PWM频率或加RC吸收
├─ 机械共振 → 加陷波滤波器
└─ 电流纹波大 → 提高开关频率或加电感scripts/foc_pi_tuner.py - PI参数自动整定脚本(推荐优先使用)references/foc-quick-ref.md - FOC工程参数速查卡(典型值、阈值速查)references/pm-materials.md - 永磁体牌号参数表(可选扩展)# 完整参数计算(自动输出离散PI参数)
python scripts/foc_pi_tuner.py --R 1.23 --L 5.6e-3 --poles 8 --J 1e-3 --Kt 0.15 --Ts_us 62.5
# 绘制 Bode 图(验证稳定性)
python scripts/foc_pi_tuner.py --R 1.23 --L 5.6e-3 --plot
# 对比不同带宽参数
python scripts/foc_pi_tuner.py --R 2.1 --L 8e-3 --target_bw 80
python scripts/foc_pi_tuner.py --R 2.1 --L 8e-3 --target_bw 200注意:脚本输出为理论初始值,实际需在电机上微调。调试顺序:电流环→速度环→位置环,逐级验证带宽和稳定性。
© LeoYeAI, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file
SKILL.md and 3 other files (scripts, references) in skills/motor-foc-control of LeoYeAI/openclaw-master-skills.
Open the folder on GitHubat commit e5199b5
Motor Foc Control next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.
| Skill | Stars | Used in | Tokens | Auto-check | Licence | Repo updated |
|---|---|---|---|---|---|---|
| Motor Foc Control this skillLeoYeAI/openclaw-master-skills | 2.2k | — | ~3.5k | Automated safety check: Pass | MIT | |
| Simulink Control Motorsmatlab/simulink-agentic-toolkit | 1.2k | — | ~2.8k | Automated safety check: Pass | Custom licence | |
| Motor Model Dynamicsbenchflow-ai/skillsbench | 1.8k | — | ~845 | Automated safety check: Pass | Apache-2.0 | |
| Focs Experimentsbrycewang-stanford/Awesome-Journal-Skills | 1.2k | — | ~1.6k | Automated safety check: Pass | MIT | |
| Focs Reproducibilitybrycewang-stanford/Awesome-Journal-Skills | 1.2k | — | ~1.4k | Automated safety check: Pass | MIT | |
| Focs Supplementarybrycewang-stanford/Awesome-Journal-Skills | 1.2k | — | ~1.6k | Automated safety check: Pass | MIT |
matlab/simulink-agentic-toolkit
Build motor control solutions using Motor Control Blockset for PMSM, induction motors, BLDC, and SynRM.
benchflow-ai/skillsbench
A skill your agent uses when simulating quadrotor physical dynamics — mapping desired thrust/moments to individual motor RPMs via a propeller allocation matrix, applying first-order motor lag, and…
brycewang-stanford/Awesome-Journal-Skills
A skill your agent uses when deciding whether and how computation appears in a FOCS (IEEE Symposium on Foundations of Computer Science) paper — a venue that accepts on theorems with no evaluation…
brycewang-stanford/Awesome-Journal-Skills
A skill your agent uses when hardening a FOCS (IEEE Symposium on Foundations of Computer Science) paper's checkability — the theory analogue of reproducibility — via hypothesis ledgers…
brycewang-stanford/Awesome-Journal-Skills
A skill your agent uses when architecting everything after page ten of a FOCS (IEEE Symposium on Foundations of Computer Science) submission — a venue with no separate supplement channel where the…
brycewang-stanford/Awesome-Journal-Skills
A skill your agent uses when running the final pre-upload audit of a FOCS (IEEE Symposium on Foundations of Computer Science) submission — the April HotCRP deadline clock, the…
LeoYeAI/openclaw-master-skills
Manages pipelines on a DevOps quality and efficiency platform through its OpenAPI: list workspaces and templates, create, update, run and cancel pipelines, and read run records.
LeoYeAI/openclaw-master-skills
Patches OpenClaw's Feishu extension so an edited document triggers an isolated agent session that reads the doc and replies inline, turning it into a live chat space.
LeoYeAI/openclaw-master-skills
Multi-context memory management system for OpenClaw agents with group-isolated storage, global shared memory, workspace organization, and group-specific skills isolation.
LeoYeAI/openclaw-master-skills
Runs a brand's AI-search visibility work end to end: diagnosing how AI platforms represent it, repositioning it, producing AI-optimized content and monitoring ongoing mentions.
LeoYeAI/openclaw-master-skills
Installs and authenticates the gws CLI, then automates Gmail, Drive, Sheets, Calendar, Docs, Chat and Tasks with ready-made recipes, persona bundles and security audits.
LeoYeAI/openclaw-master-skills
Runs four advisor roles, a fitness coach, nutritionist, data analyst and TCM practitioner, to build a health profile and track workouts, diet and wellness over time.
FOC磁场定向控制深度指南 | 深入讲解FOC原理、SVPWM、MTPA、弱磁控制、龙贝格观测器,配合实测案例、C代码和PI整定脚本. Motor Foc Control is an agent skill from LeoYeAI/openclaw-master-skills.
Run `npx skills add LeoYeAI/openclaw-master-skills --skill motor-foc-control -a claude-code`. Or copy the skill folder (skills/motor-foc-control in LeoYeAI/openclaw-master-skills) into .claude/skills/motor-foc-control in your project. Claude Code loads it when a task matches its description.
Run `npx skills add LeoYeAI/openclaw-master-skills --skill motor-foc-control -a codex`. Or copy the skill folder (skills/motor-foc-control in LeoYeAI/openclaw-master-skills) into .agents/skills/motor-foc-control in your project. Codex loads it when a task matches its description.
Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add LeoYeAI/openclaw-master-skills --skill motor-foc-control -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/motor-foc-control, .gemini/skills/motor-foc-control, .github/skills/motor-foc-control and .opencode/skills/motor-foc-control in your project.
Going by SKILL.md and its folder, Motor Foc Control needs Python for the scripts in its folder and the command-line tools its instructions call (python). Our summary lists: Python 3.
SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.
Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. The check reads SKILL.md only: the scripts in the folder are not scanned, so read them before running anything.
Motor Foc Control is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.
About 3.5k tokens (SKILL.md is roughly 14k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 1k tokens, read only when the agent opens those files.
Skills that share tags, products or a category with Motor Foc Control: Simulink Control Motors (matlab/simulink-agentic-toolkit, 1.2k stars), Motor Model Dynamics (benchflow-ai/skillsbench, 1.8k stars), Focs Experiments (brycewang-stanford/Awesome-Journal-Skills, 1.2k stars) and Focs Reproducibility (brycewang-stanford/Awesome-Journal-Skills, 1.2k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.
LeoYeAI (a GitHub user) maintains it in LeoYeAI/openclaw-master-skills, which has 2,161 GitHub stars. The repository holds 1,235 skills in this directory. The repository was last updated on July 20, 2026.
Source: LeoYeAI/openclaw-master-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.