Skip to content

yufurkan/VirtuDrive-RTOS

Repository files navigation

VirtuDrive-RTOS: HIL PID Controller

STM32 RTOS Language Python

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.

🔄 What is Hardware-in-the-Loop (HIL)?

In this project, the STM32F446RE believes it is driving a real motor. However, the physical motor is replaced by a Python simulation.

  1. STM32 calculates PID output and sends a PWM command via UART.
  2. Python Script receives the PWM, calculates the physics (inertia, friction), and determines the new RPM.
  3. Python Script sends the real-time RPM feedback back to the STM32.
  4. 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
Loading

🛠 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

  1. Flash the Firmware Open the project in STM32CubeIDE, build, and flash it to your Nucleo-F446RE board.

  2. 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

About

Real-time PID control system on STM32F446RE using FreeRTOS and C++, featuring a Python-based Hardware-in-the-Loop (HIL) physical simulation.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages