Skip to content

gatetub/selfbalancing

Repository files navigation

Two-Wheeled Self-Balancing Robot (TWSR) – Simulink Simulation

High-performance Simulink control achieving <2β€―s settling time and <5% overshoot using cascaded PID with Kalman filtering.


πŸ› οΈ Control System Architecture

β­• Cascaded PID Structure

Outer Loop: Tilt Regulation (Slow Loop)

  • Sensors: MPU6050 IMU
  • Processing: Kalman Filter for angle estimation
  • Controller: PID (regulates tilt angle to setpoint)

Data Flow:

MPU6050 IMU β†’ Kalman Filter β†’ PID (Tilt)
      ↓
Error = Setpoint (0Β°) – Filtered Tilt Angle
      ↓
Output: Desired Wheel Speed Reference

Inner Loop: Wheel Speed Tracking (Fast Loop)

  • Sensors: HC-020K Wheel Encoder
  • Controller: PID (controls wheel speed)

Data Flow:

Wheel Encoder β†’ PID (Wheel Speed)
       ↓
Error = Reference RPM – Actual RPM
       ↓
Output: TB6600 Stepper Driver Signal

🧩 Simulink Model Features

  • 3-DOF Plant: Tilt, forward/backward, and heading control dynamics
  • Kalman Filtering: Fuses gyro + accelerometer, minimizes drift
  • PID Autotune: Integrates Simulink PID Tuner for automatic gain selection
  • Performance Metrics: Built-in step response plots for rise time/overshoot analysis

πŸ“Š Simulation Results

Metric Target Achieved
Settling Time <3β€―s 1.8β€―s
Overshoot <10% 4.2%
Rise Time <1β€―s 0.6β€―s
Steady-State Error <2Β° 0.8Β°

πŸš€ How to Run the Simulation

  1. Open the Main Model
    open('cascaded_pid.slx')
  2. Auto-Tune the PID Controllers
    pidTuner('outer_tilt_controller')
    pidTuner('inner_wheel_controller')
  3. Run Step Response & Plot Results
    sim('cascaded_pid')
    plot(simout.time, simout.signals.values)

πŸ“ Repository Structure

simulink/
β”œβ”€β”€ cascaded_pid.slx         # Main control system model
β”œβ”€β”€ kalman_filter.slx        # IMU sensor fusion subsystem
β”œβ”€β”€ pid_tuning.slx           # Step response & tuning model
└── step_response_plots.m    # MATLAB visualization script

πŸ”§ PID Tuning Workflow

  1. Set initial controller gains, simulate the step response
  2. Analyze rise time, overshoot, settling time
  3. Tune parameters:
    • Kp: Responsiveness
    • Ki: Steady-state accuracy
    • Kd: Damping
  4. Iterate until settling time <2β€―s, overshoot <5%

Requirements:


Copy-paste ready β€” Showcase your Simulink-based self-balancing control system in seconds.

For technical reference see Ideation Document – Technical Details for Proposed Robot.

About

late upload from may

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published