Capstone Exercise: Closed-Loop Mechatronic System
This capstone combines mechanics, sensing, actuation, control, safety, and commissioning. The goal is a small axis or rotary mechanism that follows a setpoint using feedback and fails predictably when something goes wrong.
Learning Objectives
By the end of this exercise, you should be able to assemble a simple closed-loop mechanism, implement a sampled controller, verify sensor and actuator polarity, tune performance, test faults, and produce commissioning evidence.
Prerequisites
You should already be comfortable with:
- force, torque, speed, and power calculations;
- sensor calibration;
- DC, stepper, or servo motor selection;
- driver current limits and protection;
- feedback control and PID basics;
- machine safety and staged commissioning.
Concrete Task
Build or simulate a one-axis system:
- a DC motor with encoder, or a stepper with position sensor, or a simulated plant;
- a position setpoint in counts or millimeters;
- a controller that runs at a fixed sample time;
- limit checks and an emergency-stop input;
- logging of setpoint, position, error, output, and fault state.
The system must move from one position to another, settle within a defined error band, and stop safely when a limit or emergency input is triggered.
Reference Implementation
The following Python simulation is buildable and can be used before connecting hardware. It models a simple motor axis and a PID-like controller with output limiting.
import math
DT = 0.01
STEPS = 600
SETPOINT = 1000.0
KP = 0.9
KI = 0.6
KD = 0.03
MAX_CMD = 12.0
ERROR_BAND = 5.0
position = 0.0
velocity = 0.0
integral = 0.0
last_error = 0.0
fault = None
def clamp(value, low, high):
return max(low, min(high, value))
for n in range(STEPS):
t = n * DT
estop = False
limit_active = position < -20 or position > 1200
if estop:
fault = "ESTOP"
elif limit_active:
fault = "LIMIT"
error = SETPOINT - position
derivative = (error - last_error) / DT
if fault:
command = 0.0
integral = 0.0
else:
integral = clamp(integral + error * DT, -200, 200)
command = clamp(KP * error + KI * integral + KD * derivative, -MAX_CMD, MAX_CMD)
# Simple plant: command accelerates the axis, friction slows it.
acceleration = 4.0 * command - 2.5 * velocity
velocity += acceleration * DT
position += velocity * DT
last_error = error
if n % 50 == 0:
print(f"{t:4.2f}s pos={position:7.1f} err={error:7.1f} cmd={command:6.2f} fault={fault or '-'}")
settled = abs(SETPOINT - position) <= ERROR_BAND
print("PASS" if settled and not fault else "CHECK", f"final position={position:.1f}")
For hardware, replace the plant update with encoder reading and PWM or driver command output. Keep the same state, limit, and logging structure.
Expected Behavior
A correct implementation should:
- start with actuators disabled during checks;
- read position with the correct sign and scale;
- command motion toward the setpoint, not away from it;
- limit output to the driver and mechanism rating;
- reduce error over time without sustained oscillation;
- stop command output immediately on fault;
- require deliberate reset after a fault.
Verification Steps
- Inspect mechanics, wiring, guards, and emergency stop before power.
- Verify sensor counts increase in the expected direction by moving the axis by hand.
- Jog the actuator at low command and verify direction.
- Run the controller with a small setpoint step and output limit.
- Log setpoint, position, error, command, and fault state.
- Measure overshoot, settling time, steady error, and peak current.
- Trigger limit and emergency inputs and confirm command output goes safe.
- Repeat after power cycling to confirm no unexpected restart.
Common Failure Symptoms
- Runs away from setpoint: motor polarity or encoder sign is inverted.
- Oscillates: proportional gain too high, derivative too low, loose mechanics, or sample time too slow.
- Never reaches target: output limit too low, friction too high, integral disabled, or mechanical binding.
- Resets under load: supply sag, driver overcurrent, wiring resistance, or EMI.
- Fault will not clear: latched condition still active or reset sequence is incomplete.
Debugging Guidance
Start open-loop at low output before closing the loop. Confirm units and signs. Plot error over time instead of judging by sound. Tune one parameter at a time: begin with small (K_P), add damping or (K_D), then add limited (K_I) only if steady-state error matters. Keep integral clamping to prevent windup.
Extension Challenge
Add a trapezoidal motion profile so the setpoint changes gradually. Then compare peak current, overshoot, and settling time against a direct step command.
Concise Explained Solution
The reference implementation closes the loop around position. Each sample computes error, derivative, and a clamped integral term. The command is limited to the safe actuator range. Faults force command to zero and clear the integral so the controller cannot restart with stored windup. A passing system reaches the setpoint within the error band while keeping fault behavior deterministic.
Summary
The capstone is complete when the axis moves correctly, settles to target, handles faults safely, and has commissioning evidence. A working demo is not enough; the verification record is part of the engineering deliverable.
Further Reading
- Franklin, Powell, and Emami-Naeini, "Feedback Control of Dynamic Systems."
- IEC 60204-1, electrical equipment of machines.
- Texas Instruments, "Motor Control Compendium."