· Hankyu Kim · Project  · 1 min read

Dynamic Compensation MATLAB Code

I wrote some tutorial code of pd controller, pi controller, lead compensator, and lag compensator in MATLAB. Feel free to use!!

I wrote some tutorial code of pd controller, pi controller, lead compensator, and lag compensator in MATLAB. Feel free to use!!

PD Controller Code:

Kp = 2;
Kd = 0.5;

s = tf('s');
C = Kp + Kd*s;

figure;
bode(C);
grid on;
title('PD Controller: Bode Plot');

Lead Compensator Code:

K = 1;
tau = 0.5;
alpha = 0.1;

s = tf('s');
C = K * (tau*s + 1) / (alpha*tau*s + 1);

figure;
bode(C);
grid on;
title('Lead Compensator: Bode Plot');

PI Controller Code:

Kp = 2;
Ki = 1;

s = tf('s');
C = Kp + Ki/s;

figure;
bode(C);
grid on;
title('PI Controller: Bode Plot');

Lag Compensator Code:

K = 1;
tau = 0.5;      
beta = 10;      

s = tf('s');
C = K * (tau*s + 1) / (beta*tau*s + 1);

figure;
bode(C);
grid on;
title('Lag Compensator: Bode Plot');
Back to Blog

Related Posts

View All Posts »
FABRIK

FABRIK

FABRIK(A Fast Iterative Solver for the Inverse Kinematics Problem) is a heuristic, iterative inverse kinematics solver that avoids complex matrix operations and singularities, providing smooth motion and fast convergence for robotic chains.

Numerical Inverse Kinematics

Numerical Inverse Kinematics

Numerical inverse kinematics can iteratively solve for joint angles to reach a desired end-effector position using gradient descent with the Jacobian pseudo-inverse, suitable for planar manipulators and more complex robotic arms.

Analytical Inverse Kinematics

Analytical Inverse Kinematics

This post demonstrates how to compute the inverse kinematics of a 2-link planar robot arm using the Law of Cosines, providing a step-by-step guide for analytical solutions.

DH Parameters

DH Parameters

Denavit-Hartenberg (DH) parameters provide a systematic way to describe robot geometry, linking kinematics, joints, and links for practical robot modeling and control.