Issuu on Google+

AA 448 Lab 3: Magnetic Ball Levitator

Mike Becker Daniel Broyles Justin Fletcher

Feb. 22, 2012


ABSTRACT Accurate control of physical systems often hinges around how the non-linear dynamics of the system can be handled in a linear fashion. This exact problem is explored in this lab report, where a several control schemes are examined in order to magnetically levitate a metallic ball within a narrowly defined region of operation. Using Mathworks Simulink software, a non-linear model of levitation dynamics is built and the system simulated. Using linearization techniques, a linear model is then created and the two systems compared. Finally the systems are implemented on the physical levitation apparatus. It was found that simulation results closely matched physical results and that the PID controller provided the most stability.

Nomenclature m = 0.0674 kg d = 0.026 m g = 9.8 m/s2 Ď =1.225 kg/m3 Kkepco = -3.6 V

Mass of ball Diameter of ball Gravitational constant Density of air Gain of Kepco Amplifier State Vector

Fm Vm(t) VD(t) VP(t) z(t) z0

Control Vector Magnetic Force Applied magnet voltage Position sensor output voltage Optical sensor output voltage Distance from tip of magnet to ball center Nominal levitation distance, “trim point� Velocity of ball center in reference to magnet tip

INTRODUCTION The goal of this lab was to levitate a ferric ball using control signals generated from a Target PC that runs a Simulink control model. Position feedback is provided via an optical sensor whose feedback zone interacts with the levitating ball. The entire apparatus must first be calibrated correctly in order for a model to be constructed. This data is then used to correlate magnetic force as a function of applied magnet voltage and position as measured by the optical sensor. A non-linear model is then created, and used to linearize around a trim point and create a linear model. Full-state, PD, and PID control schemes are then run on the physical model in order to find the optimum ball levitation control method.


EQUIPMENT & SOFTWARE The following equipment was used to obtain data in this experiment: GW GDM-8145 Digital Multimeter The GW multimeter is able to measure resistance and DC voltage and current, while also being able to test for electronic conduction. Voltage measurements are obtained by placing the meter leads in a parallel connection with the desired voltage to be measured, while current is measured by placing the meter in a series connection. However, it is generally advised to measure current by measuring the voltage drop across a very small resistance and then calculate current with the known resistance and measured voltage using Ohm’s law. GW GPC-3030D Power Supply The 3030D power supply provides three independent sources; two adjustable to +- 15 V and one fixed at 5 V. The fixed supply has a maximum current rating of 3 amps and will drop the voltage accordingly if a connection to this supply draws too much current. The adjustable sources each have an associated current-limiting adjustment which allows a user to set the maximum allowed current. Again, if the current threshold is set below the operating current of a circuit, the power supply will regulate the output voltage to keep the current within the set limit. Kepco Power Amplifier The Kepco power amplifier simply amplifies an input signal by a constant gain of -3.6 V/V. An important feature of the amplifier is a set of output limiting screws which can be manually set to limit the output voltage to a given negative to positive range, which on this unit should never exceed +-15 V. Levilator Stand & Sensors

This lab hinges around the successful use of a magnetic levitation stand. This apparatus consists of an inverted electro-magnet, with a small infra-red light and parallel optical sensor both mounted below the magnet tip. Levitation of a ferric metal ball is controlled by keeping the ball in a narrow band below the magnet tip and between the light and optical sensor. Both the magnet voltage and optical readings interface with a target PC running a simulated embedded system via a D/A and A/D converter. In addition to this equipment, several software packages were used on two PC’s which include Matlab, its’ included packaging Simulink, and a Mathworks program xPC target. Matlab and simulink were used exclusively on the user, or ‘host’, PC. Simulink was used to both create plant, control, and system models while Matlab itself was used to both interface and initialize variables used in Simulink as well as to later analyze experimental data. xPC target was used on a ‘Target’ PC which acted as the embedded platform for the models that were created in Simulink. The target PC then sent digital data out to a physical system and collected analog data from that system which was then sent back to the Host PC for analysis.


SETUP & CALIBRATION A simple set-up of the levitation device and communication between equipment is shown below in fig. 1.

