RAS 550 — Final Project

Closed-Loop DC Motor
Position Control

Simulink model-based design with real-time Arduino deployment — comparing P, PD, and PID controllers for sinusoidal trajectory tracking.

↓ scroll

System Overview

A closed-loop position control system built around a DC motor with quadrature encoder feedback, deployed in real-time on an Arduino via Simulink code generation.

┌──────────────┐    ┌───────────┐    ┌────────────┐    ┌─────────────┐
│  Sine Wave   │───▶│   Error   │───▶│ Controller │───▶│ Motor Drive │
│  Reference   │    │ e = θref  │    │ (P/PD/PID) │    │ PWM + Dir   │
│  Generator   │    │   − θmeas │    │            │    │ (H-Bridge)  │
└──────────────┘    └───────────┘    └────────────┘    └──────┬──────┘
                          ▲                                    │
                          │         ┌──────────────┐           │
                          └─────────│  Quadrature  │◀──────────┘
                                    │   Encoder    │      DC Motor
                                    └──────────────┘
01

Reference Generation

Sine wave block producing a configurable position trajectory with adjustable amplitude and frequency.

02

Encoder Interface

Reads quadrature A/B channels, converts raw counts to degrees or revolutions using gear ratio.

03

Error Computation

Subtracts measured position from reference: e(t) = θ_ref(t) − θ_meas(t).

04

PID Controller

Configurable P, PD, or PID with output conditioning (saturation, absolute value) for PWM bounds.

05

Motor Drive Logic

PWM duty cycle controls speed/torque. Two digital direction pins drive the H-bridge for bidirectional control.

06

Arduino Deployment

Simulink auto-generates code, compiles, and flashes to the Arduino for real-time closed-loop execution.

Controller Configurations

Nine configurations were tested across P, PD, and PID strategies, varying gains, data types, sample times, and reference frequencies.

TypeKpKdKiDataTs (s)Freq (Hz)
PD51.5single0.010.2
PD91single0.010.2
PD91double0.0050.2
P3double0.0050.2
P4single0.010.1
P3single0.010.1
PID31.50.5single0.010.1
PID321single0.010.1
PID321double0.0010.1

Performance Comparison

P Control

Tracks the general sinusoidal shape but shows significant phase lag and steady-state error, especially at higher reference frequencies.

PD Control

Derivative action reduces phase lag and sharpens transient response. Higher Kp with moderate Kd produces the tightest trajectory tracking.

PID Control

Integral action eliminates steady-state error. Best performance at Kp=3, Kd=2, Ki=1 with double precision and Ts=0.001s. Slight overshoot in the negative region.

Video Demonstration

Video not loading? Watch on Google Drive →

Requirements

Hardware

  • Arduino board
  • DC motor with quadrature encoder
  • H-bridge motor driver
  • Encoder A/B channels on digital pins
  • PWM output + 2 direction pins

Software

  • MATLAB / Simulink
  • Simulink Support Package for Arduino
  • Simulink Coder