This repo demonstrates the control of an inverted pendulum. This system approximated as a linear system about the operating point (up-right vertical position). Control gains can either be chosen to satisfy desired closed loop system poles or can be choosen to minimze a cost function.
- Set MATLAB directory to path containing all files in repo
- Run the script titled: pendulumAssembly_DataFile1.m
- Run the first section of the script titled: Script_SlidingPendulum.m
- a) To choose feedback gains that satisfy desired closed loop poles requirements run the second section. You can change the desired poles by changing the values of the variable named 'eigs.'
- b) To choose feedback gains that minimize a cost function, run the third section of Script_SlidingPendulum.m
The system has 4 states which are defined in the following order:
- Linear Position of Cart
- Linear Velocity of Cart
- Angular Position of Pendulum
- Angular Velocity of Pendulum
The MATLAB function 'place' is used to select gains such that the feedback law u=K*(Xdesired-X) places the poles of the closed loop system at the locations specified by the variable 'eigs'
The gains can also be calculated so that a cost function of system states is minimized with respect to some criteria. The cost function is specified as follows: J=QXerror+Ru. Q is a diagonal matrix containing weights for error in each state. R is chosen as a constant because this system only has one control input. The MATLAB function 'lqr' is used to determine the gain values.
High Weight for Cart Position | High Weight for Pendulum Position |
---|---|
High Weight for Cart Position | High Weight for Pendulum Position |
---|---|