Add host FCS-MPCC simulation and control.mpcc node for three-phase PMSM - #5
Open
saeed95-lab wants to merge 35 commits into
Open
Add host FCS-MPCC simulation and control.mpcc node for three-phase PMSM#5saeed95-lab wants to merge 35 commits into
saeed95-lab wants to merge 35 commits into
Conversation
Introduce Lib/Simulation (dq plant, eight-state VSI, MPCC/FOC runners and tests), the control.mpcc graph template, and docs/scripts so predictive current control can be verified on host before STM32 PWM adapter work.
4 tasks
- Add Assets/Examples/mpcc_demo.json: full FCS-MPCC hardware graph with phase currents, encoder, DC-link, FRAM config params, and telemetry. - Add Transforms.SwitchToDuty node: maps switch states (0/1) to 0%/100% duty for the existing Actuators.PwmOut. - Add Values.Config/constructor.cpp: restore platform_config_load() call that was dropped when config.value was renamed to Values.Config. - Fix control.mpcc: correct angular-velocity unit to au::radians/au::seconds, add port/parameter descriptions. - Fix CodeGenerator: treat Values.Config as a config node.
Conventional FCS picks S111 on low-L motors because one full vector predicts ~1000 A per step; Mode 3 applies deadbeat voltage through SVPWM so duties are continuous and Iq can track.
Bypass IqGate and stop CfgEnable from forcing ThrottleEnable off. Mode 3 now uses a shorter Ts_Eff plus residual current integrators so low-L deadbeat voltages are not lost to inverter deadtime.
…m/saeed95-lab/RTE into feature/fcs-mpcc-three-phase-pmsm
Reload Values.Config from FRAM in TimIsrStart, guard Poles<=0 in ElecAngle, and trip Mode 3 voltage when measured current exceeds I_Max.
Replace aggressive Ts_Eff/Ki and hard overcurrent trip with FOC-like gains, voltage LPF, soft current foldback, and wire L/Rs/Psi from FRAM.
…m/saeed95-lab/RTE into feature/fcs-mpcc-three-phase-pmsm
Sanitize Ld/Lq when Config is 0, restore Config.Value on control start, guard EncoderSign≈0, and add mpcc_ld/lq/sign/theta_mech telemetry.
SelfExecutablePath used Linux-only /proc/self/exe; add Apple support and still fall back to PATH when needed.
Unwrap θe derivative spikes, clamp Ωe feedforward, persist non-zero motor/encoder FRAM defaults, harden OC latch, and detune Mode 3 gains.
Raise Mode 3 gains, set I_Max=40 with a higher OC latch threshold, and slow Iq slew for Gen6 bring-up.
Hard OC latch and aggressive gains locked the rotor with huge current; Config repair also treated Sign=-1 as missing and forced +1. Co-authored-by: Cursor <cursoragent@cursor.com>
Session 215141 pinned duties near 50% via an rs-based stall cap (~2 V with Rs≈0.012 Ω) and iq tracked opposite IqVar; match FOC gains/limits and flip q-axis error polarity. Co-authored-by: Cursor <cursoragent@cursor.com>
…m/saeed95-lab/RTE into feature/fcs-mpcc-three-phase-pmsm
Session 220144 still had FRAM Sign=+1 (wrong θe, id ±40 A) and soft foldback that kept duties near 50%; wire Sign=-1 and raise L/Ts current gains. Co-authored-by: Cursor <cursoragent@cursor.com>
…emo) Main fixed the FOC current-dump regression (lost sensor sign inversion in the node-library overhaul) via a configurable InvertPolarity parameter. Port the same template here and enable it on the Currents node so the MPCC loop gets correctly-signed feedback.
Use deadbeat voltage→SVPWM without hard OC foldback, match FOC encoder Sign (+1/FRAM), and document the safe first-spin procedure. Co-authored-by: Cursor <cursoragent@cursor.com>
The graph's embedded Sensors.PhaseCurrents uses the InvertPolarity parameter (ported from main), but the node instance never set it, so codegen emitted no binding and the build failed with 'InvertPolarity was not declared in this scope'.
Lift ωe clamp to ±3000 rad/s, increase deadbeat gain scale to 0.70, and match FOC Iq slew (50 A/s) so 100 V high-speed runs are not starved. Co-authored-by: Cursor <cursoragent@cursor.com>
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Lib/Simulationwith a dq PMSM plant, eight-state two-level VSI model, FCS-MPCC controller (conventional + Zhang delay/back-EMF/optimal-duty modes), FOC baseline, closed-loop runners, and unit tests.control.mpccnode template (Assets/NodeTemplates/control.mpcc/) that outputs switching statesSa/Sb/Scfor future STM32 PWM adapter work.docs/, with host plot/comparison helpers inscripts/.Test plan
cmake -B build -G Ninja && cmake --build build -j8ctest --test-dir build --output-on-failure(includesSimulation_*tests)./build/Lib/Simulation/mpcc_closed_looppython3 scripts/plot_results.pyand/orpython3 scripts/compare_mpcc_foc.pyMade with Cursor