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 6310_MAGLEV_FA23.zip
Task Summary
- Complete last week's lab FIRST!.
- Download the sketch.
- Check coil current directions for consistency with a compass.
- Recalibrate the sensor scale and offset.
- 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
near line 50 in the 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 more 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 the in Teensy 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, and controller 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
Since our model corresponds to a first-order CT system, when we excite the system with a step, we get a response whose steady-state is easily related to our model's scale factor \gamma_{\frac{di}{dc}}, and whose rise time is inversely proportional to our model's natural frequency \lambda_E. And when we excite the system with a sinusoid of frequency \omega (in radians/second), if |\omega| = |\lambda_E| then the sinusoidal-steady-state response will be phase-shifted 45 degrees from the excitation, and will be a factor of \frac{\sqrt(2)}{2} smaller than the amplitude of the sinusoidal-steady-state response for |omega| is much lower (e.g. \omega < 0.1 |\lambda_E|).
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 may 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}.
If you set the sinusoid frequency to 10, and the input command and the measured coil current are out of phase, like in the picture below, then your current sensor and coil fields are flipped in sign.
This flipped-in-sign problem is easy to fix. Just change line 206 in the Teensy sketch from
crnt = 10.0*(my6310.adcGetAvg(IN1) - CurrentOffset);
to
crnt = -10.0*(my6310.adcGetAvg(IN1) - CurrentOffset);
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 rise time), you are ready for checkoff one.
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 parameters are most 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.
From Wednesday's lecture, we used lines of matlab code to test controllers once the variable s has been defined,
s = tf([1,0],1)
and Hs has been specified. We repeat those lines here for the PD controller case and then the lead controller case.
Kp = 5; Kd = 0.1; Ks = Kp+Kd*s; figure(1); hold off; margin(Ks); hold on; margin(Hs); margin(Ks*Hs); figure(2); step(feedback(Ks*Hs,1),1);
K0 = 5.0; sz = -100; sp = -1000; Ks = K0*(sp/sz)*(s-sz)/(s-sp); figure(1); hold off; margin(Ks); hold on; margin(Hs); margin(Ks*Hs); figure(2); step(feedback(Ks*Hs,1),1);
Finding the model parameters will require a mixture of measurement and insight. Below are some hints to help you get started.
- Since \gamma_{da/dy} has a limited impact on stability, start by setting it to zero and then determine \gamma by matching the "ringing" frequency of the step response.
- Once you have determined \gamma, analytically determine the unit step response steady state as a function of \gamma_{da/dy}. Then match the steady-state of the matlab simulation to your measured data.
The frequency of the "ringing" in the step response, particularly for the nearly unstable case (like in the third example below), is a particularly sensitive measure of \gamma.
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 .
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 \gamma_{da/dy}. Try determining the formula for the step response steady-state, and then matching.
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 Teensy 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).
Try to keep the high frequency gain, K_0 \frac{s_p}{s_z}, less than 100, so that you do not magnify the measurement noise too much. And match your low frequency gain, K_0, to the value you used for K_p in the PD controller. You may need to lower K_p = K_0 in the PD controller and the lead controller, so that you can make the ratio \frac{s_p}{s_z} large enough to get a good "phase bump" at unity gain frequency.
PLEASE USE NUMERICAL VALUES FOR THE COEFFICIENTS IN THE TEENSY SKETCH!! IT IS FAR EASIER FOR US TO DETERMINE IF THE VALUES ARE IN A REASONABLE RANGE.
YOU SHOULD BE ABLE TO ANSWER ALL THE CHECKOFF QUESTIONS IN ORDER TO GET THE CHECKOFF!!!