Figure 1: Lab Set-up (Lum) The set-up consists of the Target PC which runs a Simulink model, continually sending out control voltages through the D/A that are amplified through the Kepco unit and sent to the magnet to control the force applied to the levitating ball. Feedback is provided via the optical sensor output which is routed back through the A/D to the Target PC and used in the Simulink model to determine the ball’s position and adjust the applied control voltage u(t). Proper set-up and accurate calibration of the levitation apparatus and sensors was an integral part of success in this lab. Precise optical sensor voltage readings had to be gathered for various positions of the ball, as did applied voltage levels on the magnet in order to determine magnetic force as a function of distance. In order to gather this data, the levitation apparatus had to be inverted and a calibration device set on top (see fig 2).


Figure 2: Calibration set-up (Lum) The calibration device in figure 2 consists of a force transducer that interfaces with the ball via a small rod assembly. The transducer allows the ball to be raised and lowered above the magnet, allowing optical measurements to be taken in real time. Additionally, the transducer measures the force on the (and from) the hanging ball and rod assembly and sends this information to through the A/D converter in the form of a voltage magnitude. I. Position Sensor The first step taken was to calibrate the position sensor. To begin, the ball diameter [d] was measured at 0.026 m and converted to a radius [r] of 0.013 m. This value was then added to all distance measurements taken to give a distance from the tip of the magnet to the center of the ball’s mass [z(t)]. The ball and rod was attached to the position sensor, where the voltage of the position sensor changed linearly with movement of the ball and rod in the z direction.The position sensor’s output was connected to a multimeter, and a calibrated block (see fig. 3) was placed between the ball and magnet tip at several known distances and the corresponding position sensor voltages [VD] recorded.

Figure 3: Calibrated block


With the recorded distances converted to their equivalent z values, the table of voltages vs distances was plotted and a linear fit line was created. This provides a linear relationship that converts the position sensor voltage to a distance in meters. The table of data is provided in Appendix A, and the plotted data and fitted equation appear below in fig 4.

Figure 4: Optical sensor data II. Optical Sensor The next step was to correlate the converted z(t) positions to optical sensor voltages. Both the position and optical sensor outputs were connected to multimeters and to available A/D channels. A simulink model was used to capture the incoming data from the A/D converter and the model was downloaded to the Target PC. With the model running, the ball was slowly lowered from it’s highest position from the magnet to the magnet’s tip. The data was then uploaded from the Target PC and plotted in Matlab, giving a clear picture of where the optical sensor voltage [VP] provides good feedback for position of the ball. The edges of the feedback zone correlate to the ball being too far away from the optical sensor for it to gather any meaningful data. The feedback zone is thus defined below in figure 5 as the linear region between the two data cursors-giving the voltages and positions that correspond to a controllable region.


Figure 5: Possible feedback zone From figure 5, the midpoint of the distance boundaries is taken as:

Levitating the ball at this position should optimize the available control feedback region, with the boundaries being: m &

m

As will be seen later in our report, we chose to use a lower z0 trim point (0.0255 m) in order center around slightly lower magnet voltages than would be required with a greater distance z. With the feedback zone defined, the optical calibration data was then trimmed at the critical values and fitted with a first order fit as shown below in figure 6.


Figure 6: Feedback region & fitted equation III. Force Transducer In order to define a relationship between magnet force vs applied magnet voltage,the ball and rod assembly was replaced with a hanger & pan and the output of the force transducer sensor was connected to a multimeter (fig. 7)

Figure 7: Transducer calibration weight hanger Weights of varying mass were then set in the pan and the output voltage from the sensor for each mass (including pan & hanger weight) was recorded. This data is provided in Appendix B. From this data, a plot was made of transducer voltage [VT] vs force in newtons. A linear fit was then applied to the data to obtain an equation relating


these parameters (see fig. 8).

