Lab 1: Fast and Spurious

The questions below are due on Wednesday September 18, 2024; 11:00:00 PM.
 
You are not logged in.

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

Parameter Indices to use in the serial plotter "Send" window

Links

  • Software to install is described here.
  • Build instructions are here.
  • Sketch for this lab is here.

Task Summary

Week A

  1. FIND A PARTNER.
  2. Install Software.
  3. Build, Test, and Calibrate the Speed Control Hardware (checkoff 1).
  4. Determine the roles of the ticksperupdate, kff, kp, repeats, freq, and amp, and DisturbA (checkoff 2).

Week B

  1. Extract coefficients from data for a 1st-order difference equation model.
  2. Use model to inter-relate gains, update period, and stability. Compare with experiments (checkoff 3).
  3. Investigate how gains effect tracking error and disturbance rejection, design controller (checkoff 4).
  4. Collect experimental data for the postlab using various values of ticksperestimeate (as screenshots) (Checkoff 5).

Safety First

Please read the EECS Lab Safety instructions.

  • We will be building and debugging electrical systems. While everything we do in this subject is low-voltage, you should never modify or even touch a circuit without turning off its power.
  • We will be using small but very high speed motors. If our systems go unstable, parts can fly off in any direction. Please wear safety goggles when using the high-speed motors with spinning propellers.
Please sign the EECS Lab Safety form now! You will not be allowed to work in the lab (38-545) and get a grade in this subject unless you indicate that you have reviewed the safety instructions by signing the form.

Introduction

The goal of this lab is to control the speed of a motor-driven rotor, while learning about

  1. Control system modeling,
  2. Feedback and Stability,
  3. Sample Rate Effects,
  4. Steady-state and Dynamic Tracking,
  5. Insensitivity to Disturbances and uncertainty,

As you will see, the issues associated with control will be obvious and direct, but the issues associated with modeling will be both pervasive and, unfortunately, subtle.

After constructing and testing the speed control system, you will collect data from which to calibrate a first-order difference equation model for the relationship between the Teensy-sketch-generated motor command and the measured rotor speed. You will then use this model to make reasonably good predictions about the interactions between sample rates, controller gains, stability, tracking errors, and disturbance insensitivity.

Then, in preparation for the post-lab, you will collect another data set, one specifically designed to expose inaccuracies in the first-order model. As part of the post-lab, you will derive, calibrate, and analyze an improved second-order model, and see if its predictions are better (spoiler alert, sometimes they are).

The take-away about modeling from this lab and post-lab is NOT (we repeat, NOT) that one model is good and the other is bad. As you will see in lab, a first-order model is accurate enough (and simple enough) to answer questions about the interaction between sample rate and stability, or feedback gain and disturbance rejection. But as you will see in the postlab, you'll need a second order model to accurately predict the stability limits on gain, or to predict waveforms near the stability limit.

So, what is the take-away from this lab and postlab about modeling? A good model is usually the simplest model that correctly answers your questions.

Installation and Construction

We use the Arduino IDE 2.3.2 software (with modifications and a 6.310 specific library) to communicate with, program, and plot results from our 6.310 controller board (based on the Teensy 4.1 microcontroller). Throughout the term, you will be using this software-board combination, along with lab-specific hardware, to design and experiment with algorithms that control rotor speed, rotating arm position, and even magnetic levitation.

Put Together Your Lab Kit. Staff will help you find parts.

Install the Software as described here.

Build and Test the Speed Control Hardware as described here.

Checkoff 1:

Demonstrate your speed control hardware.

  • Demonstrate the operation of your motor by plotting (and saving) results using mode 0. Describe what is plotted on the horizontal and vertical axes. (Hint: In mode 0, the Teensy samples the optical sensor once every 66.6\museconds.) Describe a method for determining motor speed from this plot. What is the speed indicated by the plot?

  • In mode 1, the speed of the motor is controlled by a feedback system. A potentiometer sets the nominal motor command which is added to a feedback command that is proportional to the difference between the desired and measured values of motor speed. Determine the maximum range of speeds that results from turning the potentiometer. Then set the desired speed to toggle between 14 and 16 RPS (by setting amp to 1) with a period of 10 seconds (by setting freq to 0.1). Compare results for feedback gains Kp of 1, 0.1, and 0.

  • Set a non-zero disturbance by changing the value of DisturbA (line 14 of sketch). Describe and document (by plotting) the effect of the disturbance on motor speed for feedback gains of 1, 0.1, and 0.

