Skip to content

Single-axis rigid-body attitude controller with viscous damping built in Simulink . PD/PID with anti-windup, robustness to ±10% moment of inertia, and resistance to applied disturbance torques. Annotated plots included.

License

Notifications You must be signed in to change notification settings

fcirulli/attitude-pd

Repository files navigation

Attitude PD / PID Controller (Simulink)

Goal: Create angle command controller with zero overshoot + robustness and disturbance resistance

Plant: Rigid axis with damping (viscous, against applied torque)

$\dot{\theta}=\omega,\quad I\dot{\omega}=\tau-b,\omega$

Parameters: I=0.05 kg·m², b=0.002 N·m·s. Actuator max: max_tau

Controller

  • PD tune for near-critical damping, next add a small integral gain to reject bias
  • Preset gains used in figures: Kp=2.4, Kd=1.35, Ki=0 (PD controller)
  • Disturbance demo presets: Ki=0.03 with anti-windup (back-calculation)

Tuning method I used: construct closed loop using dynamics + control eqns, match to second-order target, solve for gains.

Dynamics: $\dot{\theta}=\omega,\quad I\dot{\omega}=\tau-b,\omega$

Control: $\tau = K_p(\theta_c-\theta) - K_d,\dot{\theta}$

Closed loop (PD)

$$ \ddot{\theta} + \frac{b+K_d}{I},\dot{\theta} + \frac{K_p}{I},\theta = \frac{K_p}{I},\theta_c $$

Match to second-order target (approx. critical damping, $\zeta\ = 1$)

$$ \ddot{\theta} + 2\zeta,\omega_n,\dot{\theta} + \omega_n^2,\theta = \omega_n^2,\theta_c $$

So gains are:

$$ K_p = I,\omega_n^2,\qquad K_d = 2,\zeta,I,\omega_n - b $$

I picked $\omega_n$ for desired speed (using torque limit), then did minor tweaks by hand

Note d/dt($\theta_c$) = 0 as goal point is held constant.

How to run

  1. Open attitude_pd.slx
  2. Edit Model Workspace parameters:
    My values: I=0.05, b=0.002, Kp=2.4, Kd=1.35, Ki=0, theta_step=deg2rad(30), max_tau=0.02
  3. Run
  4. Robustness check: Set I to desired values (I chose 0.045, 0.055) and rerun
  5. Disturbance check: connect tau_dist (disturbance torque) step at desired time and value (e.g. 0.018 N·m, t = 4 s)

Note: use either the internal output limiter or external saturation block (not both). Limits: ±max_tau

Observations

  • Without disturbance torque, a PD controller works well (0 overshoot, Ki = 0)
  • With disturbance torque, select nonzero Ki (PID), and enable back calculation anti windup for no overshoot

Results

  • Block setup: model
  • Theta vs. commanded theta: step
  • Commanded torque: tau.
  • Robustness (±10% moment of inertia): robustness.
  • Disturbance Torque Applied: PD (notice offset) and PID+AW (no more offset):
    pd pid_aw

Tested with Simulink R2025A

License: MIT

About

Single-axis rigid-body attitude controller with viscous damping built in Simulink . PD/PID with anti-windup, robustness to ±10% moment of inertia, and resistance to applied disturbance torques. Annotated plots included.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published