This repository implements a complete motor controller simulation with Field Oriented Control (FOC), using C++ for the simulation environment and Rust for the core control algorithms. It is designed to facilitate embedded firmware development, algorithm prototyping, and cross-language FFI exploration.
- Full Field Oriented Control (FOC): A complete FOC implementation in Rust, including Clarke, Park, and Inverse Park transforms, along with PI controllers for d-q axis current regulation.
- Detailed Motor Model: A Permanent Magnet Synchronous Motor (PMSM) model in Rust that simulates both electrical and mechanical dynamics.
- Closed-Loop Control: The C++ simulation now operates in a closed loop, feeding simulated sensor data from the motor model back into the Rust control algorithms.
- Functional Bootloader: A simulated bootloader in C++ that demonstrates firmware update procedures, including flash erase and programming.
- Real-time GUI Tuner: A Python-based GUI that connects to the simulation via TCP, allowing for live tuning of PI gains and current targets.
- Simulation Realism: The simulation includes models for sensor noise to better approximate real-world conditions.
- Comprehensive Unit Tests: The Rust code is validated with a suite of unit tests (
cargo test).
For detailed instructions on prerequisites, building, running, and testing the project, please refer to the INSTRUCTIONS.md file.
For convenience, you can use the provided quick start scripts:
- Windows:
run_sim.bat(from the project root) - Linux/macOS:
run_sim.sh(from the project root)
These scripts will automatically build the project, start the C++ simulation in the background, and then launch the Python GUI tuner.
-
Build the Project:
# Create the C header from Rust code cbindgen --config rust/cbindgen.toml --crate motor_algo --output cpp/inc/motor_algo.h --lang c rust # Build the C++ and Rust code mkdir build && cd build cmake .. cmake --build .
-
Run the Simulation (from the
builddirectory):./sim
-
Launch the GUI Tuner (from the
python_toolsdirectory in a new terminal):python gui_tuner.py
A detailed breakdown of the project's file structure is available in INSTRUCTIONS.md.