루덴스코드 Blog

Ball and Beam problem using PID Control

In this digital control version of the ball and beam experiment, we are going to use the PID control method to design the digital controller. If you refer to the Ball and Beam Modeling page, the open-loop transfer function was derived as
사용자 삽입 이미지
.....m........mass of the ball...............0.11 kg
.....g........gravitational acceleration.....9.8 m/s^2
.....d........lever arm offset...............0.03 m
.....L........length of the beam.............1.0 m
.....R........radius of the ball.............0.015 m
.....J........ball's moment of inertia.......9.99e-6 kgm^2
.....R(s).....ball position coordinate (m)
.....theta(s).servo gear angle...............0.25 rad

The design criteria for this problem are:
  • Settling time less than 3 seconds
  • Overshoot less than 5%
Digital PID controller
If you refer to any of the PID control problem for continuous systems, the PID transfer function was expressed as
사용자 삽입 이미지
As you noticed the above transfer function was written in terms of s. For the digital PID control, we use the following transfer function in terms of z.
사용자 삽입 이미지
Discrete transfer function
The first thing to do here is to convert the above continuous system transfer function to discrete transfer function. To do this, we are going to use the Matlab function called c2dm. To use this c2dm, we need to specify four arguments: numerator and denominator matrices, sampling time (Ts), and the 'method'. You should already be familiar with how to enter numerator and denominator matrices. The sampling time should be smaller than 1/(30*BW) sec, where BW is the closed-loop bandwidth frequency. The method we will use is the zero-order hold ('zoh'). Assuming that the closed-loop bandwidth frequency is around 1 rad/sec, let the sampling time be 1/50 sec/sample. Now we are ready to use c2dm. Enter the following commands to an m-file.

.....m = 0.111;
.....R = 0.015;
.....g = -9.8;
.....L = 1.0;
.....d = 0.03;
.....J = 9.99e-6;

.....K = (m*g*d)/(L*(J/R^2+m));   %simplifies input

.....num = [-K];
.....den = [1 0 0];

.....Ts = 1/50;

.....[numDz,denDz]= c2dm (num,den,Ts,'zoh')

Running this m-file in the Matlab command window gives you the following matrices.

.....numDz =
..........1.0e-0.4 *
..........0    0.4200    0.4200

.....denDz =
..........1    -2    1

From these matrices, the discrete transfer function can be written as
사용자 삽입 이미지
Open-loop response
Now we will observe the ball's response to a step input of 0.25 m. To do this, enter the following commands to an new m-file and run it in the command window. You should see the following response.

.....numDz = 0.0001*[0.42 0.42];
.....denDz = [1 -2 1];

.....[x] = dstep(0.25*numDz,denDz,251);
.....t=0:0.02:5;
.....stairs(t,x)
사용자 삽입 이미지
From this plot, it is clear that the open-loop system is unstable causing the ball to roll off from the end of the beam.

Proportianal Control
Now we will add the proportional control (Kp) to the system and obtain the closed-loop system response. For now let Kp equal to 100 and see what happens to the response. Enter the following commands to an new m-file and run it in the command window.

.....numDz = 0.0001*[0.42 0.42];
.....denDz = [1 -2 1];

.....Kp=100;
.....[numDzC,denDzC]=cloop (Kp*numDz,denDz);

.....[x] = dstep(0.25*numDzC,denDzC,251);
.....t=0:0.02:5;
.....stairs(t,x)
사용자 삽입 이미지
As you can see, the addition of proportional control does not make the system stable. You may try to increase the proportional gain (Kp) and confirm that the system remains unstable.

Proportional-Derivative control
Now we will add a derivative term to the controller. Keep the proportional gain (Kp) equal to 100, and let the derivative gain (Kd) equal to 10. Copy the following code to an new m-file and run it to view the system response.