Structure of the Control System

The following block diagram illustrates the structure of the speed control system that we will develop.

As this diagram suggests, controlling the rotation speed of a spinning object requires three interconnected functions. Foremost of the three is an actuator that can be commanded to either accelerate or decelerate the object. Second, one needs a sensor to verify the object's speed. And thirdly, the focus of much of this class, one must design a controller that can determine effective actuator commands given the desired and measured speeds of the object.

Perturbations from Nominal

As you may have noticed when testing your speed-controlled rotor system, there is a nominal speed of 15 rotations/second (15 RPS), and an associated nominal actuator command. All the other speeds and commands are offsets to these nominal values, so our system is more precisely described by the abstract diagram below. We formulated our speed control problem in terms of perturbations from nominal values partly because it is a natural fit to the common control problem, maintaining constant speed (think automobile cruise control). But more importantly for our purposes, relationships between perturbations are likely to be more linear, and therefore more easily modeled. And good models, as we shall see thoughout the term, are essential precursers to designing good controllers.

Abstracting from Structure

Below is a functional block diagram of our speed control system, based on its physical structures. What should be immediately clear is that the functional block diagram looks nothing like the abstract block diagrams above. For example, is the motor the actuator? Or is it the motor plus the H-Bridge drivers? Also, the combination of the white eight-bladed rotor and the optical sensor does not produce rotation speed, it produces a signal from which the speed can be deduced. So does the combination really form the sensor in our abstract model?

Whether the problem is software or hardware or some combination of the two, finding a good abstract model is often the central challenge in any engineering design. As we noted in the introduction, a good model has enough detail to accurately assess design tradeoffs, yet is simple enough to reveal alternative strategies. But, how does one find a model good enough to answer one's questions, if one needs the model to determine what questions to ask? And how does one find a model that reveals strategies one does not yet know?

Modeling, it is impossible to teach, but fortunately, not impossible to learn.

Connecting Structures and Abstractions

In the case of our speed control system, we can extract an abstract model like the one in section 3.1, provided we ignore the structural boundaries. The speed sensor is a combination of the rotor, the optical sensor, and the function getSpeed in the Teensy sketch (which converts the time between falling edges in the optical sensor output into speed estimates, see the next section). The actuator in the abstract diagram is a combination of the function hbridgeBipolar in the Teensy sketch (which converts a motor command into a pulse-width-modulated signal), the h-bridge driver, and the motor connected to the white rotor.

We summarize the connection between abstract model and structural implementation in the figure below.

The Controller Block

As we can see from the figure in the previous subsection, there is a small part of the Teensy sketch that corresponds to the speed-controller block in the abstract block diagram. The actuator command, motorCmd in the sketch, is computed from the nominal command, nomCmd in the sketch, the desired perturbation in rotor speed, omega_d in the sketch, and the measured perturbation in motor speed, omega in the sketch. To make the meaning of omega and omega_d clearer, consider the example plot below. The plot was generated by running the speed control system in control mode (MODE 1), with omega_d set to be a unit amplitude square wave, the controller gain kff set to 0.025, and the square wave frequency set to \frac{1}{25}.

Below we show an incomplete block diagram for the controller, showing how the motor command is computed from the desired and measured motor speeds, as well as the nominal command (which is just added in). The block diagram shows how K_p, the proportional feedback gain, effects the motor command, but does not show the effect of K_{ff}. Be prepared to show how to add K_{ff} to the block diagram at checkoff.

Sensing Speed

The optical sensor generates a pulse every time a white encoder blade passes underneath it. More specifically, the propeller reflects the infrared light from the led on one side of the sensor to the optotransistor on the other side of the sensor, and when bombarded with infrared light, the optotransistor turns "on". The "on" transistor effectively "pulls-up" the IN5 input on the 6.310 controller board, increasing the voltage from close to zero to nearly three volts. Once the propeller blade passes out from under the sensor, the optotransistor turns "off", the IN5 voltage is pulled back down to zero by a resistor ground (see the schematic in the assembly guide).