Figure 8: Transducer force vs voltage linear fit IV. Characterization of Magnetic Force The final step is to put together the calibration data gathered in the previous three steps in order to correlate magnetic force vs an applied voltage on the magnet. The position and force sensors were both connected to the Target PC via the A/D channels as well as to multimeters for real-time monitoring. The ball and rod assembly were reconnected in place of the hanger & pan from step III. Simulink was used to to create a model to apply a constant control voltage [u(t)] and record the incoming sensor data from the A/D channels. With the model loaded onto the Target PC and a constant voltage applied to the magnet from the Target PC and amplifier, the ball was carefully lowered down across the feedback zone to nearly the tip of the magnet and the sensor data recorded. This process was then repeated for applied magnet voltages varying from 1.5 V to 15 V. Curves were plotted for each run to ensure that the data collected was reasonable and smooth curves of VD vs VT were obtained. After all the runs were complete, a correlation between magnet force, magnet voltage, and ball position could be formulated through the two-variable function: FM(z,VM). In order to parametrize the function inputs correctly, the linear calibration fit equations from steps I & III are utilized. For each applied magnet voltage VM, the corresponding transducer and position sensor voltages had to be converted into an applied force and position in terms of the center of the ball from the magnet tip. To do this, we apply the linear fit equations and replace the variable ‘x’ in the position and optical fits with VT & VD respectively. Additionally it is noted that the ball & rod’s mass must be subtracted out of the force characterization equation to normalize the applied force. Thus we have:


Both FM and z(m) are vectors of data, with force expressed in newtons and z values expressed in meters. In this manner, the data for each applied magnet voltage was converted to magnet force and corrected position, and a plot of the curve for each voltage level was created (see fig. 9 below).

Figure 9: Magnet force vs position for varying magnet voltages

DERIVATION OF EQUATION OF MOTION AND NON-LINEAR STATE SPACE MODEL Figure 10 displays the free body diagram for the ball in the system The positive displacement from the tip of the magnet to the center of mass of the ball, z(t) is defined as positive in the downward direction, as is the velocity, .


Figure 10: Free Body Diagram A force due to gravity (Fg) acts on the ball in the positive z direction, and the ball feels forces in the negative z direction from the magnet (Fm) and drag (Fd) forces. For this system, the gravitational force is modeled as a constant:

Where m is the mass of the ball, and g is the acceleration due to gravity, or 9.81 m/ The drag force is modeled using the following function:

Where Cd is the coefficient of drag for a sphere, S is the reference area, and is the dynamic pressure. The sign() function is required in order to make the drag force negative when the velocity is negative. To model the magnet force, we first choose the state and control vectors. Let:

Where

is the distance from the tip of the magnet to the center of mass of the ball

(positive downward), is the velocity of the ball (also positive downward), and is the voltage output from the D/A card (or, the voltage into the Kepco Amplifier). In lieu of using a complicated model involving the electric field of the magnet and material


properties of the ball, we can experimentally determine how Fm changes with respect to the control and state vectors. More specifically, it is assumed that the voltage on the magnet and distance between the ball and magnet tip dominate the behavior of the magnet force. That is:

Where is the gain of the Kepco amplifier. Using this relationship, the equation of motion for the system can be written using Newton’s second law:

Using the relationship that the voltage across the magnet, Vm, is just the control signal, u1, multiplied by the gain of the Kepco amplifier, the equation of motion can be written entirely in terms of states, controls, and constants.

With this definition for the acceleration of the ball, a non-linear state space representation of the system can be obtained by differentiating the state vector:

(Lum) This non-linear state-space model can be implemented in Simulink as shown in figure 11:

Figure 11: Non-linear Plant Model Where the inner workings of the Calculate State Derivative block is displayed in figure 12:


Figure 12: Calculate State Derivative Block Construction In order to compute the state derivative, this block requires a 2-D look-up table that outputs the magnet force, Fm, given the current position, x1, and magnet voltage, Vm. This table was obtained using the data from the the graph of Magnet Force vs. Position with varying Vm in figure 9. This data was cut down to a critical window that reflected the position where optical sensor feedback was possible (as discussed section II of Setup and Calibration), and where the magnet force was between 25% and 150% of the gravitational force on the ball, mg. As well, the data in this region was fitted with a function that models the magnet force as:

Figure 13 shows the critical window and all of the data points and exponential fits for every measured voltage, Vm.


Figure 13: Fm vs Z (m) fitted for critical window at measured levels of Vm. Ideally we want a function that incorporates both the position, z (m) of the ball, but also the magnet voltage, Vm. A mesh plot from the fitted Fm plots in figure 13 is shown below. This mesh plot shows approximately the 3D function Fm that we seek to find, except for the linear fit between data points.


Figure 14: Ideal 3D plot of Fm vs Z(m) and Vm (volts) In order to get a smooth 3D function for Fm, we took the α and β parts of the Fm equation and fitted them for the varying magnet voltage, Vm. Figure 15 shows the values of α and β as functions of magnet voltage. The method was chosen to fit α with a firstorder linear fit, and β as a constant, βavg. Which gives:


Figure 15: ι (top) and β (bottom) as functions of magnet voltage

With these parameters obtained, the 2-D look-up table was constructed to reflect the magnet force, Fm, in the critical window. Figure 16 shows a graphical representation of this data. The equation for Fm was then:


Figure 16: Data for Fm 2-D look-up table

LINEARIZATION & LINEAR MODEL Once the nonlinear model was constructed, it was necessary to linearize the system about a trim point in order design a controller. For convenience, the trim point was chosen to be an equilibrium point. This point is defined as the state and control vectors such that the state derivative is the zero vector, or:

Solving this vector equation yields that this point occurs when the magnet force equals the gravitational force on the ball:

By choosing a position, the control voltage can be found that will balance the forces on the ball. The trim position was chosen as a point in the middle of the possible feedback zone (see section II of Calibration and Setup), and the control voltage was extrapolated from figure 13:

To linearize the system around this point, a multi-dimensional Taylor Series


approximation is used, given by:

Where:

This computation can be further decomposed by separating the partial derivatives associated with the state and control vectors, such that:

(Lum) By defining matrices A and B, the expression has taken a linear form that can be used to design controllers and analyze stability:

Special care is taken here, as this expression is in terms of deltas, or changes around the trim point, as opposed to actual values of position, velocity, and control voltage. One way to obtain these matrices would be to analytically determine the partial derivatives using a symbolic manipulator, such as Mathematica. However, for this experiment the MATLAB function linmod() was used. This function numerically calculates the partial derivatives necessary to form the A, B, C, and D matrices of the linearized system around a specified point, given a non-linear model and trim point vectors. Once computed, the linearized system can be implemented with a state-space block in Simulink. A modification can be made to the state-space block to achieve the same input/output relationship as the non-linear model by noting that:

Using these definitions, the linearized system model about the trim point is shown in figure 17:

Figure 17: Linearized System Model This linear representation allows for stability analysis by examining the eigenvalues of


the matrix A. The state space matrices for this system and the eigenvalues of A are given below. As expected, one of the eigenvalues is positive, implying the system is unstable.

Control Design and Simulation Results With a linearized system in hand, a few tests were performed to validate the model. First, the behavior of the open-loop system was simulated. It was expected that at small magnet voltages, the position of the ball would travel in the positive direction, corresponding to the ball falling to the floor, and at large magnet voltages the ball would be sucked up into the magnet in the negative direction. Figure 18 shows the simulated position and velocity of the open-loop non-linear system. For this scenario the voltage across the magnet was set to 7.5 V, and the initial position of the ball is set to 0.0255 m.

Figure 18: Simulated position (top) and velocity (bottom) for open-loop nonlinear system (Vm=7.5 V)


As expected, the ball starts at its initial position and begins to fall away from the magnet in the positive z direction. The velocity also increases in the positive direction. Figure 19 shows the same system, only with a magnet voltage of 8.5 V. In this case, the system also behaves as expected because the magnet force causes the ball to travel in the negative z direction, and the ball gets sucked up into the magnet tip.

Figure 19: Simulated position (top) and velocity (bottom) for open-loop nonlinear system (Vm=8.5 V) With the linear system model validated, controller design could begin. First, a full-state controller was designed using the place() command on the linearized system model (see figure 20). The desired closed loop poles were specified to be -80 and -60, and the resulting controller gain, K, was returned as -1358.8 and -28.6. LQR() was used as well to pick K, with a Q matrix of [100 0; 0 0] and an R matrix of [1]. This specifies a high desire for position to to change quickly, with relatively small considerations for how “expensive� the controller is. Using this method, the resulting controller gain, K, was -759.8298 and -17.6053. The controller gain attained from using the place() command was what was chosen to use for further experimentation, as this was a more aggressive controller yet still did not go outside the bounds of the control voltage, Vm.


