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.
- Overview
- System Architecture
- System Parameters
- Controller Design
- Key Results
- Visualization
- Project Structure
- Getting Started
- Experiments Covered
- Modeling Limitations
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
Reference → Error → PID Controller → Actuator Saturation (±10 V)
← Sensor (noise + quantization) ← DC Motor + Lead Screw → Platform Position
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 |
| 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 |
| 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.
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).
| 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 |
| 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) |
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 |
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)
- MATLAB
- Simulink
- Control System Toolbox
-
Clone the repository
git clone git@github.com:<your-username>/linear-stage-pid-control.git cd linear-stage-pid-control
-
Open MATLAB and set the working directory to the repo root.
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; -
Run the setup and simulation script:
run('linear_stage_model.m') -
Launch the real-time visualization after simulation:
run('animate_final_stage.m')
| 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 |
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.