.....numDz = 0.0001*[0.42 0.42];
.....denDz = [1 -2 1];
.....Kp=100;
.....Kd=10;
.....numpd = [Kp+Kd -(Kp+2*Kd) Kd];
.....denpd = [1 1 0];
.....numDnew = conv(numDz,numpd);
.....denDnew = conv(denDz,denpd);
.....[numDnewC,denDnewC] = cloop(numDnew,denDnew);
.....[x] = dstep(0.25*numDnewC,denDnewC,251);
.....t=0:0.02:5;
.....stairs(t,x)
사용자 삽입 이미지
Now the system is stable, but the rise time is too long. From the PID Tutorial page, we see that the increasing the proportional gain (Kp) will decrease the rise time. Let's increase the proportional gain (Kp) to 1000 and see what happens. Change Kp in the above m-file from 100 to 1000 and rerun it in the command window. You should see the following step response.
사용자 삽입 이미지
As you can see, all of the design requirements are satisfied. For this particular problem, no implementation of an integral control was needed. But remember there is more than one solution for a control problem. For practice, you may try different P, I and D combinations to obtain a satisfactory response.

Comment +0

Ball & Beam Problem Using the State-space Design Method

The state-space representation of the ball and beam example is given below:
사용자 삽입 이미지
Remember, unlike the previous examples where we controlled the gear's angle to control the beam and ball, here we are controlling alpha-doubledot. By doing this we are essentially controlling a torque applied at the center of the beam by a motor. Therefore, we do not need a gear and lever system.

The design criteria for this problem are:
  • Settling time less than 3 seconds
  • Overshoot less than 5%
To see the derivation of the state-space equations for this problem refer to the ball and beam modeling page.

If you are interested in running an animation of this example based on the control techniques used in the state-space tutorial please go to the Ball & Beam Animation Page after completing this tutorial.

Full-State Feedback Controller

We will design a controller for this physical system that utilizes full-state feedback control. A schematic of this type of system is shown below:
사용자 삽입 이미지
Recall, that the characteristic polynomial for this closed-loop system is the determinant of (sI-(A-BK)), where s is the Laplace variable. For our system the A and B*K matrices are both 4x4. Hence, there should be four poles for our system. In designing our full-state feedback controller we can move these poles anywhere we want.

For our design we desire an overshoot of less than 5% which corresponds to a zeta of 0.7 (please refer to your textbook for the relationship between overshoot and damping ratio). On a root locus this criterion is represented as a 45 degree line emanating from the origin and extending out into the left-half plane. We want to place our poles on or beneath this line. Our next criterion is a settling time less than 3 seconds, which corresponds to a sigma = 4.6/Ts = 4.6/3 = 1.53, represented by a vertical line at -1.53 on the root locus. Anything beyond this line in the left-half plane is a suitable place for our poles. Therefore we will place our poles at -2+2i and -2-2i. We will place the other poles far to the left for now, so that they will not affect the response too much. To start with place them at -20 and -80. Now that we have our poles we can use Matlab to find the controller (K matrix) by using the place command. Copy the following code to an m-file to model the system and find the K matrix:

NOTE: Matlab commands from the control system toolbox are highlighted in red.


.....m = 0.111;
.....R = 0.015;
.....g = -9.8;
.....J = 9.99e-6;

.....H = -m*g/(J/(R^2)+m);
         
.....A=[0 1 0 0
........0 0 H 0
........0 0 0 1
........0 0 0 0];
.....B=[0;0;0;1];
.....C=[1 0 0 0];
.....D=[0];

.....p1=-2+2i;
.....p2=-2-2i;
.....p3=-20;
.....p4=-80;

.....K=place(A,B,[p1,p2,p3,p4])

Run your m-file and you should get the following output for the K matrix:

.....place: ndigits= 15

.....K =
..........1.0e+03 *
..........1.8286    1.0286    2.0080    0.1040

After adding the K matrix, the state space equations now become:
사용자 삽입 이미지
We can now simulate the closed-loop response to a 0.25m step input by using the lsim command. Add the following to your m-file:

.....T = 0:0.01:5;                  
.....U = 0.25*ones(size(T));             
.....[Y,X]=lsim(A-B*K,B,C,D,U,T);     
.....plot(T,Y)

Run your m-file and you should get the following plot:
사용자 삽입 이미지
From this plot we see that there is a large steady state error for which we will need to add reference input (explained in next section). However, the overshoot and settling time criteria are met. If we wanted to reduce the overshoot further than we would make the imaginary part of the pole smaller than the real part. Also, if we wanted a faster settling time we would move the poles further in the left-half plane. Feel free to experiment with the pole positions to see these trends.

Reference Input
Now we want to get rid of the steady-state error. In contrast to the other design methods, where we feedback the output and compare it to the reference input to compute an error, with a full-state feedback controller we are feeding back both states. We need to compute what the steady-state value of the states should be, multiply that by the chosen gain K, and use a new value as our reference for computing the input. This can be done by adding a constant gain Nbar after the reference. The schematic below shows this relationship:
사용자 삽입 이미지
Nbar can be found using the user-defined function rscale (copy it to the directory that your m-file is in). Copy the following to your m-file and run it to view the step response with Nbar added.

.....Nbar=rscale(A,B,C,D,K)

.....T = 0:0.01:5;                  
.....U = 0.25*ones(size(T));             
.....[Y,X]=lsim(A-B*K,B*Nbar,C,D,U,T);     
.....plot(T,Y)

Note: Non-standard Matlab commands used in this example are highlighted in green.

Your output should be:

.....place: ndigits= 15
.....Nbar =
..........1.8286e+03
사용자 삽입 이미지
Now the steady-state error is gone and all the design criteria are satisfied.

Note: A design problem does not necessarily have a unique answer. Using this method (or any other) may result in many different compensators. For practice you may want to go back and try to change the pole positions to see how the system responds.

Comment +0

Ball & Beam Problem Using Frequency Response Method

The open-loop transfer function of the plant for the ball and beam experiment is given below:
사용자 삽입 이미지
The design criteria for this problem are:
  • Settling time less than 3 seconds
  • Overshoot less than 5%
To see the derivation of the equations for this problem refer to the ball and beam modeling page. A schematic of the closed loop system with a controller is given below:
사용자 삽입 이미지

Open-loop Bode Plot
The main idea of frequency based design is to use the Bode plot of the open-loop transfer function to estimate the closed-loop response. Adding a controller to the system changes the open-loop Bode plot, therefore changing the closed-loop response. Let's first draw the bode plot for the original open-loop transfer function. Create an m-file with the following code and then run it in the Matlab command window:

.....m = 0.111;
.....R = 0.015;
.....g = -9.8;
.....L = 1.0;
.....d = 0.03;
.....J = 9.99e-6;

.....K = (m*g*d)/(L*(J/R^2+m));   %simplifies input

.....num = [-K];
.....den = [1 0 0];

.....bode(num,den)

NOTE: Matlab commands from the control system toolbox are highlighted in red.


You should get the following Bode plot:
사용자 삽입 이미지
From this plot we see that the phase margin is zero. Since the phase margin is defined as the change in open-loop phase shift necessary to make a closed-loop system stable this means that our zero phase margin indicates our system is unstable. We want to increase the phase margin and we can use a lead compensator controller to do this. For more information on Phase and Gain margins please refer to the Frequency Response Tutorial.

Phase-Lead Controller
A first order phase-lead compensator has the form given below:
사용자 삽입 이미지

The phase-lead compensator will add positive phase to our system over the frequency range 1/aT and 1/T, which are called the corner frequencies. The maximum added phase for one lead compensator is 90 degrees. For our controller design we need a percent overshoot of 5, which corresponds to a zeta of 0.7. Generally zeta * 100 will give you the minimum phase margin needed to obtain your desired overshoot. Therefore we require a phase margin greater than 70 degrees.

To obtain "T" and "a", the following steps can be used.

1. Determine the positive phase needed:

      We need at least 70 degrees from our controller.

2. Determine the frequency where the phase should be added (center frequency):

      In our case this is difficult to determine because the phase vs. frequency graph in the bode plot is a flat line. However, we have a relation between bandwidth frequency (wbw) and settling time (refer to the Bandwidth Frequency page for this equation) which tells us that wbw is approximately 1.92 rad/s. Therefore we want a center frequency just before this. For now we will choose 1.

3. Determine the constant "a" from the equation below, this determines the required space between the zero and the pole for the maximum phase added.
사용자 삽입 이미지
.....where phi refers to the desired phase margin. For 70 degrees, a = 0.0311.

4. Determine "T" and "aT" from the following equations:
사용자 삽입 이미지
사용자 삽입 이미지
..... For 70 degrees and center frequency (w) = 1, aT = 0.176 and T = 5.67

Now, we can add our lead controller to the system and view the bode plot. Remove the bode command from your m-file and add the following:

.....k=1;
.....numlead = k*[5.67 1];
.....denlead = [0.176 1];

.....numl = conv(num,numlead);
.....denl = conv(den,denlead);

.....bode(numl,denl)

You should get the following bode plot:
사용자 삽입 이미지

You can see that our phase margin is now 70 degrees. Let's check the closed-loop response to a step input of 0.25m. Add the following to your m-file:

.....[numcl,dencl] = cloop(numl,denl);
.....t=0:0.01:5;
.....step(0.25*numcl,dencl,t)

You should get the following plot:
사용자 삽입 이미지
Although the system is now stable and the overshoot is only slightly over 5%, the settling time is not satisfactory. Increasing the gain will increase the crossover frequency and make the response faster. Make k = 5, your response should look like:
사용자 삽입 이미지
사용자 삽입 이미지
The response is faster, however, the overshoot is much too high. Increasing the gain further will just make the overshoot worse.

Adding More Phase
We can increase our phase-lead compensator to decrease the overshoot. In order to make the iterative process easier use the following program. Create an m-file and copy the function from your web-browser into it (make sure the function command starts in the first column of the m-file).

.....function[ ] = phaseball()

.....%define TF
.....m = 0.111;
.....R = 0.015;
.....g = -9.8;
.....L = 1.0;
.....d = 0.03;
.....J = 9.99e-6;

.....K = (m*g*d)/(L*(J/R^2+m));   %simplifies input

.....num = [-K];
.....den = [1 0 0];

.....%ask user for controller information
.....pm = input('Phase Margin?.......');
.....w  = input('Center Frequency?...');
.....k  = input('Gain?...............');

.....%view compensated system bode plot
.....pmr = pm*pi/180;
.....a = (1 - sin(pmr))/(1+sin(pmr));
.....T = sqrt(a)/w;
.....aT = 1/(w*sqrt(a));

.....numlead = k*[aT 1];
.....denlead = [T 1];

.....numl=conv(num,numlead);
.....denl=conv(den,denlead);
.....figure
.....bode(numl,denl)

.....%view step response
.....[numcl,dencl]=cloop(numl,denl);
.....t=0:0.01:5;
.....figure
.....step(0.25*numcl,dencl,t)

With this m-file you can choose the phase margin, center frequency, and gain. Run your m-file with the following values and you should see the plots below on your screen.

.....Phase Margin?.......80
.....Center Frequency?...1
.....Gain?...............1
사용자 삽입 이미지
사용자 삽입 이미지
The overshoot is fine but the settling time is just a bit long. Try different numbers and see what happens.

Using the following values the design criteria was met.

.....Phase Margin?.......85
.....Center Frequency?...1.9
.....Gain?...............2
사용자 삽입 이미지
사용자 삽입 이미지
Note: A design problem does not necessarily have a unique answer. Using this method (or any other) may result in many different compensators. For practice you may want to go back and change the added phase, gain, or center frequency.

Comment +0

Solution to the Ball & Beam Problem Using Root Locus Method

The open-loop transfer function of the plant for the ball and beam experiment is given below:

사용자 삽입 이미지
The design criteria for this problem are:
  • Settling time less than 3 seconds
  • Overshoot less than 5%

To see the derivation of the equations for this problem refer to the ball and beam modeling page. A schematic of the closed loop system with a controller is given below:

사용자 삽입 이미지

Open-loop Root Locus

The main idea of the root locus design is to estimate the closed-loop response from the open-loop root locus plot. By adding zeroes and/or poles to the original system (adding a compensator), the root locus and thus the closed-loop response will be modified. Let us first view the root locus for the plant in open loop. Create an m-file with the following Matlab code in order to model the plant and plot the root locus.

.....m = 0.111;
.....R = 0.015;
.....g = -9.8;
.....L = 1.0;
.....d = 0.03;
.....J = 9.99e-6;

.....K = (m*g*d)/(L*(J/R^2+m));   %simplifies input

.....num = [-K];
.....den = [1 0 0];

.....rlocus(num,den)

NOTE: Matlab commands from the control system toolbox are highlighted in red.

Now, run the m-file and you should see the following root locus plot:

사용자 삽입 이미지
As you can see the system has two poles at the origin which go off to infinity along the imaginary axes.

The design criteria can also be plotted onto the root locus using the sgrid command. This command generates a grid of constant damping ratio and natural frequency. The damping ratio and natural frequency were found using the following equation, which relates the them to our percent overshoot (PO) and settling time (Ts) requirements:

사용자 삽입 이미지
사용자 삽입 이미지
Note, that the equation with Ts is found by assuming settled is when the response remains within 2% of it's final value. From these equation damping ratio and natural frequency were found to be 0.7 and 1.9 respectively.

.....sgrid(0.70, 1.9)
.....axis([-5 5 -2 2])

사용자 삽입 이미지
The area between the two dotted diagnol lines represents locations where the percent overshoot is less than 5%. The area outside the curved line represents locations where the setttling time is less than 3 seconds. Note that no region of the plot falls within the design criteria shown be these lines. To remedy this and bring the root locus into the left-hand plane for stability we will try adding a lead-compensator to the system.

Lead Controller
A first order lead compensator tends to shift the root locus into the left-hand plane. For a more detailed description of lead compensators refer to the Lead & Lag Compensator Design page. A lead compensator has the form given below:

사용자 삽입 이미지
where, the magnitude of zo is less than the magnitude of po.

Now, let us add the controller to the plant and view the root locus. We will position the zero near the origin to cancel out one of the poles. The pole of our compensator will be placed to the left of the origin to pull the root locus further into the left-hand plane. Add the following lines of Matlab code to your m-file.

.....zo = 0.01;
.....po = 5;

.....numlead = [1 zo];
.....denlead = [1 po];

.....numl = conv(num,numlead);
.....denl = conv(den,denlead);

.....rlocus(numl,denl)
.....sgrid(0.70, 1.9)


Run your m-file in the Matlab command window and you should see the following:

사용자 삽입 이미지
Now, the branches of the root locus are within our design criteria.

Selecting a Gain
Now that we have moved the root locus into the left-hand plane, we may select a gain that will satisfy our design requirements. We can use the rlocfind command to help us do this. Add the following onto the end of your m-file.

.....[kc,poles]=rlocfind(numl,denl)

Go to the plot and select a point near those indicated by the cross mark on the plot below:

사용자 삽입 이미지
You should see in the Matlab command window something similar to the following (your numbers will be slightly different):


.....selected_point =
.....  -2.4988+ 1.2493i
 
.....kc =
.....   37.3131
 
.....poles =
.....  -2.4950+ 1.2493i
.....  -2.4950- 1.2493i
.....  -0.0101       


Now, we can plot the response with this gain.

Plotting the Closed-loop Response
This value of kc can be put into the system and the closed-loop response to a step input of 0.25 m can be obtained. Add the following lines to your m-file to perform this analysis.

.....numl2 = kc*numl;
.....[numcl,dencl] = cloop(numl2,denl);
.....t=0:0.01:5;
.....figure
.....step(0.25*numcl,dencl,t)

Run your m-file and you select a point on the root locus similar to the selected point above. The step response should look like the following:

사용자 삽입 이미지
From this plot we see that when a 0.25m step input is given to the system both the settling time and percent overshoot design criteria are met.
Note: A design problem does not necessarily have a unique answer. Using this method (or any other) may result in many different compensators. Try running your m-file several more times selecting a different point each time and study the effect this has on the step response. For practice you may also want to go back to the original open-loop root locus and try to find other ways to add zeros and poles to get a better response.

