MDCS

Modular Dynamics Control Suite

Stop learning Control Systems in a vacuum. > Code the math. Control the hardware. Bridge the gap.

During mechanical, electrical, and electronic engineering education, students are rarely exposed to a physical control systems bench. Most learning is confined to abstract simulation environments like MATLAB and Simulink, leaving a massive gap between the idealized model and industrial firmware reality.

Traditional control education often leaves students stranded in a "Classical Gap," mastering Root Locus and Bode plots for simple systems that fail when confronted with the multi-variable complexity of a Cart-Pole or Furuta Pendulum.

This simulator upgrades that journey by utilizing State-Space Control Theory, allowing students to move beyond Transfer Functions and interact directly with the "Source Code" of physics. By reframing LQR not as an abstract algorithm, but as an optimized way to tune the "PID Intuition" — this project bridges the divide between academic math and hardware reality.

Supported by a high-fidelity 20kHz simulation that bypasses the friction of Z-transforms, students don't just learn the how of the equations; they experience the why of the hardware. This is the same language used by industry leaders, transforming abstract matrices into the tangible movement of a 200g cart fighting gravity and providing the vital context needed to turn academic theory into professional mastery.

MDCS provides a Real-Time (Soft) Hardware-Emulated environment—a Software-in-the-Loop (SIL) Digital Twin that faithfully models a system using Lagrangian mechanics and the RK4 solver. Unlike theoretical scripts, this is designed to be interacted with as if it were a real plant sitting on your desk. It utilizes C, the industry standard for embedded systems, ensuring the transition from simulation to real hardware is seamless.

To enrich the student experience further, the project includes a High-Fidelity 3D Visualizer and Real-Time Telemetry Graphs. By mimicking noisy feedback and hardware signals, a bench-like environment is provided that challenges you to solve real-world problems like sensor jitter and encoder drift.

The framework is completely configurable; you can tweak the system specs and noise levels directly in the source code. Since the core executable is only ~20 KB (minus the visualizers and the external shared libraries), it's incredibly lean. By writing your compensator in native C, you get a real feel for how industrial control actually works—managing fixed-step timing and deterministic loops rather than just dragging blocks in a GUI.

The core physics engine is optimized for single-thread execution to ensure deterministic timing, mirroring bare-metal microcontroller behavior. Meanwhile, the visualization layer utilizes asynchronous threading to handle UI rendering without blocking the 20kHz data stream. This decoupled architecture ensures high-fidelity physics even when running on standard consumer-grade x86 hardware without the overhead of heavy simulation suites.

The SIL project is built for Linux Desktop environments and utilizes a high-precision timing super-loop to emulate a Real-Time (Soft) bare-metal microcontroller environment. To mitigate general-purpose OS jitter, the framework employs a lockstep architecture where the physics solver and compensator are synchronously coupled; if the OS introduces a scheduling delay, the entire simulation state remains frozen to preserve temporal determinism. The system implements a self-healing absolute timeline that automatically corrects for OS-induced blocking to prevent cumulative timing drift against the wall clock, maintaining seamless visual realism regardless of background CPU load.

Dynamic Response Visualizations

Simulation Replay

Note: These are screen recordings of the MDCS environment. If videos do not render, please refresh.

Available Models

1. Rotary Inverted Pendulum: This high-fidelity Furuta Pendulum Digital Twin utilizes a 20kHz RK4 physics engine and full Lagrangian mechanics to simulate complex multi-body dynamics, bridging the gap between theoretical state-space control and embedded system reality. Stabilized by an aggressive LQR controller tuned with a high-priority \( Q \) matrix (\( Q_{pend}=100 \)) to overcome a simulated 0.4V motor deadzone, the system maintains the unstable \( \pi \) equilibrium through precise, high-gain restorative torques. Unlike idealized models, this platform explicitly emulates hardware non-linearities—including quadrature encoder jitter, missing pulses, and discrete 1kHz compensator timing—to provide a rigorous environment for stress-testing robust industrial control laws. The integration of a real-time visualizer and a C-based SIL loop ensures that every micro-correction is both mathematically optimal and physically faithful to the constraints of DC motor actuation and sensor noise.

2. DC Motor with Inverse Pendulum: A classic "unstable" control systems benchmark where a motorized pivot must provide real-time torque to maintain a free-rotating rod in an upright equilibrium (\( 180^\circ \le \)). The system operates by measuring the angular position and velocity through high-resolution encoders and applying a control law—typically a combination of LQR (Linear Quadratic Regulator) for stability and an Integrator for precision—to command motor voltage. Mathematically, the motor must "chase" the pendulum's center of gravity by accelerating the pivot point to counteract the gravitational torque. While the theoretical model predicts a perfect balance, the physical implementation must contend with sensor noise, which causes micro-vibrations, and mechanical drift, which requires high-stiffness gains (\( k_1 = -220 \)) and integral action to maintain a true vertical.

Hardware Noise Emulation

The MDCS environment simulates common industrial hardware non-linearities to ensure control laws are robust against real-world interference:

NOISE_PWM_VIBRATION NOISE_SENSOR_JITTER NOISE_MISSING_PULSES NOISE_ENCODER_SPIKE
Clone from GitHub

Project Demonstration

Watch the full setup and walkthrough of the Modular Dynamics Control Suite (MDCS) in action.

Ecosystem Positioning

While research-grade tools like MATLAB or Gazebo are essential for high-level robotics, this simulator focuses on the Firmware-Logic Bridge.

Approach Ideal For Cost Focus
Theoretical (Python/Scilab) Math & Plotting Free Pure Analytics
Heavyweight (Simulink) Industrial Research &
Enterprise MBD
Proprietary System Modeling
Robotics (ROS/Gazebo) Navigation/Physics Free High-level AI
Acausal (OpenModelica) Multi-Domain Physics Free Complex Systems
Firmware SIL (This Project) Bare-metal C Logic Free (~20KB) The Control Loop
TERMINOLOGY NOTE: Acausal modeling (OpenModelica) uses declarative equations to describe how physical components exchange energy, hiding the mathematical derivation from the user. In contrast, MDCS (This Project) uses Causal/Procedural logic, mirroring how an embedded processor executes code line-by-line. This forces the engineer to master the exact relationship between system variables.

"The goal isn't to replace the giants—it's to give you a lightweight, transparent environment where you can master the C code that actually drives the motors."


TECHNICAL ASSUMPTIONS:
The simulation utilizes an RK4 (4th Order Runge-Kutta) solver capable of sustained, prolonged execution without catastrophic numerical divergence. To maintain a lightweight footprint, this solver assumes rigid-body dynamics and utilizes a linear friction model. Motor induction effects are not considered to simplify the electromechanical coupling.

Note: Modifying physical parameters (mass, dimensions) alters the system's dynamic matrices, introducing novel control challenges to solve. LQR gains tuned for the default configuration must be re-derived to ensure stability.

System Block Diagram

High-level architectural overview of the SIL control loop and emulated hardware interfaces.

System Block Diagram

Modeling Fidelity & Abstractions

Bridging the digital-to-physical gap with intentional modeling choices:

Actuator (PWM)

Utilizes a Mean Value Model where the compensator returns a normalized duty cycle. While the 20kHz loop successfully simulates high-frequency quadrature pulses, simulating raw PWM square waves would require a separate, significantly faster execution mechanism to maintain resolution. To avoid unnecessary architectural complexity, the system bypasses pulse-width modulation simulation and returns the PWM value directly as a continuous control signal, ensuring high-fidelity torque calculation without the overhead of high-speed switching logic.

Sensors (Encoders)

Explicitly modeled as Discrete Quadrature Pulses (A/B). This forces the compensator to manage quantization error and velocity jitter. Absolute positioning is verified via Z-Index latching at the \( 0^\circ \) (Down) reference point.

Development Methodology

This project represents an AI-augmented engineering workflow. While I architected the core mechanical framework, 20kHz physics/1kHz control timing constraints, and coordinate sign conventions, Gemini (Google) was utilized to assist in the symbolic expansion of the Lagrangian and Jacobian matrices, as well as the boilerplate generation of the Pygame visualizer, PyQtGraph plotter, and LQR solver.

Beyond Simulation: Master the Silicon

The MDCS simulator focuses on the control loop, but true Embedded Freedom requires mastering the hardware itself.

For students who want to go deeper into the "physics" of microcontrollers—including Linker Scripts, Startup Code, and Bare-Metal Peripheral Drivers—I have released a comprehensive 24-Hour Cortex-M4 Deep Dive.

View the 24-Hour Course on YouTube

Recommended by the r/embedded community as a standard reference for bare-metal ARM development.