User Tools

Site Tools


pid_vs_lqr_ballandbeam

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
pid_vs_lqr_ballandbeam [2016/07/13 14:41] joaomatospid_vs_lqr_ballandbeam [2016/07/13 14:59] (current) joaomatos
Line 21: Line 21:
 ===== Parts List and Source ===== ===== Parts List and Source =====
  
-Parts List.+[[ballandbeam_parts|Parts List]]
  
  
Line 36: Line 36:
 ===== System Modeling ===== ===== System Modeling =====
  
-. System Modeling.+[[ballandbeam_modelling|System Modeling.]]
  
  
Line 43: Line 43:
 ===== Programming ===== ===== Programming =====
  
-. Programming+[[ballandbeam_code|Programming]]
  
  
Line 49: Line 49:
  
  
-**SUMMARY** 
  
-PID CONTROL: 
-  #1:Ball and Beam Transfer Function Derivation. 
-  #2:Motor Transfer Function Derivation. 
-  #3:Motor system modeling on Simulink. 
-  #4:Simulating the whole system with PID Control on Simulink. 
-  #5:Working Video / Simulating Disturbance. 
-  #6:Comparison Simulink vs Real System. 
-  #7:NXT CODE. 
  
-LQR CONTROL:  
-  #8:State Space representation. 
-  #9:Motor Parameters. 
-  #10:LQR [A],[B],[Q],[R] matrices.  
-  #11:Matlab code to find [K] matrix. 
-  #12:LQR Control results. 
-  
-PID VS LQR CONTROL: 
-  #13:PID vs LQR Control results. 
- . 
-  
- . 
-** __PID CONTROL__ ** 
  