Figure 20: Full State control of linearized system The simulated position and velocity of the controller on the linearized model is shown in figure 21. In this scenario, the initial change in position away from the trim point, ∆x, was set to 0.002 m. This corresponds to the initial position seen in figure 21, 0.0275 m, which is exactly 0.02 m from the trim position, 0.0255 m. The controller appears to behave correctly, and regulates the system back to its trim point in about a tenth of a second with no overshoot.

Figure 21: Full-state control simulated on Linear Model


Next, the linear controller was modified for use on the nonlinear plant model. Due to the linearization process, the linear controller takes in ∆x, and outputs ∆u. Using the relationships between the ∆’s and the trim point, a nonlinear full state controller was constructed by adding or subtracting the appropriate trim point values, resulting in a controller that takes the state vector, x, as an input, and outputs the control, u. The nonlinear controller is shown in figure 22.

Figure 22: Nonlinear Full State Controller This controller was implemented on the nonlinear plant model by feeding back the state vector, as shown in figure 23.

Figure 23: Full state control of nonlinear plant mode To test this controller, the initial displacement was again set to 0.0275 m. Figure 24 shows the resulting position and velocity traces from the simulation.


Figure 24: Full-state control simulated on Non-linear Model We can see that there is some small steady-state error (~0.0002 m) when using our fullstate controller on the non-linear model. Adding an integrator will help bring the steady state error down to zero and additionally transform the controller into a PID controller. The gain values for the PID controller were those of the full state controller with respect to position (KP=-1358.8) and speed (KD=-28.6). The integrator gain, KI, was simply chosen to be â…” of our KD value. The PID controller is shown in figure 25.

Figure 25: PID controller


This controller requires an input of the error between a desired position and the actual position, and outputs the appropriate control voltage. Simulation results with this controller show that the steady state error does indeed go down to zero, although only after a considerable amount of time (~180 sec.), as shown in figure 26 below:

Figure 26: PID control simulated on Non-linear Model

CONTROL OF PHYSICAL SYSTEM With the apparatus calibrated and the linear and non-linear models created and working correctly, physical levitation control was implemented and tested through three different control schemes: 1. Full-State 2. PD 3. PID

Before testing any of the control schemes on the physical levitation system, the optical


sensor to position calculations were first tested to ensure that they were giving accurate results. A Simulink model was created to convert optical output data to position and a ball was then manually moved up and down above the magnet to ensure that the conversion was giving reasonable results. Figure 27 shows the physical plant model used.

Figure 27: Physical Plant The output of the A/D is the voltage from the optical sensor. To convert this voltage into a position, a linear fit of the optical sensor calibration data only in the critical window was used. Another, more accurate approach would be to use a look-up table for this purpose. However, satisfactory results were obtained using the plot and block shown in figure 28. As well, a pseudo-derivative was used to access the velocity of the ball, as this state could not be directly measured. Another way to access this state would be to implement an observer, however the pseudo-derivative provided satisfactory results for our purposes.

Figure 28: Vp to Position Conversion Block implementation and associated plot The results from testing the functionality of this system are shown in figure 29:


Figure 29: Optical sensor data verification Figure 29 above depicts three graphs corresponding to the optical feedback voltage, ball position as converted from optical sensor readings, and ball velocity, respectively. An optical voltage of 5.2 V corresponds to the ball being far away from the magnet, and as the voltage decreases the position can be seen getting closer to the magnet as expected. Any sudden changes in ball position are clearly shown as spikes on the ball velocity graph. With the conversion working correctly, the controllers were ready be to tested.

I. Full-State Full state control was implemented using the pole placement technique. Figure 30 shows the implementation of the full state controller on the physical plant. A saturation block is used to ensure the control voltage never reaches the limits of the Kepco Amplifier (-4.2V < u < 4.2V). Additionally, the optical sensor voltage, Vp, was measured to verify the resulting state vector values.