The negative change in the voltage on IN5 "interrupts" the microcontroller, which determines the time since the last negative change, and computes the motor speed.

The signal generated by the optical sensor circuit is plotted below (notice the y-axis is normalized, so that 1000 corresponds to three volts), along with a diagram showing when interrupts are triggered on the Teensy, as well as when a control loop (which updates the motor command) executes. As the diagram should make clear, interrupts are generated every time a propeller blade passes under the optical sensor (eight times per rotation for our eight-bladed rotor), but the control loop only runs every m^{th} interrupt, where m is the setting of ticksperupdate (which you change from the serial plotter send window, by typing, e.g. "0 4" to set ticks per update to 4). Note that when ticksperupdate is zero, m is set to the maximum value of 8.

Checkoff 2:

How does ticksperupdate affect behaviors of your speed controller?

  • Determine the value of ticksperupdate for which noise'' in the speed measurement is largest. Show plots to demonstrate your result and briefly describe why noise levels depend on ticksperupdate.

  • Does changing ticksperupdate change the effect of K_{ff}? Show plots to demonstrate your result and briefly describe why noise levels depend on ticksperupdate.

  • Does changing ticksperupdate change the effect of K_p? Show plots to demonstrate your result and briefly describe why noise levels depend on ticksperupdate.

STOP HERE FOR THE FIRST WEEK!!!!

Difference Equation Modeling.

As we saw in the last two lectures, we can construct a first-order difference equation model for our feedback control system, and use the model to design a good controller. In general, we approach modeling in two steps:

  1. Apply a few physical prinicples to determine a parameterized form of the model and,
  2. Extract the parameter values from the results of carefully-chosen experiments.

Model Form

Recall that when first experimenting with the speed control system, we turned a small potentiometer to adjust a nominal motor command, C_0 (nomCmd in the Teensy sketch), to set a nominal motor speed, \Omega_0 (nomOmega in the sketch). We then perturbed the motor command (e.g. by setting non-zero feedback or feed-forward gains) and measured the perturbation in motor speed. In order to model our system more precisely, we will use lower case letters to denote perturbations from nominal,

c[n] = C[n] - C_0 \;\;\; \omega[n] = \Omega[n] - \Omega_0 \;\;\; \omega_d[n] = \Omega_d[n] - \Omega_0
where c[n] (corresponding to cmd in the sketch) is the measured perturbation in motor command, \omega[n] (corresponding to omega in the sketch) is the perturbation in measured motor speed, and \omega_d[n] (corresponding to omega_d in the sketch) is the desired perturbation in motor speed.

To start, changes in motor speed can be related to motor acceleration, \alpha, by

