Skip to content

ebrahimabdelghfar/Rotary-Inverted-Pendulum

Repository files navigation

Software used

Matlab 2020a

Introduction

This project involves the design and implementation of a rotary inverted pendulum system using Arduino and Simulink. The system consists of a motor with a built-in encoder and an incremental rotary encoder for measuring the angle of the pendulum. The controller for stabilizing the system is implemented using an LQR controller.

Requirments

  • Arduino uno
  • Incremental encoder
  • motor with built-encoder
  • 12V Battery 2200 mah
  • H-bridge L298N 2A
  • Breadboard

Steps

  1. Desgin the system and assemble it
  2. Parameter estimaton for the motor to get the the motor coffecient
    1. give the motor a $\pm 12V$ signal
    2. Collect of the $V$ and $\frac{rad}{sec}$ in an excel file
    3. Import the reading in the Matlab
    4. Build a simulated model using simscape library as the following fig: image
    5. Using the Parameter-Estimator app of simulink to predict the measurments between simulated and real data
  3. Get the gain of LQR by using the mathmatical model built on Matlab
  4. Use the hardware in loop as following :image

Note

  • When you work with the code and model you must include the repo in Matlab path
  • Include the encoder function
  • Enter the motor parameter in workspace

State Space Model

image

image image2

Electrical circuit

Schematic_New Project_2023-01-02

Mechanical Model

image image2

Video

Inverted.pendulum.mp4

Limitations

There is no swing up functionality in the current model. Additionally, there is some vibration present in the system. The system is able to work within an angle range of +20 to -20 degrees, beyond which it will turn off until the pendulum is returned within this range.

Usage

To use the system, connect the Arduino board to a computer and open the Simulink model. Run the model and the system will start operating. The angle of the pendulum and the control signal can be monitored in the scope blocks in the model.

Files

The repository includes the following files:

  • MotorParameter.mat "which contain the esimtated motor parameter using parameter estimator tool"
  • MotorModelEstimated.slx "A simulink file that contain a simscape model for the motor to be used in parameter estimation"
  • model_inverted_rotary_pendulumV4.mlx "A live matlab script at which the model is applied ,in addition to be used in getting the response and stability gains"
  • RotaryInvertedPendulumHardwareInLoop.slx "A simulink Hardware in loop code for arduino uno that was programmed using simulink"
  • Driver guide "folder that contain the simulink's arduino encoder driver in it"

Credits

This project was developed by Ebrahim Abdelghfar and Hesham Hesham with the help of the following papers and videos: