This repository is a Claude Code workspace for building MATLAB/Simulink models of PMSM control (FOC, FCS-MPC, DTC, SMC) and for distilling reference models into reusable skills under anti-contamination discipline.
Before doing modeling work in this workspace:
- Install the MATLAB MCP server so MATLAB runs directly instead of through Bash:
- Source: https://github.com/matlab/matlab-mcp-core-server (MathWorks, MIT)
- Build per its README, then register it:
claude mcp add matlab --scope user -- <path-to-binary> - It provides
detect_matlab_toolboxes,check_matlab_code,evaluate_matlab_code,run_matlab_file.
- Install the MathWorks official MATLAB skills for Claude Code per MathWorks' instructions.
- Confirm MATLAB R2024b or later with Simulink, Simscape, Simscape Electrical, and Control System Toolbox.
If the MCP server is not available, run MATLAB through its CLI:
matlab -batch "run('script.m')" — and use a background process for long simulations.
.claude/skills/ is registered automatically when Claude Code opens this folder:
motor-pmsm-base— plant + dq conventions + building-blocks SOP + broken-FOC defense. Base for the method skills.motor-fcs-mpc— single-vector Finite-Control-Set MPC current loop.motor-fcs-mpc-dualvector— dual-vector (two-vectors-per-period) FCS-MPC current loop with q-axis deadbeat time allocation. Layers onmotor-fcs-mpc.motor-fcs-mpc-trivector— three-vector (two adjacent active + one zero per period) FCS-MPC current loop; a 2×2 dual-axis deadbeat solve nulls bothi_dandi_qin one period.motor-dtc-pmsm— Direct Torque Control, αβ frame, Sutikno 6-state switching table.motor-smc-pmsm— Sliding Mode Control speed loop (PD-type sliding + super-twisting) over a dq PI current loop.motor-mfpcc-eso— model-free deadbeat predictive current control (ultralocal model + Extended State Observer + SVPWM); parameter-free current law (onlyα,ω0). Continuous control set, not FCS-MPC. Layers onmotor-pmsm-base.simulink-layout-tidy— general-purpose Simulink layout tidier (compact, overlap-free, honest crossing report). Not motor-specific; supports the layout gate.
Each method skill layers on motor-pmsm-base (motor-fcs-mpc-dualvector additionally builds on motor-fcs-mpc). Read the relevant SKILL.md and its references/ before building.
To learn an external reference model and distil it into a new skill, follow
workflow/reference_model_learning_workflow.md — the 11-phase Reference Model Learning Workflow.
Its non-negotiable disciplines:
- Learn / build separation — understanding a model and rebuilding it are verified as two separate capabilities.
- No peeking on rebuild — the rebuild subagent must not read the reference model; otherwise the result collapses into a copy and the skill is hollow.
- Anti-contamination isolation — give every verification subagent an explicit must-NOT-read list (confidential sources, prior-pass artifacts, methodology internals), and audit its output (grep / mathematical consistency / structural consistency) before trusting it.
- Theory first — derive the plant equations and control-law formulas before reading any
.slx; a model that contradicts the derived formulas is a finding, not a hallucination.
- Plan before building. Write a numbered plan (parameter table, design decisions, build-script structure) and get user approval before the first
add_block. shared/is read-only. Reuseshared/formulas/andshared/building_blocks/by reference; do not duplicate or re-derive. Build your models inworkspace/.- One-click reproducibility. A built
.slxmust run from a double-click in a fresh MATLAB session — inject all parameters viaset_param(mdl, 'InitFcn', ...). - Visual check before metrics. Before trusting numerical scores, confirm the motor rotates,
iqtracks its reference, theabccurrents are AC sinusoids (not DC-locked), and the torque energy balance holds. A failed visual check means a broken implementation regardless of the numbers.
- On failure, change approach — don't repeat a method that just failed; after ~3 distinct attempts, stop and report rather than thrashing.
- Never swallow an error silently.
- On long build scripts, re-read your plan every few steps.
- Be direct: if the user's approach has a flaw, give the counter-argument with reasoning rather than going along with it.