None Lab_4

Challenge

You will need to use a model of your Zumo's behavior in order to be able to predict how far and fast it will go given different motor inputs for Project 1. We know that the Zumo's motors will be an important part of that model, so we need to develop some experience generating a dynamic model of an electric motor.

The challenge then is to develop this understanding by creating a validated model of your workstation motor using experimentally collected data that will allow you to predict the output for any step input. Since you are preparing to model the Zumo with different payloads, you will also need the model of the workstation motor to be able to handle physical changes in the system. For example, what if a "load" is added to the workstation motor? Therefore, you will need to develop a physics-based model that can account for these kinds of changes.

Model Development - Scoping: Capturing a Step Input Response

We'll follow the the disciplined process from Week 03B and begin by identifying the inputs and outputs of the system. As you've already seen in your previous labs, the input to the motor is voltage and the output is angular velocity.

In order to scope the order of the differential equation we would use to model the system, we'll need to record the response of the motor's angular velocity to a step input in voltage. It will require a few steps to develop this experimental capability.

Workstation Motor

An exploded view of the Pololu 50:1 gearmotor that will be used for the testing is shown below. Find the motor windings, commutator and brushes on the diagram.

Consider revisting the material on DC motors from Lab 1 if these terms or concepts are not familiar to you.


image-3.png

Relevant characteristics of the motor are provided by the manufacturer.

Your motor has a peak current of 1.5 amps (3 times the nomimal output of a typical USB connection) so the USB cable can't provide the power you need for this experiment. Use the power supply provided by your instructor and connect it to the workstation through the "5V power jack" labeled in the hardware resource: ME480 Portable Workstation

Measuring Motor Position

In order to measure the speed of the motor we will use the Pololu motor encoder that is attached to the back of the motor. The encoder can be used to measure both the position and speed of the motor. An image of our encoder is shown below. The disk has six embbeded magnetic poles (3 north, 3 south) that can be sensed by the Hall effect sensors attached to the small circuit board.

image-2.png

The encoder uses a method called quadrature to let us measure the incremental movement of the disk as well as its direction of rotation. The two Hall effect senors are 75° apart. That makes them 1.25 the distance between the magnets which are 60° apart. The animation below shows how this works with a wheel that has more magnets but with sensors separated by the same 1.25X the space between magnets. If you watch the animation you will see this positionging allows the system to measure position to 1/4 of the tick spacing and to sense the direction or rotation.

QuadratureAnimation.gif

Looking at a snapshots of the encoder output below, if the encoder channel B transitions to false after channels A and B were both true, the disk is moving clockwise. If channel A transitions to false after channels A and B were both true, the disk is moving counterclockwise (as shown in the animation above). This gives us the relative motion of the disk.

image.png http://www.creative-robotics.com

If we track the number of transitions, we can measure the position of the motor from its starting point.

If we measure the time between transistions or we count the number of transitions over a fixed time, we can determine the speed of the motor. The hall-effect sensors and magnetic poles on the disk are arranged such that each sensor can measure 3 N-S or S-N transitions per revolution of the disk. This means that with a 51.45:1 gear ratio, a 3 pole-pair disk and quadrature we can measure to 1/3 x 1/4 x 1/51.45 of a rotation of the output shaft (0.00162*rotation or 0.6°).

Reading the motor encoder signal

The encoder is already connected to your arduino through the motor cable. You can find the signals for the MOTOR2 connector on your Workstations pinout diagram.

The ME480FSM library has been updated to allow you to read the signals from the encoders, but before you install it you will need to delete the older version of the library from your software. To remove the old version, in the Arduino IDE go to File > Preferences > Sketchbook location. Now from the operating system (Windows or Mac OS), open that folder and the libraries folder from that location. From there you should see and then delete the ME480FSM folder.

With the old library files removed, you can install the new library zip file by downloading it here.

Once the library is installed, review the documentation for the new classes FSMEncoder1 & FSMEncoder2. These provide encoder information for the MOTOR1 and MOTOR2 connectors respectively.

Confirming your motor is connected to MOTOR2 and the wires coming from the load inertia are NOT CONNECTED TO THE WORKSTATION (these will be used in Lab 5), write an Arduino code that reads the encoder counts from your motor.

Run the program, and with the motor unpowered, rotate the encoder disk at the end of the motor gently by hand and see the change in the counter value in the serial monitor. How many counts (approximately) for a complete revolution of the motor output shaft? Enter your answer below and compare it to your prediction (explaining where your prediction came from)

YOUR ANSWER HERE

Measuring motor speed

Now it's time to run your motor and measure its speed.

Confirm your motor is configured as in Lab 3 so it is disconnected from the inertia module.

Confirm with your instructor you safety system code from Lab 3 is approved for use

Make of copy of your lab 3 code and add the encoder code from above. Read the encoder and calculate the angular position of the motor shaft in radians and output that to the serial monitor. Confirm the angular position is reasonable by moving the motor shaft by hand and comparing the calculated position and the actual shaft position

Now add a calculation for the speed of motor output shaft coming out of the gearbox in radians per second by using a numerical appoximation of the derivative every time through the loop. Use the micros() function to calculate the elapsed time between measurements to improve the accuracy of the numerical approximation.

Run the code with the motor running slow enough you can estimate the speed visually. Display the speed in the serial monitor and confirm the calculated speed is comparable to your observation.

Now find the maximum speed of the motor in rad/sec and determin how many encoder counts you measure during one loop of the program.

Copy the table into the cell below to provide your answer

Parameter Value
encoder counts per loop
max speed (rad/s)

YOUR ANSWER HERE

Place a PROPERLY FORMATTED copy of your Arduino code in the cell below.

YOUR ANSWER HERE

Recording a Step Response

With this new measurement capability in place, you can use it to judge a reasonable order for the differential equation that might model your system. To do this you will need to record the response of your system to a step input. Your code will allow you to set an Initial Voltage and a Step Voltage using potentiometers. Modify your code to enable the following capabilities:

The safety modes should control the motor relay just the way they did in Lab 3. We will be changing how we use the LCD panel and how we control the motor in RUN mode.

In FAULT mode:

  • The LCD panel should be cleared and then print FAULT in the upper line of the panel.

In SAFE mode:

  • Read the counts from Potentiometer 1 (POT 1) and convert the counts to a voltage from 0V to 5V. This voltage is the initial voltage that will be sent to the motor. Display the initial voltage on the first line of the LCD: "P1:" [Voltage].
  • Read the counts from Potentiometer 2 (POT 2) and convert the counts to a voltage from 0V to 5V. This voltage is the amount the voltage to the motor will change (step voltage) when BTN 1 is pressed. Display the step voltage on the second line of the LCD: "P2:" [Voltage].
  • As you change each potentiometer, the corresponding displayed voltage should also change.
  • The values of the initial and step voltages may only be changed in SAFE mode. If you move the potentiometer when you are in any other mode the initial and step voltage values should remain unchanged.
  • You can format the output of a float variable by adding the number of significant digits in the print statement after the variable name, i.e. LCD.print(MyVariable, 2) will print 2 significant digits. This works for both the LCD and Serial print commands.

In RUN mode

  • When you enter RUN mode the motor will be sent an input voltage equal to the inital voltage level.
  • When BTN 1 is held down, the motor input voltage will change from the initial voltage to the initial voltage + the step voltage. When BTN 1 is released the motor voltage will return to the initial voltage.
  • If the sum of the two voltages is less than 0V or greater than 5V, the motor input voltage will be limited to no less than 0V and no greater than 5V.
  • Use the serial monitor to output 4 columns:

    current time from micros() | the motor's initial voltage | the motor's current voltage | motor angular velocity

  • To maximize your sampling rate, set your baud rate to 115200 in setup using Serial.begin()

  • As before, if you leave RUN mode the motor should shut down.

The LCD display should only be updated in the FAULT or SAFE modes to ensure a high sample rate for your data capture

*Place a copy of your main Arduino code in the cell below.

YOUR ANSWER HERE

To perform a step-input experiment, adjust the value of the initial voltage so the motor just achieves a speed where it runs "smoothly" and there are no obvious variations in angular velocity as it rotates. Now adjust the step voltage to achieve a maximum voltage near 5V, but not exceeding 5V.

Perform a step input experiment and save the step input data from the serial monitor to a text file. Upload the file to your Lab_4 jupyter folder and read it into the Octave cell below using the load() command.

In a labeled plot with units, show the angular velocity vs. time

In [1]:
% YOUR CODE HERE
error('No Answer Given!')
error: No Answer Given!

In the cell below, explain what order differential equation you would use to model your system and why.

YOUR ANSWER HERE

Filtering your motor speed

You may notice that your plot of motor speed appears "noisy." One way to handle a noisy signal is to filter it! As you may recall from ME331, a filter can be represented in the Fourier or Laplace domain as a transfer function relating an input (an unfiltered signal) to and output (a filtered signal). It is also true that we could write a simple first-order "RC" type filter as an input-output differential equation relating the input (raw unfiltered signal) to an output (filtered signal). You might see a filter of this type written as the following differential equation:

$$y_{filt} + RC\dot{y}_{filt} = y_{raw} $$

You have experience from ME352 and ME331 that RC in this equation represents the time constant $\tau$. Its value will effect the output.

Because the raw value $y_{raw}$ is not a constant "step-like" input, but something that varies in time, an analytical solution to the filter's differential equation is impractical. However, in W04A, it describes that you can use numerical integration to solve a differential equation. We can rearrange the equation:

$$\dot{y}_{filt} = \frac{1}{RC}\left(y_{raw} - y_{filt}\right)$$

And write it for ANY simple, first-order filter with a time constant $\tau$:

$$\dot{y}_{filt} =\frac{1}{\tau}\left(y_{raw} - y_{filt}\right)$$

You can use this equation, Euler integration, and your raw velocity data to numerically filter the raw values of your motor speed recorded above. Since this is a filter of your deisgn, the time constant $\tau$ of the filter is your choice. A good filter time constant $\tau$ for this kind of low pass filter is one that removes noise (higher frequency components) without substantially changing the dynamics of the original response (lower frequency components).

Build your filter by:

  • Using the finite difference approximation for $\frac{dy}{dt} (k)$ shown in W04A to substitute for the left side of the equation.
  • In your Octave code, use your velocity vector as the "input" in this equation y_raw
  • Create a for-loop that calculates y_filt(k) (k is the current time step) from y_raw(k-1) and y_filt(k-1) (k-1 is the previous time step)
  • You will need the size of the time step from your time vector. You can calculate that as T = t(k)-t(k-1)

Produce a plot of filtered and unfiltered motor speed vs. time in the cell below.

In [2]:
% YOUR CODE HERE
error('No Answer Given!')
error: No Answer Given!

In the cell below, discuss your choice of filter time constant $\tau$. How does it compare with the time constant of your motor's response to the step input?

YOUR ANSWER HERE

Model Construction: Select elements and connect in a system representation

Following the disciplined process from Week 03B, select elements that represent the physics of the actual motor and construct a system representation (not a linear graph yet, just a schematic showing how the elements are connected).

YOUR ANSWER HERE

Model Construction: Linear Graph and System Equation

In the cell below show your linear graph, differential equation development, and the single equation that describes the angular velocity as a function of time with voltage as an input.

YOUR ANSWER HERE

Model Construction and Validation: Parameter Estimation

To complete the model you will need to estimate the value of the constants associated with the lumped parameter models. Some may be determined from manufacturer data. The remainder will have to be determined by fitting the model to the experimentally measured response of the real system.

Note that by considering the solutions to 1st and 2nd order linear differential equations a 1st order response is described by 2 parameters and a 2nd order response is described by 3 parameters. If you have more parameters than a single response can determine, you will need an additional step response to have enough information to fit the additional parameters. However, just changing the input is not sufficient. Consider, for example the steady state gain. We know that it will be related to the parameters of a differential equation.

$$K_{ss} = \frac{\Delta y_{ss}}{\Delta u_{ss}}$$

However, if the input were doubled, the output would be doubled as well (since we are expecting the system to behave linearly) and so no new information is revealed. Therefore, you will need to change HOW the system responds, not its input. You can achieve this by changing the system in KNOWN way. We will accomplish this by using the load inertia that you can attach to the motor shaft, adding a known inertia to the system and allow you to generate a new response and determine the additional parameters. Using the formula for the mass moment of inertia of a cylinder $I_z = \frac{mr^2}{2}$, knowing its dimension and density, you would be able to determine the mass moment of inertia for your load is 0.000111 $kg\,m^2$

If you do fit your model to 2 different responses, it must simultaneously fit both responses with both modeling equations to ensure the parameters meet both conditions.

To attach the load inertia, use the flex coupling provided by your instructor. Attach it to the motor shaft and inertia shaft by tightening the set screws down on the FLATS of the shafts:

image-2.png

Check with your instructor if you have any questions on the assembly and attachment of the load inertia.

In the cell below, read in your expimental data and fit the parameters of your model to the response(s) you recorded. On ONE plot, show the responses for both configuration and the fit of a SINGLE model to both configuration. Label the graph axis and series.

In [3]:
% YOUR CODE HERE
error('No Answer Given!')
error: No Answer Given!

List the parameters and values you found that complete your model by using the table format provided in the markdown cell below

Parameter Name Value Units
Param 1 value ( )
Param 2 value ( )

YOUR ANSWER HERE

Model Validation: Coast Down

All of the scenarios you have considered for your model involve the motor operating under power. However, In project 1, your zumo will be starting and stopping from rest, so it is important to know whether this requires any additional modeling attention.

Let's examine the linearity of a start from rest. Use your existing code to capture a step up in voltage from 0V to 2.5V and from 0V to 5V for the motor with the load inertia attached.

Plot the motor angular velocity vs time on the same plot in the Octave cell below

In [4]:
% YOUR CODE HERE
error('No Answer Given!')
error: No Answer Given!

Now lets examine what happens when you turn OFF the motor and "coast-down" to 0 velocity as your zumo would when you command it to stop.

A coast-down experiment will require a modification to your code. Add the following functionality:

In RUN mode

  • When BTN 2 is held down, the motor relay will be DISCONNECTED and the motor voltage will be set to 0V.
  • When BTN 2 is released the relay will reconnect and the motor voltage will return to the initial voltage.

Capture a cost down with the the load inertia attached and the motor initial voltage set to 5V. Plot the motor angular velocity vs time in the cell below

In [5]:
% YOUR CODE HERE
error('No Answer Given!')
error: No Answer Given!

In the cell below, discussed the linearity of this physical system during a step up and step down.

In [6]:
% YOUR CODE HERE
error('No Answer Given!')
error: No Answer Given!

To contribute to your consideration of your system's response, you might remember a discussion from physics or dynamics regarding "sliding" or "dry" friction. This is the physical phenomenon you might remember from physics or dynamics where the friction force of a sliding object is dependent on the speed.

The same friction applies to rotating systems. The plot below suggests that the actual behavior of the torque resulting from the friction, $T_F$, is fairly complicated. However, a simplified model for the friction that is shown is called the Coulomb friction model. Here the friction is modeled with 2 values. When the angular velocity is 0, there is a static frictional torque that reaches a maximum value of $T_S$ just before it begins to move and then the frictional torque is modeled as a constant dynamic value $T_D$.

image-6.png

This model suggests that IF (AND ONLY IF) THE MOTOR IS MOVING, this phenomenon could be modeled as a CONSTANT torque $T_D$. This is a fairly simple edition to your existing model, HOWEVER, a constant in your differential equation (the mathematical model of your system) will make the equation NONLINEAR!

How will you handle this if you want to account for this effect on your workstation or in your Zumo? Linearize!