Marginal Maglev Part B: Lead Design
Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
Quick Reference
Serial Plotter Send Window Indices and offsets
Links
- Instructions for assembling adding the magnetic field sensor to your maglev system can be found here.
- Sketch for this lab (UPDATED FROM BEFORE SPRING BREAK!!) is here.
Task Summary
- Complete last week's lab FIRST!.
- Download 6310_MAGLEV_23.zip
- Check coil current directions (which are set on lines 229->231 of the new sketch) for consistency with a compass.
- Recalibrate the sensor scale and offset (on lines 11 and 12 of the new sketch, and used on line 178).
- Add a magnetic field sensor, as described at the end of the maglev assembly guide (see link above).
- Calibrate the controller-command to coil-current model (Checkoff 1).
- Calibrate the system model, and demonstrate model-measurement matches(Checkoff 2).
- Use the model to design, and then test, a lead controller (Checkoff 3).
In the two videos below, we show two "working" maglev systems, one using a PD controller, on the left, and one using a lead-based controller, on the right. In the video on the left (the PD controller), you can see that the command (in green) is rapidly jumping up and down between its most positive and most negative values. This noisy command leads to noise in the umbrella position, as you can see by comparing the plot of the desired and the measured umbrella position (in red and blue respectively), or by examining the actual umbrella motions. The situation is quite different in the video on the right (the lead controller). The command (in green) has some noise, but far less than the PD-case noise. Note also that the response, in blue, tracks the desired response cleaner (as you can see from the measurements plotted in blue, or by watching the umbrella). The difference is not subtle!
Notice also that for both controllers, the desired position (in red) is a smoothed square wave, generated by setting Psmooth
on line 49 of the 6310_MAGLEV_SP23 sketch to 0.999. You will investigate reasons for using a smoothed square wave at the end of this lab, but DO NOT SMOOTH THE INPUT SQUARE WAVE WHILE CALIBRATING YOUR MODEL! The maglev system's response to those rapid transitions can be very informative.
In the last lab, we constructed the Maglev system that suspended an "umbrella" (a cube magnet with a white plastic diffuse reflecting top and a threaded rod tail). As a reminder, we:
- Used black 3-D printed spacers to
- calibrate a nonlinear function for accurately estimating the distance between the umbrella and the electro-magnet from the optical sensor signal and
- establish an umbrella equilibrium position, y = y_{eq}, 1.5 centimeters below the electro-magnet;
- linearized, about y_{eq}, the relation between umbrella acceleration and electro-magnet coil current;
- investigated proportional feedback stability using the linearized model, assuming coil currents instantly track changes in Teensy command;
- determined gains for a PD controller to "float" the umbrella.
Before we begin part B, designing a lead controller, we will need an accurate model of our system. So let us we review (by picture) what was investigated in part A.
In the figure above, we note the forces acting on our cube-magnet "umbrella": a position-independent gravity force, f_g; a position-dependent force attracting the cube magnet to the electro-magnet's steel core, f_{fe}(y); and a coil-current and distance-dependent attracting/repelling force between the cube magnet and the electro-magnet f_b(y,i_{coil}). Recall that for our solenoid-type electro-magnets, magnetic field is proportional to coil current, making them interchangable up to a scale factor.
In the above figure, we note the definition of \Delta y , the distance from the force-balanced equilibrium position y = y_{eq}.
Note that, compared to the previous lab, f_b is defined as being dependent on the electro-magnet's coil current rather than its field. As a result, our linearized model has \gamma_{\frac{da}{di}}, which relates perturbations in coil current to perturbations in umbrella acceleration, along with \gamma_{\frac{da}{dy}}, which relates perturbations in umbrella position to perturbations in umbrella acceleration.
In the previous lab, we calibrated a nonlinear relationship between \Delta y and the optical distance sensor voltage (see lines 177, 178 in 6310_maglev_SP23 sketch). Please be sure to recalibrate that relationship.
Previously we used an ad-hoc approach (we guessed) to finding a PD controller that levitated the umbrella. With that PD controller, we can make measurements that help us improve our model of the maglev system. Once we have a model, we can use the phase margin concept to design a better controller.
Perhaps it is helpful to review the abstraction process before we delve into estimate model parameters. That is, how did we arrive at a transfer function description of the coils, magnets, umbrella, controller, and sketch that comprise the maglev system?
In the above diagram, we note the connections between the abstract blocks we will manipulate mathematically and the physical system.
The above block diagrams show two more steps in process of abstracting the physical system into a composition of transfer functions. Note a key decision imbedded in the diagrams, a choice of variables. That is, we chose certain physical variables in our perturbation model, \Delta y_m, \Delta i_{coil}, and \Delta c. In general such choices are not unique, and are often based on intuition rather than more formal reasoning.
The transfer function abstraction clarifies (in green) what we are missing: the two parameters in the transfer function relating coil current to umbrella position; H_{c2i}(s), which relates controller command, c, to coil current, i_{coil}; and of course the improved controller, K(s).
The figure above is a summary of our tasks for today's lab. We will need to
- Determine a controller-command to coil-current model,
- Estimate coefficients for the model,
- Use the model to design a better controller.
The electro-magnet is made up of three wire coils surrounding three steel cores, each of which is driven by its own H-bridge driver. Together thay generate the field that either attracts or repels the umbrella's cube magnet.
In the above circuit-ish diagram of the three-coil maglev electro-magnet there are:
- three voltage sources, v_{pwm_{BL}}, v_{pwm_{AL}}, and v_{pwm_{BR}}, which model the three H-bridge coil drivers and
- three series resistor-inductor (RL) combinations, which model the inductance and wiring resistance of each of the three coils.
As a result, there are three coil currents, i_{coil_{BL}}, i_{coil_{AL}}, and i_{coil_{BR}}, which are, as we noted before, proportional to each coil's field.
In our case, the three voltage sources have identical voltages, given by the product of the power supply voltage, V_{ss} (five volts in our case) and the Teensy command, -1 < c < 1. So if c changes instantly from -1 to 1, the three voltage sources change instantly from -5 to 5 volts, but the non-zero coil inductance prevents the coil currents from changing instantly.
Sound familiar? Recall that when we changed the voltage across the propeller motor, the thrust did not change instantly.
Since all three voltage sources are equal to V_{ss} c, if we assume all three inductors and resistors are equal, then all three coil currents will be equal. So we'll just analyze one R-L circuit.
From the circuit model, the voltage across the resistor plus the voltage across the inductor must equal the source voltage. Using the inductor and resistor constituitive relations,
Assuming c(t) = Ce^{st} and i(t) = I_{coil} e^{st}, we can determine the transfer function relating the Teensy command to the coil current,
We can abstract the circuit elements from the relation between coil current and Teensy command, to see that there are only two parameters in the relation,
The transfer function relating Teensy command to field in the electromagnet is then
Recall that for a first-order CT system, when we excite the system with a step, we get a step response that we can easily relate to \gamma_{\frac{di}{dc}} and \lambda_E. In addition, when we excite the system with a sinusoid at frequency, \omega, that is equal to its natural frequency, or pole, \lambda_E, the sinusoidal response should have a magnitude that is \frac{1}{\sqrt(2)} times the magnitude at very low frequency, and the phase should be 45 degrees.
If you set the MODE on line 10 of the Teensy sketch to 0 (which is only for testing the coil, NOT FOR MAGLEV), upload the sketch, and set the frequency (by typing 5 10 to set the frequency to 10 hertz, for example), you should see the sinusoidal command, c(t), and the coil current response, i_{coil}(t). You can then change the frequency (though you make have to change the number of skipped points in the plotting to see the sinusoids clearly, try typing 4 2 in the send window). You can also plot step responses, by changing the amplitude of the input (try typing 6 1.8 in the send window, that will change the preset value of the amplitude from -0.9 to 0.9, and it will switch to square waves). Be sure to use a low enough square wave frequency so that the coil current achieves quasi-steady-state.
In the three figures below, we show three approaches for estimating \lambda_E:
- finding the 45 degree phase shift frequency,
- finding the frequency for which the amplitude is \frac{\sqrt{2}}{2} smaller than at very low frequency,
- and finding the time to rise by 1-e^{-1}.
- How did you use frequency response phase, frequency response magnitude, and step response to determine \lambda_E and \gamma_{\frac{di}{dc}}?
- Why did using phase give you the lowest estimate for \lambda_E? Suppose the actual transfer function from command to coil current was not exactly \frac{\gamma_{\frac{di}{dc}} \lambda_E}{(s-\lambda_E)} but instead \frac{\gamma_{\frac{di}{dc}} 10 (\lambda_E)^2}{(s-\lambda_E)(s - 10 \lambda_E)}. Which of your estimates would change the most?
- What where your values for and \gamma, \gamma_{\frac{da}{dy}} and \lambda_E?
- What is the transfer function for the feedback system, G(s) when K(s) = K_p + K_d s ?
- How well does your model predict the behavior of your system for different values of K_p and K_d?
- How did you implement a DT version of the CT lead controller?
- What low frequency gain, what zero, and what pole did you use for your compensator?
- What is the phase margin according to your matlab model?
- What is the largest step you can use? Can you take larger steps if you set pSmooth (line 49) to 0.999? Why is that?
Please be careful to multiple by 2 \pi when converting from frequency in hertz to frequency in radians per second. And YOU CAN NOT LEVITATE IN MODE 0!!!!!!!!!!!!!!!
Once you have found \gamma_{\frac{di}{dc}} and \lambda_E using all three of the above methods (phase, magnitude, and time constant), you are ready for checkoff one.
YOU SHOULD BE ABLE TO ANSWER ALL THE CHECKOFF QUESTIONS IN ORDER TO GET THE CHECKOFF!!!
The end goal of this lab is to design a stable feedback controller for the maglev system, one whose step response does not overshoot "too much", and is not too noisy. More specifically, you will be designing a lead controller by maximizing a property of the open-loop system's frequency response, its phase margin. You will need a fairly complete CT model of the maglev system to design the lead controller, and to generate that model, you will use a combination of measurements (frequency response as well as step response) and thoughtful analysis.
Putting together the transfer functions for command-to-current and current-to-position, along with the controller and the feedback loop, we have a complete system diagram, as shown below.
The above block diagram is the transfer-function based model of the linearized Maglev system, including the second-order transfer function relating changes in coil current, \Delta I to changes in separation distance \Delta Y , and the one-pole model relating changes in Teensy command \Delta C to changes in the electro-magnet coil current \Delta I .
To complete the system model, H(s), we will need to determine values for several parameters, but which will be important for phase margin design? Clearly we can combine the \gamma's for the command-to-current and current-to-separation distance transfer functions, so that we can simplify H(s) to
Since we estimated \lambda_E fromn coil current measurements, there are only two parameters to estimate, \gamma and \gamma_{da/dy}.
You also have a model for the PD controller,
Be sure you can use matlab to perform margin plots, compute closed-loop transfer functions, and step responses. Have a quick look at the prelab for matlab hints, and ask if you need help. Also, investigate the impact of \gamma_{da/dy} by increasing its value from 2 to 2000.
Finding the model parameters will require a mixture of measurement and insight. Below are some hints to help you get started.
In the figure above, we show annotatation for a plot extracted from the Arduino serial plotter, generated by running the maglev control system with a PD controller. The plot, a comparison of the quasi-steady-state peak-to-peak amplitudes of the desired (red) and measured (blue) umbrella positions, can be used to determine the \frac{\gamma}{\gamma_{\frac{da}{dy}}}. Do you see how?
Below we compare PD controller step responses with step responses computed with a well-calibrated matlab model, for K_d = 0.8*K_{d0}, K_d = K_{d0}, K_d = 1.4*K_{d0}, for our optimized K_{d0} and K_p = 5 .
Now that you have a calibrated model, you can use it to design a lead controller, but then you must also determine how to map your CT lead controller into a DT controller, implement that on the Teensy microcontroller, and test its performance.
If we use a PD controller, then
Our controller determines the Teensy command, c(t), from measurements of the separation distance error, e(t). If we use a PD controller, then
Alternatively, if we are using a lead controller then
Determine the difference equation for c[n] in the case of a lead controller, using the same approximation applied to deriving the difference equation for the PD controller. You will need this to finish the last part of this lab!
If you examine line 217 of the 6310_MAGLEV_SP23 sketch,
deltaC = 0.0 * pastDeltaC[1] + 0.0 * error + 0.0 * pastError[1];
you will see that to implement a lead controller, you need only replace the three 0.0 coefficients with values determined from mapping your CT lead controller to DT.
If we use a PD controller, then
https://introcontrol.mit.edu/fall22/prelabs/prelab07/preLabLead then
Determine a lead controller, implement and test it. We strongly recommend you determine the numerical values for your controller, and then transfer those values to line 217 in the Teensy sketch. Also, we suggest setting the offsetCtype on line 39 to 1 (so that your lead controller is used by default).
YOU SHOULD BE ABLE TO ANSWER ALL THE CHECKOFF QUESTIONS IN ORDER TO GET THE CHECKOFF!!!