\omega[n] \approx \omega[n-1] + \Delta T \alpha[n-1],
where \Delta T is the time between speed samples. The motor is accelerated and decelerated by perturbations in two torques, one proportional to perturbations in motor command (which changes the motor current) and the other proportional to motor speed (due to friction and air resistance). Denoting \gamma and \beta as the proportionality constants for command and friction respectively,
\omega[n] \approx \omega[n-1] + \Delta T \cdot \left( \beta \omega[n-1] + \gamma c[n-1]\right).
Now, we have a form for the model and can start to design the experiments needed to determine \beta and \gamma for our particular speed control system (these are not precision motors, don't expect to get the same answers as your labmates).

Note: since the sample period is dependent on the motor speed, and the motor speed is being perturbed, we are explicitly ignoring the perturbations in \Delta T. We will assume \Delta T \approx \frac{1}{\Omega_0} (assuming the motor speed is in units of RPS).

Parameter Calibration

One way to generate responses from which to calibrate the linearized model is to use the AMP index in the send window to set the maximum value of omega_d to ten percent of the nominal speed (nominal speed = 15 RPS, so we want to set amp = 1.5 using the sender window), then use the KFF index to set K_{ff} so that omega reaches a steady-state that matches omega_d. You will need to set the input frequency low enough so that the motor speed settles between transitions (perhaps 0.05 hertz or ten seconds between transitions, using the send window and the FREQ index). The approach is illustrated in the following figure.

For the above senario, and in steady-state, \omega[n] = \omega[n-1]= \omega_d[n]. Since

c[n] = K_{ff}*\omega_d[n],
there is a lot of fortuitous cancellation, yielding a simple relation between our unknown parametes, \beta and \gamma.

You can derive a second relation involving \beta and \gamma by examining the immediate (rather than steady-state) behavior of the perturbed motor speed, \omega[n], in response to the step changes in \omega_d[n]. And the analysis of \omega[n] dynamic behavior will simplify if you exploit the fact that the system is linear, and that both \omega and \omega_d are in steady-state before the step change and eventually in a different steady-state afterwards.

See additional notes on this analysis in the notes from lecture 2b.

NOTE: You can stop the plot by clicking on the run-stop icon in the plotter, and when stopped, you can move the cursor to any plot to find its x-y values.

Testing Your Model

For the feedback case, the c[n] for your system becomes,

c[n] = K_p*(\omega_d[n] - \omega[n])
and the system will only be stable for a certain range of K_p. You should be able to derive, analytically, the range of stable K_p's given your calibrated values of \gamma and \beta.

Test your analysis against experiment by using the same values for the AMP and FREQ indices as you used for model calibration, setting K_{ff} to zero, and then slowly increasing K_p (starting with K_p=0) and watching the step responses. Determine when your system goes unstable and see if your experiments match your analytic predictions from your calibrated model.

Determine the Parameters for Your Motor

There are two coefficients to estimate (\beta and \gamma), and two types of information in your measured step responses, how fast the measured speed changes and the change in steady-state value.

For this checkoff, determine \beta and \gamma for your system, and test how well your model predicts the onset of instability (with ticksperupdate set to 8). For additional information about instability, see the notes from lecture 2a.

Enter your value of \beta:  

Enter your value of \gamma:  

Checkoff 3:
Explain how you found \beta and \gamma.

Determine "Optimal" Gains

Checkoff 4:
  • Calculate the maximum value of K_p for which the mathematical model of the system is stable.

  • Measure the maximum value of K_p for which the physical system is stable.

  • Compare the theoretical and empirically measured maximum values of K_p for stability.

  • Calculate the value of K_p for which the mathematical model of the system converges fastest.

  • Measure the value of K_p for which the physical system convergest fastest.

  • Compare the theoretical and empirically measured maximum values of K_p for fast convergence.

Collecting Data for the PostLab.

Today's lab focuses on modeling our speed control system. Generally, the model worked well -- right?!?   Perhaps we should look a little closer.

Our model was premised on the idea that we can feed back motor speed. But we cannot measure motor speed directly. Instead, we measured the times between ticks that correspond to the passage of spokes under our optical detector. We then estimated speed once per update'' by dividing the amount of rotation of the motor (1 revolution when ticksPerUpdate is 8 or 1/8 revolution when ticksPerUpdate is 1) by the time that elapsed during the update period (one period when ticksPerUpdate is 8 or 1/8 of a period when ticksPerUpdate is 1).

Do we introduce errors in this estimation process? Yes. Can we model those errors and correct for them? That's the question we would like to explore in PostLab 1.

We could characterize the errors introduced by our speed estimation method by varying the derivative estimator with ticksPerUpdate. With ticksPerUpdate equal to 8, the speed estimate is 1 revolution per 8 ticks. With ticksPerUpdate equal to 4, the speed estimate is 1/2 revolution per 4 ticks. And so forth. However, we have already seen that ticksPerUpdate also changes \Delta T.

For that reason, we will use a different parameter ticksPerEstimate that allows us to alter the derivative estimator without changing \Delta T.

Gather data to analyze in PostLab 1 as follows.

  • Set all of the parameters to their default values. Then set amp to 1, freq to 0.2, repeats to 3, and adjust kp so that the response is barely stable (it's fine if the measurement does not converge, as long as it doesn't diverge).

  • Leave ticksPerUpdate at its default value (0). Then make and save measurements with ticksPerEstimate equal to 1, 2, 4, and 8. You will need these plots for the postlab.

Something should look wrong. The problem is subtle -- but understanding it will provide new insights into our motor controller.

Checkoff 5:
Show your plots to a staff member and explain what looks wrong about them.