Comment +0

Solution to the Ball & Beam Problem Using PID Control

The open-loop transfer function of the plant for the ball and beam experiment is given below:

사용자 삽입 이미지
The design criteria for this problem are:
  • Settling time less than 3 seconds
  • Overshoot less than 5%

To see the derivation of the equations for this problem refer to the ball and beam modeling page.


Closed-loop Representation
The block diagram for this example with a controller and unity feedback of the ball's position is shown below:

사용자 삽입 이미지
First, we will study the response of the system shown above when a proportional controller is used. Then, derivative and/or integral control will be added if necessary.

Recall, that the transfer function for a PID controller is:

사용자 삽입 이미지

Proportional Control
The closed-loop transfer function for proportional control with a proportional gain (kp) equal to 100, can be modeled by copying the following lines of Matlab code into an m-file (or a '.m' file located in the same directory as Matlab)

.....m = 0.111;
.....R = 0.015;
.....g = -9.8;
.....L = 1.0;
.....d = 0.03;
.....J = 9.99e-6;

.....K = (m*g*d)/(L*(J/R^2+m));   %simplifies input

.....num = [-K];
.....den = [1 0 0];

.....kp = 1;
.....numP = kp*num;

.....[numc, denc] = cloop(numP, den)

NOTE: Matlab commands from the control system toolbox are highlighted in red.

You numerator and denominator should be:

.....numc =..... 
.....         0         0    0.2100

.....denc =
.....    1.0000         0    0.2100

Now, we can model the system's response to a step input of 0.25 m. Add the following line of code to your m-file and run it:

.....step(0.25*numc,denc)

You should get the following output:

사용자 삽입 이미지
As, you can see the addition of proportional gain does not make the system stable. Try changing the value of kp and note that the system remains unstable.

Proportional-Derivative Control
Now, we will add a derivative term to the controller. Copy the following lines of code to an m-file and run it to view the system's response to this control method.

.....m = 0.111;
.....R = 0.015;
.....g = -9.8;
.....L = 1.0;
.....d = 0.03;
.....J = 9.99e-6;

.....K = (m*g*d)/(L*(J/R^2+m));   %simplifies input

.....num = [-K];
.....den = [1 0 0];

.....kp = 10;
.....kd = 10;
.....numPD = [kd kp];

.....numh = conv(num, numPD);
.....[numc, denc] = cloop(numh, den);
.....t=0:0.01:5;
.....step(0.25*numc,denc,t)

Your plot should be similar to the following:

사용자 삽입 이미지
Now the system is stable but the overshoot is much too high and the settling time needs to go down a bit. From the PID tutorial page in the section on characteristics of P, I, and D controllers, we see that by increasing kd we can lower overshoot and decrease the settling time slightly. Therefore, make kd = 20 in your m-file and run it again. Your output should be:
사용자 삽입 이미지
The overshoot criterion is met but the settling time needs to come down a bit. To decrease the settling time we may try increasing the kp slightly to increase the rise time. The derivative gain (kd) can also be increased to take off some of the overshoot that increasing kp will cause. After playing with the gains a bit, the following step response plot can be achieved with kp = 15 and kd = 40:
사용자 삽입 이미지
As you can see from the above plot all the control objectives have been met without the use of an integral controller (settling time for this example is considered achieved when the response is less than 2% of it's final value). Remember, that for a control problem there is more than one solution for the problem.

Comment +0

VIA[CTM]

Modeling the Ball and Beam Experiment

Problem Setup

A ball is placed on a beam, see figure below, where it is allowed to roll with 1 degree of freedom along the length of the beam. A lever arm is attached to the beam at one end and a servo gear at the other. As the servo gear turns by an angle theta, the lever changes the angle of the beam by alpha. When the angle is changed from the vertical position, gravity causes the ball to roll along the beam. A controller will be designed for this system so that the ball's position can be manipulated.

사용자 삽입 이미지



For this problem, we will assume that the ball rolls without slipping and friction between the beam and ball is negligible. The constants and variables for this example are defined as follows:

  • M.........mass of the ball  0.11 kg 
  • R.........radius of the ball  0.015 m 
  • d.........lever arm offset  0.03 m 
  • g.........gravitational acceleration  9.8 m/s^2 
  • L.........length of the beam  1.0 m 
  • J.........ball's moment of inertia  9.99e-6 kgm^2 
  • r.........ball position coordinate  
  • alpha.....beam angle coordinate  
  • theta.....servo gear angle  

The design criteria for this problem are:

  • Settling time less than 3 seconds
  • Overshoot less than 5%


System Equations

The Lagrangian equation of motion for the ball is given by the following:

사용자 삽입 이미지
Linearization of this equation about the beam angle, alpha = 0, gives us the following linear approximation of the system:
사용자 삽입 이미지
The equation which relates the beam angle to the angle of the gear can be approximated as linear by the equation below:
사용자 삽입 이미지

Substituting this into the previous equation, we get:

사용자 삽입 이미지

1. Transfer Function
Taking the Laplace transform of the equation above, the following equation is found:

사용자 삽입 이미지

NOTE: When taking the Laplace transform to find the transfer function initial conditions are assumed to be zero.

Rearranging we find the transfer function from the gear angle (theta(s)) to the ball position (R(s)).

사용자 삽입 이미지
It should be noted that the above plant transfer function is a double integrator. As such it is marginally stable and will provide a challenging control problem.

2. State-Space
The linearized system equations can also be represented in state-space form. This can be done by selecting the ball's position (r) and velocity (rdot) as the state variables and the gear angle (theta) as the input. The state-space representation is shown below:

사용자 삽입 이미지
However, for our state-space example we will be using a slightly different model. The same equation for the ball still applies but instead of controlling the position through the gear angle, theta, we will control alpha-doubledot. This is essentially controlling the torque of the beam. Below is the representation of this system:
사용자 삽입 이미지
사용자 삽입 이미지
Note: For this system the gear and lever arm would not be used, instead a motor at the center of the beam will apply torque to the beam, to control the ball's position.


Matlab Representation and Open-Loop Response


1. Transfer Function

The transfer function found from the Laplace transform can be implemented in Matlab by inputting the numerator and denominator as vectors. To do this we must create an m-file and copy the following text into it:

.......m = 0.111;
.......R = 0.015;
.......g = -9.8;
.......L = 1.0;
.......d = 0.03;
.......J = 9.99e-6;

.......K = (m*g*d)/(L*(J/R^2+m));   %simplifies input

.......num = [-K];
.......den = [1 0 0];
.......printsys(num,den)

Your output should be:

.......num/den =   0.21 / ( s^2 )

Now, we would like to observe the ball's response to a step input of 0.25 m. To do this you will need to add the following line to your m-file:

.......step(0.25*num,den)

NOTE: Matlab commands from the control system toolbox are highlighted in red.

You should see the following plot showing the balls position as a function of time:

사용자 삽입 이미지
From this plot it is clear that the system is unstable in open-loop causing the ball to roll right off the end of the beam. Therefore, some method of controlling the ball's position in this system is required. Three examples of controller design are listed below for the transfer function problem. You may select from PID, Root Locus, and Frequency Response.

2. State-Space
The state-space equations can be represented in Matlab with the following commands (these equations are for the torque control model).

.......m = 0.111;
.......R = 0.015;
.......g = -9.8;
.......J = 9.99e-6;

.......H = -m*g/(J/(R^2)+m);
  
.......A=[0 1 0 0
.......   0 0 H 0
.......   0 0 0 1
.......   0 0 0 0];
.......B=[0;0;0;1];
.......C=[1 0 0 0];
.......D=[0];

The step response to a 0.25m desired position can be viewed by running the command below:

.......step(A,B*.25,C,D)

Your output should look like the following:

사용자 삽입 이미지
Like the plot for the transfer function this plot shows that the system is unstable and the ball will roll right off the end of the beam. Therefore, we will require some method of controlling the ball's position in this system. The State-Space example below shows how to implement a controller for this type of system.

Comment +0