motor_control provides a calculation-only C++ control block for the Ownverter
FOC examples.
The library computes:
- current reconstruction from measured phase currents
- d/q current control
- optional outer speed PI with decimation
- optional open-loop electrical angle generation
Vdq,Vabc, and PWM duties
The application keeps ownership of:
- board APIs (
ShieldAPI,TaskAPI,ScopeMimicry,PositionAPI) - current offset calibration and signal filtering
- startup, idle, error, and overcurrent handling
- PWM enable/disable and all state-machine decisions
int8_t init(const MotorControlConfig& config)void reset()void setMode(MotorControlMode mode)void setCurrentReference(const dqo_t& current_reference)void setSpeedReference(float32_t speed_reference)void setOpenLoopVoltageQ(float32_t open_loop_voltage_q)void setOpenLoopSpeed(float32_t open_loop_speed)void setOpenLoopAngle(float32_t open_loop_angle)MotorControlOutput step(const MotorControlInput& input)
The application must provide, at every control tick:
- calibrated
iaandib - measured DC bus voltage
- electrical angle and speed when using closed-loop modes
- a valid
position_validflag for closed-loop modes
The library returns only calculations. It does not latch faults, stop PWM, or change operating state.
The current Ownverter example keeps its state machine in src/main.cpp. The
inline FOC math has been replaced by MotorControl::step(), while startup
sequencing, protections, and serial commands stay in the application.