Skip to content

Repository files navigation

MATLAB Simulink Control Toolbox PID

Linear Stage PID Control

PID-based DC motor linear stage position control and trajectory tracking using MATLAB/Simulink.

A complete simulation of a DC-motor-driven linear stage implementing plant modeling, PID controller design, robustness testing, disturbance rejection, sensor noise, and real-time MATLAB visualization.


Table of Contents


Overview

This project models and controls a DC-motor-driven linear stage using MATLAB/Simulink. The control goal is precise position tracking — demonstrated with a 50 mm target — under realistic conditions including actuator saturation, sensor noise, quantization, and external disturbances.

Tools: MATLAB R2026a · Simulink · Control System Toolbox

Visualization Demo


System Architecture

Reference → Error → PID Controller → Actuator Saturation (±10 V)
         ←  Sensor (noise + quantization)  ←  DC Motor + Lead Screw → Platform Position

Simulink Model

Logged signals:

Signal Description
out.r_out Reference position
out.y_actual True physical position
out.y_measured Measured (noisy) position
out.u_pid PID command (before saturation)
out.u_sat Actuator command (after saturation)
out.tout Simulation time

System Parameters

DC Motor

Parameter Symbol Value
Armature resistance R 2 Ω
Armature inductance L 0.2 H
Torque constant Kt 0.05 N·m/A
Back-EMF constant Ke 0.05 V·s/rad
Rotor inertia J 1×10⁻⁵ kg·m²
Viscous friction b 1×10⁻⁵ N·m·s/rad

Linear Stage

Parameter Symbol Value
Platform mass m 1 kg
Stage damping bx 2 N·s/m
Lead-screw pitch p 0.005 m/rev

The pitch-to-radius conversion factor k = p / (2π) ≈ 7.958×10⁻⁴ m/rad maps motor angle to linear displacement.


Controller Design

The plant transfer function maps voltage to linear position. Four controllers were compared:

Controller Kp Ki Kd
P 10–100 — —
PI 100 2–20 —
PD 100 — 1
PID (final) 100 2 1

Final PID transfer function:

C(s) = 100 + 2/s + s

Actuator limits: ±10 V (assumed driver limit).

Controller Comparison


Key Results

50 mm Step Response (±10 V)

Metric Value
Rise Time 1.335 s
Settling Time 3.214 s
Overshoot 1.37 %
Final Position Error −0.634 mm
Sensor Difference 0.001 mm
Peak PID Command 9.945 V

50mm Step Response

50 mm Ramp Tracking (0.01 m/s, ±10 V)

Metric Value
Max Tracking Error 6.074 mm
RMS Tracking Error 4.444 mm
Steady-state RMS Error 1.612 mm
Peak Actuator Command 0.739 V (no saturation)

50mm Ramp Tracking


Visualization

The final MATLAB visualization (animate_final_stage.m) renders a 4-panel real-time animation:

Panel Content
Physical Stage Motor, rail, lead screw, moving platform with position markers
Position Tracking Reference vs true vs measured position
Tracking Error Position error in mm over time
Controller Output PID command and actuator command vs ±10 V limits

Real-time Visualization


Project Structure

linear-stage-pid-control/
├── README.md
├── linear_stage_model.m              # Plant + PID setup, analysis, and simulation script
├── linear_stage_model_simulink.slx   # Simulink model (full closed-loop simulation)
├── animate_final_stage.m             # 4-panel real-time MATLAB visualization
├── figures/                          # Exported plots and screenshots
│   ├── simulink_model.png
│   ├── controller_comparison.png
│   ├── controller_commands.png
│   ├── step_50mm.png
│   ├── ramp_50mm.png
│   ├── visualization.png
│   └── visualization_demo.gif
└── slprj/                            # Simulink build artifacts (auto-generated)

Getting Started

Prerequisites

  • MATLAB
  • Simulink
  • Control System Toolbox

Running the Model

  1. Clone the repository

    git clone git@github.com:<your-username>/linear-stage-pid-control.git
    cd linear-stage-pid-control
  2. Open MATLAB and set the working directory to the repo root.

Ramp Tracking Setup

Configure ramp parameters before simulation:

target_position = 0.05;    % 50 mm
ramp_slope      = 0.01;   % m/s  (reaches target in 5 s)
buffer_time   = 6;       % s

ramp_time     = target_position / ramp_slope;   
sim_stop_time = ramp_time + buffer_time;       
  1. Run the setup and simulation script:

    run('linear_stage_model.m')
  2. Launch the real-time visualization after simulation:

    run('animate_final_stage.m')

Experiments Covered

Experiment Description
Plant Analysis Poles, zeros, open-loop step response
Controller Comparison P / PI / PD / PID with gain sweeps
Load Robustness Jeq ×0.8 / ×1.0 / ×1.3
Friction Robustness beq ×0.5 / ×1.0 / ×2.0
Actuator Saturation ±10 V nominal · ±0.5 V severe
Disturbance Rejection Input disturbance, max deviation 0.095 mm
Sensor Noise Gaussian noise, std 1.227 mm
Quantization Quantization-only vs combined noise
Step Positioning 50 mm step, ±10 V
Ramp Tracking 50 mm ramp at 0.01 m/s, ±10 V
Real-time Visualization 4-panel animated MATLAB figure

Modeling Limitations

The model is a linear approximation. Effects not included:

  • Coulomb / static friction
  • Lead-screw backlash and efficiency
  • Motor current limiting and thermal behavior
  • Structural flexibility
  • Exact torque-speed curve

Possible future extensions: anti-windup, feedforward, friction identification, hardware implementation.

About

PID-based DC motor linear stage position control and trajectory tracking using MATLAB/Simulink

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages