Lab 4 - The Ball and Beam L x d The figure above shows the ball and beam apparatus - a simple example of an inherently unstable system. The ball, usually a steel ball bearing, is free to roll up and down a track of length L. A servomotor, shown in green, is attached to a short link of length d, which can push the track up and down. Define the distance from pivot to the ball as x, the angle of the track as γ and the angle of the servomotor as θ. Note that we have chosen an unusual definition for the coordinate x: the distance from the moving end of the beam to the ball. We do this in order to make the sign for the transfer function come out positive. A positive angle for the beam (or servo arm) will cause the ball to roll to the left, which increases the x-coordinate. Thus, a positive input (servo arm angle) results in a positive output (ball rolls to the left). Our goal is to devise a control system that will place and hold the ball at a desired coordinate, xs. Ideally, the ball should reach the setpoint quickly, and with minimal overshoot. As we will see below, the ball and beam system is marginally stable. That is, the ball will remain in a given position indefinitely if the beam is held perfectly horizontal. Any disturbance of the beam or the ball will cause the ball to roll. Of course we cannot guarantee that no disturbances will occur, so the system is useless without its controller. Modeling the System r fc To begin, draw a free-body diagram of the ball, as shown above. There are three forces acting on the ball: the frictional force, f, the f g gravitational force, fg, and the centrifugal force fc. The centrifugal f force occurs because the ball in on a rotating beam whose center of rotation is not coincident with the center of the ball. We ignore the forces perpendicular to the beam (normal force and Coriolis force) since they do not affect the ball’s motion. The gravitational force is given by 1 ππ = ππ sin πΎ and the centrifugal force is ππ = π(πΏ − π₯)πΎΜ 2 where πΎΜ is the angular velocity of the beam and (L - x) is the distance from the center of rotation (the pivot). Summing torques on the ball gives ∑ π = π½π½Μ = ππ Note that the rotation angle of the ball, β, is related to the x coordinate as π½= π₯ π so that π= π½ π₯Μ π2 Now sum forces on the ball ∑ πΉ = ππ₯Μ = −π − ππ₯πΎΜ 2 + ππ sin πΎ ππ₯Μ = − (π + π½ π₯Μ − π(πΏ − π₯)πΎΜ 2 + ππ sin πΎ π2 π½ ) π₯Μ + π(πΏ − π₯)πΎΜ 2 = ππ sin πΎ π2 Note that the moment of inertia of a sphere is π½= 2 ππ 2 5 so that the mass term cancels out entirely 7 π₯Μ + (πΏ − π₯)πΎΜ 2 = π sin πΎ 5 This equation is nonlinear and we cannot calculate a transfer function, which will make designing the control system very difficult. To make the problem tractable, let us linearize the equation about the angle γ = 0 (when the beam is horizontal). For small angles γ, we have 2 sin πΎ ≈ πΎ Also, let us assume that the angular velocity of the beam is relatively small, so that πΎΜ 2 ≈ 0 The linearized equation of motion is then 7 π₯Μ = ππΎ 5 The input to the system is the angle of the servomotor, given as θ. The servomotor angle and beam angle are approximately related to each other as ππ ≈ πΏπΎ so that the final equation of motion is 7 πππ π₯Μ = 5 πΏ It is simplest to collect all of the constants into one term π΄= 5ππ 7πΏ so that π₯Μ = π΄π take the Laplace transform ππ 2 = π΄Θ The transfer function for the ball and beam is π π΄ = Θ π 2 What happens if we apply a step input to the system? Use the final value theorem to find the steady-state response. lim π₯(π‘) = lim π π(π ) = π‘→∞ π →0 π΄π 1 π΄ ( )= 2→∞ 2 π π π 3 Thus, if we suddenly change the angle of the beam, the ball will roll off to infinity. This is another way of saying that the system is unstable. To further illustrate this, consider what happens if we apply a unit impulse to the beam (by tapping one end with a hammer, for instance). lim π₯(π‘) = lim π π(π ) = π‘→∞ π →0 π΄π π΄ (1) = →∞ π 2 π The ball still rolls off to infinity! As we can see, the ball and beam desperately needs a control system to keep it stable. Potentiometer (setpoint) +_ Controller System πΎπ π΄ π 2 E X Position of Ball (Output) Position Sensor Proportional Control of the Ball and Beam The figure above shows a control diagram for the ball and beam, with proportional control added. The error coming out of the summation block is πΈ = ππ − π and the command sent to the servo is Θ = πΎπ (ππ − π) Multiplying this by the transfer function of the ball and beam system gives π= π΄ πΎ (π − π) π 2 π π Solving for the transfer function, we have π΄πΎπ π = 2 ππ π + π΄πΎπ Using the final value theorem, the steady state value for a unit step input is 4 lim π₯(π‘) = lim π π(π ) = π ⋅ π‘→∞ π →0 π 2 π΄πΎπ 1 ( )=1 + π΄πΎπ π Thus, the system is stable, finally! Before we rest on our laurels, however we might want to see what happens when we give the system a unit step input, by taking the inverse Laplace transform π= π΄πΎπ 1 ⋅ π 2 + π΄πΎπ π Row 25 in the Laplace transform table gives π₯(π‘) = 1 − cos ππ‘ where π = √π΄πΎπ Position of Ball vs. Time 2 1.8 1.6 Position of Ball (m) 1.4 1.2 1 0.8 0.6 0.4 0.2 0 0 1 2 3 4 5 Time (s) 6 7 8 9 10 The figure above shows the position of the ball versus time when the ball and beam is given a step input. The ball does indeed oscillate about the new setpoint (1), but never settles down. We have reached our initial goal of stability - the ball doesn’t roll off to infinity - but our system is still not quite satisfactory. 5 Potentiometer (setpoint) +_ E Controller System πΎπ π π΄ π 2 X Position of Ball (Output) Position Sensor Integral Control of the Ball and Beam Now consider the control diagram shown above. The error is the same as before, but the control action is now Θ= πΎπ (π − π) π π The new transfer function is π π΄πΎπ = 3 ππ (π + π΄πΎπ ) If we apply a unit step function, then π= 1 π΄πΎπ π (π 3 + π΄πΎπ ) There is no readily-available Laplace transform pair for this expression, so we’ll use Matlab to plot the step response for the system. First, choose an arbitrary value for the product AKi. This is reasonable, since we can choose any value for Ki that we wish while tuning the controller. Then enter the Matlab commands num=10 den=[1 0 0 10] ball=tf(num,den) Matlab will respond ball = 10 -------s^3 + 10 Continuous-time transfer function. Then, type 6 step(ball) Step Response 10 8 After some judicious adjustment of the axes, the plot shown at right is given. As you can see, the response shoots off to infinity rather quickly, which means that our system is once again unstable! 6 Amplitude 4 2 0 -2 The real problem with the transfer function for the integral control system is that there is no first-order term in the denominator. As we have seen earlier, the first-order term is associated with damping; thus, the integral-controlled ball and beam has no damping. Without damping, the system is unstable and quickly shoots the ball off to infinity. We have one more control scheme to try, before giving up. -4 -6 -8 -10 0 1 0.5 1.5 2 2.5 3 Time (seconds) Controller Potentiometer (setpoint) +_ E System π΄ π 2 πΎπ π X Position of Ball (Output) Position Sensor Derivative Control of the Ball and Beam The ball and beam system with a derivative controller is shown above. The new transfer function is π π΄πΎπ = ππ π + π΄πΎπ If we subject this system to a step input, we have π= π΄πΎπ 1 ⋅ π + π΄πΎπ π This corresponds to Row 14 in the table, or π₯(π‘) = 1 (1 − π −π΄πΎπ π‘ ) π΄πΎπ (1) In other words, the derivative-controlled ball and beam is a first order system with time constant π= 1 π΄πΎπ 7 Again, at first glance this appears to be an effective control system. There is one major defect which prevents us from adopting derivative control alone. Imagine a situation where the setpoint is 0.25m, but the ball starts at 0.26m. This produces an initial error of -0.1m, which is constant. Because the error does not change, its derivative is zero and the controller will order no change in beam angle. Thus, the derivative controller cannot accommodate a constant, steady-state error. This result seems to contradict the equation (1) above, which predicts the ball settling out to its setpoint with time constant 1/AKd. In fact, equation (1) is the result of changing the setpoint of the system, while the second situation is the result of a non-zero initial condition. This is a major defect in the transfer system method of designing control systems: by definition, the initial conditions are zero when using the transfer function method. This is normally not a problem - any system with damping will have its initial conditions fade away after new disturbances are added to the system. In the case of the ball and beam, however, there is no restorative “spring” force to bring the ball back to its neutral position if the initial conditions are nonzero. Potentiometer (setpoint) +_ E Controller System πΎπ π + πΎπ π΄ π 2 X Position of Ball (Output) Position Sensor PD Control of the Ball and Beam As a last resort, let us try combining proportional and derivative control to the ball and beam system, as shown in the figure above. The transfer function for the PD-controlled ball and beam system is π΄(πΎπ π + πΎπ ) π = 2 ππ π + πΎπ π΄π + πΎπ π΄ The denominator has a first-order term for damping and a zero-order term corresponding to stiffness (or restoring force). Thus, we have returned to a familiar second-order system, and we can use the same methods of finding controller gains as we did with the incubator system. Once we have found the desired damping ratio and natural frequency (by specifying settling time and maximum percent overshoot, e.g.) we can find proportional and derivative gain by πΎπ = ππ2 π΄ πΎπ = 2πππ π΄ Modeling with Initial Conditions As mentioned earlier, the transfer function model is incapable of simulating nonzero initial conditions. This is unacceptable for the ball and beam, since the usual situation is to place the ball away from the setpoint let the controller work its magic. This corresponds to a nonzero initial 8 displacement of the ball, but we might also wish to simulate a nonzero initial velocity of the ball by tapping it to one side at time t=0. To create a more accurate model of the ball and beam system, then, we must abandon the transfer function method for the more traditional “equation of motion” method in Simulink. The figure above shows the modified Simulink diagram with PD control. Note that we are also sending thetadot back to the workspace. The servo manufacturer specifies the maximum angular velocity of the servo - this must be compared with the maximum value of thetadot to check the feasibility of the controller. The integrator block has the option of taking its initial condition from an external port. This has been used in the diagram above to make obvious the nonzero initial condition of the ball. We could also employ a nonzero initial condition on xdot, the velocity of the ball. 9