Figure 30: Full state control of physical system The full state controller designed in Control Design and Simulation Results was attempted first, with control gains set to -1358.8 and -28. This controller was not aggressive enough to hold the ball at the trim position. However, through experimentation the gains were adjusted to -1500 and -50. This controller did indeed levitate the ball at the trim point. Figure 31 shows data obtained from the system during levitation. The traces from top to bottom show the optical sensor voltage [Vp], the position of the ball [ x1], the velocity of the ball [x2], and the control voltage [u(t)]. While this controller did levitate the ball, the ball oscillated up and down, as shown in plot of the ball position. As well, the control voltage seems to saturate at the upper limit (~4.2 V), suggesting more fine tuning could be done with the LQR technique.


Figure 31: System data from full state control II. PD After trying full-state control, a PD controller was implemented to see if the oscillations seen with the full-state controller would still be present. The controller itself is essentially the same as a full-state setup, and it would be expected to see similar experimental results. Figure 32 shows the implementation of a PID controller on the physical system.

Figure 32: PID control of physical system


The controller is shown in detail in figure 33. To achieve PD control only, the integral gain, KI, is set to zero. The other gains, KP and KD, were set to match the gains obtained from the full state controller design (see Control Design and Simulation Results).

Figure 33: PID Controller We are seeking to control position, so when implementing a PD controller, the derivative portion of the controller just becomes the velocity. Then there are just two gains with two parameters (position and velocity), which is the exact same as the full state (x1 = position, x2 = velocity). Figure 34 shows the response of the system with the PD controller. Although it should appear exactly as the full-state controller, there may be some differences depending on how the ball was moving as it was released under the magnet. Additionally, a trace of the error signal, e, is included.


Figure 34: System data from PD control Looking at the traces of x1 and e, the steady state error is around 0.002, and has a zero slope. This error was what the simulation of the full state controller on the nonlinear system predicted. Adding an integrator should, eventually, zero out this error. As well, the control signal for this controller does not appear to be hitting its saturation limits. III. PID The PID controller proved to have a steadier response than the full-state controller. The added integrator helps the steady state error approach zero over time, as can be seen by the negative-sloped trend in the x1 trace. Figure 35 below shows the response.


Figure 35: System data from PID control The effect of the integral gain, KI, can be seen in figure 36. The data in this figure was collected for the same system with PID control as in figure 35, however the value of KI was doubled. A close examination of the error signals reveals that increasing this gain corresponds to a slightly sharper slope in the error signal. Therefore, the system with a larger KI value will reach zero steady state error quicker.


Figure 36: System data from PID control We examined the disturbance rejection capabilities of the PID controlled system by adding three smaller ferrite balls to the levitated larger ball. Figure 37 below shows the main ball returning to its previous position very quickly after each small ball is added. The little spikes in position (first one occurring at around 12.5 seconds) indicate when each smaller ball was added. As long as the control signal u(t) was kept within itâ&#x20AC;&#x2122;s saturation limits, the controller offered excellent disturbance rejection.


Figure 37: PID control demonstrating disturbance rejection CONCLUSION In this lab we went through the full process of analyzing, measuring, simulating, and designing controls for an unstable magnetic ball levitation system. Because this was a non-linear system and we needed to build a controller for it, we linearized the system around a desired operating point and then simulated the system for the three controllers (full-state, PD, PID). We found that all three controllers were successful at maintaining an average levitation position, but that the PID controller ultimately was the best at maintaining stability, even with added mass to the object being levitated. During this lab, we had a few mishaps with our data which initially slowed our progress. Success was extremely dependent on getting good data when measuring all of the system parameters in order to obtain a trustworthy model. What was also illustrated though, is the careful manner is which we should record and save data. Variable names, file names, and saving procedures could have been handled better on our first go through of data collection. When trying to iterate through a single step several times in a row, we accidentally saved over most of our previous measurements. This resulted in the need to retake all of the magnetic force measurements a second time. The


experience illustrated the need for having a well defined system for storing and keeping track of data when several different measurements are involved. REFERENCES Lum, C. (n.d.). Lab 3: Magnetic Ball Levitation. Retrieved from http://faculty.washington.edu/lum/aa448/labs/lab3/lab_3_mbl.pdf APPENDIX A: POSITION SENSOR CALIBRATION DATA TABLE

APPENDIX B: FORCE TRANSDUCER CALIBRATION DATA TABLE


EE448_Lab_3_MBL