What happens after you move the slider?
Select a block to see its input, output, units and implementation. Solid arrows carry commands or physical effects; the dashed return carries measured feedback. A load acts on mechanics, not directly on the current reference.
The outer loop decides how hard to push
Position and speed are output-shaft quantities. Impedance combines position error, velocity error and feed-forward torque; position mode instead drives a speed loop. Drive::tick → servo_count_ / mode switch.
Torque must become a feasible current request
The default map uses id*=0 and the controller's nominal flux and 6:1 ratio. Current mode bypasses torque conversion but not current limits. A wrong Kt can cause torque error even when current tracks perfectly.
Regulate measured current, not an ideal state
PI adds cross-coupling and back-EMF feed-forward. The alternative is a relaxed one-step predictor with integral bias; it is not constrained MPC. PiFoc / PredictiveCurrent.
Voltage is limited before modulation
A circular voltage limit precedes inverse transforms and zero-sequence injection. The final limited vector is fed back to anti-windup. Duty is dimensionless, not torque or amperes. svpwm().
The inverter, not the renderer, energizes the motor
The live browser uses the averaged bridge with conduction and dead-time effects. The native bench also has a switched model. Gate-off does not imply instantaneous zero current: diode paths remain. Inverter / advance_bridge.
Motion follows current and load
dq electrical equations generate torque. Two inertias are linked by a compliant gearbox with backlash. The browser owns 1-axis mechanics; the external MuJoCo mode delegates both inertias and all poses to MuJoCo. Ownership diagram →
The controller receives a delayed observation
Filtering, noise, quantization, offset and latency sit between plant and controller. The sample-time angle is used for Park; a separate predicted angle is used for PWM. Dashboard plant-state plots are not raw ADC or controller-estimated currents.
Protection does not wait for the next FOC tick
FastTrip models comparator, blanking, BREAK and gate delay. Current crossings are observed at integration endpoints, so detection accuracy is bounded by the step. This is a virtual contract, not STM32 instruction timing or a safety-certified board.
Position, velocity and impedance are different promises.
| Mode | What the outer loop requests | Useful observation |
|---|---|---|
| Current | id*, iq* directly [A] | No output-position regulation. |
| Torque | τ* = τff [output N·m] | Nominal Kt map; not a torque-sensor feedback loop. |
| Velocity | PI on ω* − ω [rad/s] | A blocked joint requests torque up to its limit. |
| Position | Speed request 10(q*−q)+ωff, then speed PI | Velocity integral can reject a constant load. |
| Impedance | τ* = τff + Kp(q*−q) + Kd(ω*−ω) | Behaves as a virtual spring and damper. |
Try q*=0.4 rad, Kp=30 N·m/rad, and a +2 N·m load. The ideal equilibrium is 0.3333 rad. Increasing Kp reduces static deflection but raises torque demand and does not remove current, voltage, or delay limits. Run the load experiment →
Sign convention: the native plant subtracts positive external load from output torque. A reverse-side stop has a negative load reaction, so it pushes the shaft in the positive direction. A negative velocity is physical reverse rotation, not backward integration in time.
AC phase currents become nearly DC in a rotating frame.
The electrical angle is θe = p θrotor, where p=7 pole pairs in this synthetic profile. It is not the output angle: the gearbox and its elastic deflection separate those coordinates. The d axis aligns with magnet flux; q is perpendicular. These are amplitude-invariant transforms, with the convention used in math.hpp.
The transform actually used
With balanced sinusoidal phases and id=0, iq is a phase-peak-equivalent amplitude, not phase RMS. In this convention, dq power is 1.5(vd id + vq iq). Omitting 1.5 or mixing RMS with peak changes the inferred power and torque.
This interactive calculation is an explanatory diagram. It does not modify the live controller.
The electrical plant behind the animation
For id=0, Kt = 1.5pψ = 0.1155 N·m/A with nominal ψ=0.011 Wb. A 4 N·m output request through an ideal 6:1 ratio asks for about 5.772 A before limiting. That is a nominal conversion, not measured output-torque accuracy. The actual gearbox includes dynamics and losses. id=0 is the implemented baseline, not a claim of MTPA optimality for a salient motor.
Tuning must include saturation and latency.
The default PI design uses ωc=2π·600 rad/s, Kpd=Ldωc, Kpq=Lqωc and Ki=Rωc. Feed-forward cancels modeled d/q cross-coupling and back-EMF. The 600 Hz setting is a design parameter, not a measured closed-loop bandwidth for every operating point.
At 48 V, the available vector magnitude is about 26.60 V. SVPWM applies common-mode injection after inverse transforms. PI back-calculation receives the final limited vector, not independently clipped d and q values. Current-circle limiting and thermal derating happen before voltage generation.
| Symptom | Check first | Do not confuse it with |
|---|---|---|
| Angle stops tracking | Contact, current limit, torque limit, voltage saturation | A renderer problem |
| Current rings after a change | R/L mismatch, sample age, PI bandwidth | A need for maximum gain |
| Current is right; torque is wrong | Flux/Kt, ratio, losses, current normalization | A current-loop accuracy result |
| Fault at high speed | DC-bus regeneration, overcurrent and sensor validity | A software crash to hide by resetting |
The native stress profiles keep controller parameters separate from plant parameters. Use profiles/mismatch_RL.ini and profiles/linear_delay8.ini for research; changing a controller parameter is not the same as changing the simulated motor. CLI examples →
One 50 μs period, not one instantaneous calculation.
The first angle aligns current measurements at their sample time. The second predicts rotor orientation for the voltage command. Those predictions use measured speed; they do not magically remove noise, model error or acceleration within the interval.
Fault handling is a state machine, not a red label.
FastTrip observes phase current independently of the delayed ADC loop and schedules comparator, BREAK and gate-off events. A 5 μs integration grid still bounds crossing detection; configured sub-microsecond delays are not proof of sub-microsecond hardware response. BoardPort specifies future BSP responsibilities but does not implement them.
Why reverse rotation previously passed through the stop.
The old test was simply q > 0.60. Negative multi-turn motion never satisfied it, although the rendered pose repeats every 2π. The link could meet the back of the orange object with no reaction torque.
The browser now derives the blocked angular interval from the actual MJCF tip-sphere and link-capsule collision proxies against the stop box. Its boundaries are approximately 0.600000 and 1.101915 rad modulo 2π. When enabled at the default pose, the connected free arc is −5.181270 to +0.600000 rad. Crossing either boundary produces an opposing signed spring-damper reaction. The interval stays anchored during contact, so the solver cannot switch to the other side of the obstacle.
No angle is clamped for appearance and no motor parameter was changed. Finite compliance still permits small deflection: this is not zero-penetration rigid contact. Enabling a stop while the link occupies its solid interval is rejected without teleportation or killing the running experiment.
In the lab, use Collision envelopes to inspect the conservative collision proxies around the machined visual link. Only this reduced 1-axis stop is active in browser physics. Arbitrary 3D collisions, frictional contact and free-body impacts belong to the native MuJoCo examples, not to Three.js.
Continue with signals, then code.
Signals & losses connects these equations to native current, gate, power and thermal traces. Code & API owns integration details. The annotated primary-source guide explains which reference supports each method and where it stops.
Underlying methods: FOC [1], PMSM equations [2], SVPWM [3], anti-windup [4], STM32 shutdown [10]. Source-linked implementation and fidelity boundaries remain the authority for this lab.