VirtuDrive-RTOS is a real-time DC motor speed control system designed to demonstrate Hardware-in-the-Loop (HIL) verification. Instead of a physical motor, the STM32 microcontroller controls a "Virtual Plant" running on a PC, enabling safe and rapid algorithm testing without external hardware.
In this project, the STM32F446RE believes it is driving a real motor. However, the physical motor is replaced by a Python simulation.
- STM32 calculates PID output and sends a PWM command via UART.
- Python Script receives the PWM, calculates the physics (inertia, friction), and determines the new RPM.
- Python Script sends the real-time RPM feedback back to the STM32.
- STM32 reads the RPM and adjusts the PID loop.
graph LR
subgraph PC [PC / Python Simulation]
A[Physics Model] -- "Feedback (RPM)" --> B(Serial Port)
B -- "Command (PWM)" --> A
end
subgraph MCU [STM32F446RE / Firmware]
C(UART Driver) -- "RxQueue" --> D[PID Controller]
D -- "TxQueue" --> C
end
B <==>|USB / UART| C
🛠 Tech Stack Firmware: C++14, FreeRTOS, STM32 HAL.
Simulation: Python, PySerial.
Communication: Custom Binary Protocol (Header/Tail protected).
Control: PID Algorithm with Anti-Windup.
🚀 How to Run
-
Flash the Firmware Open the project in STM32CubeIDE, build, and flash it to your Nucleo-F446RE board.
-
Start the Simulation Connect the board via USB and run the Python plant model:
pip install pyserial
python scripts/plant_sim.py
v1.0.0 - Initial Release