- We can analyze the whole system into two distinct transfer functions , one for the ball and beam , and one for the motor. After , we can analyze the whole system putting these two transfer functions together in a block diagram. 
- 
- ** __Ball and Beam Transfer Function Derivation__** 
-{{ ::ball_system.jpg?direct&400 |}} 
- 
- Analyzing the equilibrium we have: 
- 
- {{::ball_derivation_1.jpg?direct&500|}} 
- 
- {{:ball_derivation_2.jpg?direct&500|}} 
- 
- {{::ball_derivation_3.jpg?direct|}} 
- 
- 
-** __Motor Transfer Function Derivation__ ** 
- 
- One easy way to get the motor's transfer function is to plot and analyze its response to an input , and by a graphical analysis get the parameters to derive its transfer function. We can program an algorithm to read and save ( using file saving functions ) the motor position during its operation. The following code was used to save and after plot the motor response until it get to the desired angle.The code makes the motor runs from 0 to 130 degrees, controlled by PID using the function " PosRegEnable " . 
- 
-{{::motor_code_save.jpg?direct|}} 
- 
- Plotting the results we have: 
- 
- {{::motor_angle_vs_time.jpg?direct|}} 
- 
- By the graphic response , we can assume the motor system as a second order system (because of the oscillatory and overshoot response). As known , a second order is characterized by two parameters , natural frequency (σ) and damping ratio (ξ).We can get these parameters by the following steps: 
-  
- {{:motor_formulas_1.jpg?direct|}} 
- 
- {{::motor_formulas_2.jpg?direct|}} 
-   
- {{:motor_formulas_3.jpg?direct|}} 
-   
- We know that a second order transfer function is:  
- 
- {{:motor_formulas_4.jpg?direct|}} 
- 
- So the motor's transfer function is: 
-   
- {{:motor_formulas_5.jpg?direct|}} 
- 
-** __Motor system modeling on Simulink__ ** 
- 
- We can simulate the motor system on Simulink and compare the result to the experimental result , to verify if the derivation is correct. 
- 
- {{::motor_response.jpg?direct|}} 
- 
- Comparing both responses we can see that the derivation was correct. 
- 
- {{::comparison_motor.jpg?direct|}} 
- 
-** __SIMULATING THE WHOLE SYSTEM WITH PID CONTROL__ ** 
- 
- We can simulate the whole system using the ball and beam together with the motor's transfer functions to simulate the real system. We can apply the PID control as well using Simulink. The block diagram and some results are shown bellow. 
- 
- {{::ball_and_beam_system.jpg?direct|}} 
- 
- Simulation a disturbance on the system ( ball goes to 30 mm ) , we can see how the system will react in order to make the final ball position 0 mm. 
- 
- **Using only proportional control ( system is unstable ).** 
- 
- {{::proportional_only.jpg?direct|}} 
- 
- **Just to ilustrate that the system can be controlled using PD control, with Kp=3 and Kd=3 .We have 17,5 seconds to reject a 120 mm disturbance ( moving the ball 120mm from the center of the beam) ** 
- 
- {{::pd_control.jpg?direct|}} 
- 
- ** Working Video / Simulating Disturbance **  
- 
- {{youtube>c2Q4lI70duc?medium}} 
- 
- On the video ,was simulated first a heavy disturbance , and then two small disturbances.  
- 
- ** Comparison Simulink vs Real System ** 
- 
- Introducing the a file saving function , the ball position over the time can be saved to a file and then plotted using an excel spreadsheet. Using KP= 1 and KI=0 and KD=0.76 and the disturbance shifting the ball to 176mm away from the setpoint.  
- 
- {{::simulink_and_real.jpg?direct|}} 
- 
-** NXT CODE ** 
- 
- {{:code1.jpg?direct|}} 
- {{::code2.jpg?direct|}} 
- {{::code_3.jpg?direct|}} 
- {{::code5.jpg?direct|}} 
- {{::code_6.jpg?direct|}} 
- 
-** TUNING THE CODE ** 
- 
- After introducing the file saving function and the necessary commands to get the data , the system response was slowed down. ( oscillating more than before ). So i made some tuning:  
-  * KP=1 and KD=0.60 
-  * No waiting time inside the if statements 
-  * 50ms waiting before starting the control loop again. 
- 
- The new result is: 
- 
- {{::the_last_response.jpg?direct|}} 
- 
- {{youtube>Jp9xxLjVyi0?medium}} 
- 
- . 
- 
- . 
-  
-** __LQR CONTROL__ ** 
- 
- {{::1_lqr.jpg?direct|}} 
- {{::2_lqr.jpg?direct|}} 
- {{::4_lqr.jpg?direct|}} 
- {{::5_lqr.jpg?direct|}} 
- {{::6_lqr.jpg?direct|}} 
- {{::7_lqr.jpg?direct|}} 
- {{::8_lqr.jpg?direct|}} 
- {{::9_lqr.jpg?direct|}} 
- {{::10_lqr.jpg?direct|}} 
- {{::11_lqr.jpg?direct|}} 
- {{::12_lqr.jpg?direct|}} 
- {{::13_lqr.jpg?direct|}} 
- {{::14_lqr.jpg?direct|}} 
- {{::15_lqr.jpg?direct|}} 
- {{::16_lqr.jpg?direct|}} 
- {{::17_lqr.jpg?direct|}} 
- {{::18_lqr.jpg?direct|}} 
- 
- . 
- 
- . 
- 
-** __PID VS LQR CONTROL__ ** 
- 
- Analyzing a 176mm disturbance rejection , we have (PID first LQR second):  
-  
-*note here that both methods can show pretty similar results , hand-tuning the gains after the initial guess. The PID version of the controler was intended to stop the ball fast , the LQR version of the controller was intended to stop the ball without overshooting too much. Again , both methods can be adjusted to control the overshoot or the rise time. 
-  
- {{::comparison.jpg?direct|}} 
-  
- It's difficult to make a comparison between the PID and LQR control methods , both can be adjusted by hand after the initial guess and can show satisfactory results.However , the main advantage of using LQR on this case is that the energy input can be controlled (at the [R] matrix ). Both methods requires a hand tuning after the initial guess to achieve the desired response. 
- 
-  
pid_vs_lqr_ballandbeam.1468446107.txt.gz · Last modified: by joaomatos