dc-motormodellingandparameter identification · the motor we experiment with is a simple dc-motor...

24
DC-motor modelling and parameter identification This version: November 1, 2017 RE G L E R T EK NI K A U TOM A T I C C O N T RO L LINKÖPING Name: P-number: Date: Passed:

Upload: vuonghanh

Post on 04-Apr-2019

212 views

Category:

Documents


0 download

TRANSCRIPT

DC-motor modelling and parameteridentification

This version: November 1, 2017

REGLERTEKNIK

AUTOMATIC CONTROL

LINKÖPING

Name:

P-number:

Date:

Passed:

Chapter 1

Introduction

The purpose of this lab is to give an introduction to a simple dynamical sys-tem, models, signals, and introduce the MinSeg robot and associated soft-ware. By performing experiments on a small DC-motor, some of its phys-ical parameters will be identified (also called estimated), and a first-orderdifferential equation describing the dynamical behavior of the motor willbe developed. As an alternative approach, a model is also developed usinga simple step-response experiment.

DC-motors are a central part of many products and mechatronic designs,and having a model of a motor is important for dimensioning, simulations,development of controllers, performance analysis etc.

Figure 1.1: Robotic hand using 15 DC-motors to position 5 fingers inde-pendently. Having good models of the motors is crucial whendeveloping a high-precision control system for the hand.

1

1.1 Hardware set-up

The lab is based on three main hardware components.

To begin with, we have a standard desktop computer. This computer isused to automatically develop and deploy code using MATLAB and SIMULINK

models.

To supply power to the DC-motor and perform measurements of motor an-gles, we use a board with an Arduino micro-controller which runs the auto-generated code. It also communicates with the desktop computer and thusallows us to look at the measurements.

The motor we experiment with is a simple DC-motor with two wheels at-tached. The motor is normally part of a LEGO Mindstorms kit.

The Arduino together with the motor and wheels is called the MinSeg.

1.2 Trouble shooting

The wheels turn slowly and/or erratically Make sure the tires do not rubagainst the motor. You can pull the wheels apart as they slide on the wheelaxis.

Complaints about COM port or connection when downloading to boardTry again. If it still fails, disconnect USB-cable and connect it again.

Complaints about OUT OF MEMORY Save your model and restart MAT-LAB.

The motor does not run Have you reinstalled the motor jumper after cur-rent measurements?

2

Chapter 2

Preparation

The questions below, and all questions throughout the document markedas Preparation must be done before attending the lab. Note that there areadditional preparation exercises in Chapter 3.

Solutions to all questions should be available upon request from the labassistant, and the preparation exercises in Chapter 3 are preferably writtenin this printed documented.

The scheduled time spent with the laboratory equipment is only a smallpart of the complete lab, as a major part is spent on the theoretical mate-rial during preparations. When the lab starts, it is assumed you have doneall preparations, and have a clear idea of the tasks that will be performedduring the lab.

Preparation 1 Read Section 2.1 and 2.6 in the course book by Ljung & Glad.

Preparation 2 Verify (by differentiation, not by solving it from scratch!) thaty(t ) = K(1 − e−t/T)c is the solution to the first-order differential equationT y(t ) = −y(t )+Ku(t ) for an input switching from u(t ) = 0 to u(t ) = c att = 0 (i.e., a step-response of amplitude c), with initial condition y(0) = 0.

Preparation 3 The constant K in the form above is called the static gain ofthe system and describes how much the system amplifies constant inputs insteady-state (i.e., when derivatives are 0 and y(t ) has converged to its sta-tionary value). Given the differential equation with input u(t ) = c and solu-tion as above, show that the output y(t ) converges to Kc when t →∞. Do this

3

using two different strategies. One approach where you simply analyze thesolution given above, and another approach where you study the differentialequation and exploit the fact that you know the value of y(t ) in steady-state.

Preparation 4 The constant T in the first-order differential equation in theabove form is called the time-constant and descibes how fast the system re-acts to changes on the input. Given y(t ) = K(1−e−t/T)c, what value will y(t )have when t = T?

Preparation 5 The time-constant is more generally defined as the time ittakes before the output reaches a certain percentage of its final value, whenthe input has made a step change. To be consistent with the definition in thefirst-order system above, what percentage is this?

Preparation 6 Sketch the function y(t ) = K(1−e−t/T)c for K = 3, T = 10 andc = 2. Particularly specify the value attained when t = 10.

Preparation 7 An oven placed in a room with temperature 0 is reasonablywell described by the differential equation T y(t ) =−y(t )+Ku(t ) where y(t )is the oven temperature and u(t ) is the supplied power. In an experimentperformed to identify T and K, the oven was turned on with u(t ) = 1000Wat t = 4 (not at t = 0!), and the oven temperature was measured. Based onthe results seen in Figure 2.1, what is the time-constant T and static gain Kof the oven? Hint: What percentage of the final temperature should havebeen reached T minutes after the oven was turned on)

Preparation 8 Write the differential equation ay(t )+ by(t ) = cu(t ) in theform T y(t ) = −y(t )+Ku(t ), i.e., express the time-constant T and gain K interms of a, b, and c.

Preparation 9 Read the complete lab-pm. There are some theoretical ques-tions in the pm which you are supposed to complete as preparation.

Preparation 10 Print this document. You must bring a physical copy to thelab.

4

Figure 2.1: Step-response experiment of an oven. At t = 4 the input ischanged from 0 to 1000, and the oven temperature is recorded.

5

Chapter 3

The lab

As explained above, the lab will primarily consist of experimentation anddata collection, using theoretical results and strategies derived during yourpreparation.

Items labeled Preparation are questions you are supposed to solve and fillout before attending the lab.

Items labeled Task are performed when attending the lab and you have ac-cess to the hardware.

3.1 DC-motor modeling

Consider a standard DC-motor model as depicted in Figure 3.1.

The electrical and mechanical differential equations governing the dynam-ics are

uA(t ) = Ldi (t )

d t+Ri (t )+kvω(t ) (3.1)

kai (t ) = Jω(t )+ f ω(t ) (3.2)

where uA(t ) is the voltage applied to the motor, i (t ) is the current in themotor, and ω(t ) = θ(t ) is the angular velocity of the motor shaft. The prod-uct kai (t ) is the torque generated by the motor, and f ω(t ) is the velocitydependent friction in the motor. The parameters in the model are

6

Figure 3.1: DC-motor. When a voltage uA(t ) is applied on the motor, a cur-rent i (t ) develops and accelerates the motor. As the angularvelocity ω(t ) = θ(t ) increases, the friction f ω(t ) in motor anddrive shafts, and back-emf (electromotiv force) kvω(t ), reducesthe acceleration ω(t ) = θ(t ).

• L: Motor inductance, assumed to be 0.

• R: Motor armature resistance, unknown and will be measured di-rectly.

• kv : Back-emf constant. Unknown and will be identified through steady-state analysis.

• ka : Torque constant. Unknown and will be identified through steady-state analysis. Related to kv .

• f : Friction coefficient. Unknown and will be identified through steady-state analysis.

• J: Motor inertia. Unknown and will be identified through dynamicanalysis.

For a perfect motor with no energy losses, it holds that ka = kv . However,in practice this does not hold, and we know that

ka ≈ 0.65kv . (3.3)

Our task in this lab is to perform experiments to identify R, kv (and thuska), f and J, to obtain a dynamical model which relates the applied voltageuA(t ) to the angular velocity ω(t ). This model will be used in later labs.

7

3.1.1 Rotary encoder

The motor is equipped with a simple encoder1 to measure rotation of themotor shaft. The encoder uses n = 12 holes with a so called quadraturedesign, meaning it has a resolution of 48 pulse changes per revolution. Themotor shaft is connected via a gear with transmission ratio 15, meaning theencoder will deliver 48·15 = 720 pulse changes per motor shaft revolution,leading to a maximal theoretical accuracy of 0.5.

Figure 3.2: Encoder in motor

Preparation 11 One full revolution of a wheel will give us a measurementfrom the encoder of 720. However, we wish to work in standard units of ra-dians, and would thus like to obtain the value 2π. With which scaling gainshould the measurement be multiplied with to accomplish this?

Open the folder minseg on the Desktop, and start MATLAB and SIMULINK

by double-clicking the SIMULINK model dcmotor/template1. This SIMULINK

scheme graphically describes the code that will be generated and down-loaded to the Arduino micro-controller.

Some important features are marked in Figure 3.3

1A small light-source shines at the right-most cog in the figure, and by detecting whenthe light is blocked or let through the holes, rotation is detected

8

Figure 3.3: Template SIMULINK model

1. The value here will be sent by the Arduino micro-controller to themotor driver, and is our control signal u(t ). Due to voltage lossesinternally on the board in the motor driver chip, the voltage uA(t )which actually is applied to the DC-motor is lower than u(t ).

2. The Arduino micro-controller counts pulses on the encoder, and thisvalue can be used for computing the angle of the motor.

3. We convert the number of pulses counted to rotation angle θ(t ) inradians. This is done in the Gain block.

4. The SIMULINK model is specified to run in External model. This al-lows the Arduino to communicate with MATLAB continuously.

5. When running the model in external mode, the Arduino micro-controllercan send data to MATLAB and SIMULINK. Here, we send the scaledencoder measurements to a plot scope to display them in real-time.

6. In external mode, we can also send information from MATLAB to theArduino micro-controller. We will use a slider gain to change the re-quested motor voltage u(t ) while the code is running. We will be ableto multiply the constant 1 with values between 0 and 4.5, i.e., request-ing up to 4.5V.

7. We compile, download and start the code on the Arduino micro-controllerby pressing the green run button.

8. We stop the code by pressing the stop button. Must be one beforeediting the model

9

3.1.2 Identification of armature resistance

The resistance R of the motor is obtained by measuring the resistance overthe motor using a multimeter. However, we do not have direct access to thecable attachments. Instead, we perform this measurement on the Arduinoboard. The resistance of the motor can be obtained by measuring the resis-tance between the two points labeled M1A and M1B, as illustrated in Figure3.4 and Figure 3.5. These two points are in connection with the motor at-tachement, and placed on the board to simplify motor measurements.

Figure 3.4: Motor resistance and voltage measurements are done betweenthe points labeled M1A and M1B next to the motor connection.

Task 1 (Resistance identification) Make sure the Arduino board is unpow-ered (i.e., USB cable disconnected). Put the multimeter in resistance mea-surement mode (Ω), and measure the resistance. You typically see a valuebetween 3Ω and 6Ω. Connect the USB cable after performing the measure-ments. Note that it takes the multimeter a couple of seconds to stabilize on afinal value.

10

Figure 3.5: Schematic picture of the measurement points M1A and M1Band the relationship between the requested control voltage u(t )and the actually applied voltage uA(t ). A large voltage loss oc-curs in the cheap motor driver chip (actual pin configurationmight not be correct, picture is only for illustration)

3.1.3 Steady-state measurements for identification of ka, kv

and f

In a batch of experiments, we will study the steady-state currents and angu-lar velocities, for different constant applied motor voltages. For a constantapplied motor voltage uA(t ) = uss , we denote the corresponding obtainedsteady-state value of the current and applied voltage

iss = limt→∞ i (t ) (3.4)

ωss = limt→∞ω(t ) (3.5)

Preparation 12 Based on (3.1), which equation holds at steady-state, andhow can this relationship be used to estimate kv by measuring steady-statevalues of voltages, currents and angular velocities? You can assume R isknown by now.

To proceed, we must obtain measurements of the voltage uA(t ) on the mo-tor, the current i (t ) in the motor, and the angular velocity ω(t ). In the fol-lowing paragraphs we explain how this is done. The actual measurementsare done later!

11

Measuring motor voltage

When the motor is spinning at steady-state, the applied voltage uA(t ) canbe measured over the same positions as we did for the resistance measure-ment. To do so, we will put the multimeter in DC-voltage mode (V=), andmeasure the voltage between M1A and M1B.

Measuring motor current

To measure current in the motor, we will open the electrical circuit (volt-ages are measured in parallel over objects, while currents are measured inseries). The board is prepared for such a measurement. On the board justin front of the motor connection, there is a jumper (with a colored tapehandle) which can be removed to open the electrical circuit. To measurethe current, we will put the multimeter in current (mA) mode and close thecircuit with the multimeter.

Figure 3.6: By removing the jumper next to the motor connection, the cir-cuit is opened and we can measure current over the two pins.Be careful not to bend the pins by applying excessive force.

12

Measuring angular velocity

The encoder only gives us angles, so we have to estimate the angular veloc-ity. Given two measurements of the angle θ(t ) and θ(t −Ts) where Ts is thesampling time (in our case fixed to 0.03s), the most basic estimate of theangular velocity is the Euler backwards approximation

ω(t ) = θ(t )−θ(t −Ts)

Ts(3.6)

Unfortunately, the estimate obtained from this simple computation willnot behave well when the code runs in external model. The problem is thatthe Arduino computer is slow, and when it has to communicate with MAT-LAB, it will not be able to finish computations in time sometimes, whichmeans that the actual sampling time will be different from the fixed value0.03s that is used in the computation. As an effect, the derivative estimatewill look noisy. We will counteract this by continuously taking the averageof the last 20 derivative estimates (a low-pass filter called an FIR filter)

Open the SIMULINK component library (either by writing simulink in theMATLAB command prompt, or through the menu in your SIMULINK modelView/Library browser.

Task 2 (Code for velocity computation) Update your SIMULINK model toincorporate the derivative computations as in Figure 3.7. The block DiscreteDerivative (which implements the Euler approximation) and Discrete FIRfilter are both found under Simulink/Discrete. A so called plot scope can befound under Sinks, or simply copy the scope already available in the model.Note that the text under blocks is completely arbitrary, and you can changethis. Double-click the FIR filter block and change the code in the field coeffi-cients to repmat(0.05,1,20) (everything in boxed bold text!). This code willcreate a vector of length 20 with all elements equal to 0.05, which leads to afilter which takes the average of the 20 last values. Save your model.

13

Figure 3.7: Updated SIMULINK model with derivative computation.

3.1.4 Experiments

Let us now perform the experiments. We will run the motor with differ-ent requested voltages u(t ) = 2.5V, u(t ) = 3.5V and u(t ) = 4.5V (set in themiddle edit box in the slider gain while running), and record the resultingsteady-state applied motor voltage uA(t ) = uss , currents iss and angular ve-locities ωss .

Task 3 (Measurements) Attach the USB-cable (preferably in the USB con-nection on the monitor) and download your code to the Arduino by pressingthe green run button. For convenience, perform the experiments in two steps.

In a first run, record steady-state motor voltage uss (multimeter) and angu-lar velocity ωss (plot scope) with the the three different requested voltages.To set the requested motor voltage in the Slider gain precisely, use the middleedit box. In the angular velocity plot, you will have to right-click in the plotand select auto-scale, or press auto-scale in the plot menu. Record the valuesof all voltage and angular velocity measurements in the table below.

In a second run, remove the motor jumper and repeat the 3 experimentsmeasuring the current iss and insert in the table. The columns for kv andf will be filled later during the lab.

You should see applied voltages slightly below the requested voltages, cur-rents in the range 20mA to 50mA, and rotational velocities up to at most 7rad/s or so.

14

Requested u(t ) uss ωss iss kv f

2.5V3.5V4.5V

Task 4 (Compute kv estimates) Once you have all the measurements, youcan compute estimates of the back-emf constant kv using your result in prepa-ration 12. Compute estimates of kv based on the three experiments and in-sert in the table.

Task 5 (Compute final kv estimate) To decide on a final value of kv one canfor instance compute the average value of the three estimates. However, amore robust approach which will guard us against a failed experiment (badmeasurement, mistake in computation,...), is to take the median instead,which in this case will be the middle value. What is your final estimate ofkv ?

Task 6 (Compute ka) With kv available, what is the estimated value of thetorque constant ka?

With all measurements available, and the estimated value of ka , we areready to use (3.2) to estimate the friction coefficient f . However, the simplelinear differential equation does not tell the whole truth. Besides the lin-ear velocity dependent friction torque f ω(t ), there is also a static frictionin the motor which prevents the motor from starting to turn and affects theperformance at low velocities. You can see this if you decrease the controlsignal u(t ) until the motor just barely turns. The current will be signifi-cantly non-zero already at that point. You would also see this if you wouldplot the computed torques kaiss against the angular velocity ωss , as exem-plified in Figure (3.8). The friction coefficient f is the slope of the curve,but the curve will not pass through the origin.

15

Figure 3.8: Typical torque and angular velocity measurements. A signifi-cant amount of current (i.e., torque kaiss) is lost on overcomingthe static friction, the torque-angular velocity line does not gothrough the origin.

If we let i0 denote the current required at very low speed, our model changesto (valid when i (t ) ≥ i0)

ka(i (t )− i0) = Jω(t )+ f ω(t ) (3.7)

Preparation 13 How can f be computed from steady-state measurementsiss and ωss if we know i0 and ka , using the model (3.7)

Task 7 (Identify i0) Find out the current i0 which is used when the motorturns very slowly by decreasing the requested voltage until it is turning very

16

slowly. When you are done, turn the voltage to 0, stop the code, and re-installthe jumper.

Task 8 (Compute f ) Use the model and the value of i0 to compute estimatesof f from the three experiments, and complete the table. Use the middlevalue as an estimate of f .

17

3.1.5 Dynamic analysis for identification of J

Through static experiments (i.e., analysis of steady-state signals), we havemanaged to identify 3 out of the 4 parameters. The parameter J requiresus to study the dynamic behavior. The fact that we need dynamic analysisto estimate J is natural as it only enters our equations multiplied with ω(t ),which is 0 in a steady-state analysis.

The constant J effectively makes it harder to accelerate the motor. Thelarger (heavier wheels) J is, the longer time it will take for the motor to reachsteady-state velocity. Hence, our analysis will be based on estimating thetime-constant of the system from uA(t ) to ω(t ).

By combining (3.1) and (3.2) we arrive at the differential equation

RJω(t ) =−(R f +kv ka)ω(t )+kauA(t ) (3.8)

Preparation 14 Prove (3.8)

Preparation 15 Write the differential-equation (3.8) as a standard first-ordersystem Tω(t )+ω(t ) = KuA(t ), i.e., derive the time-constant and static gain ofthe system (3.8), in terms of the parameters R, J, f , kv and ka .

18

Preparation 16 If you know the time-constant of the system, and all param-eters except J, how can you compute J?

In our final experiment, we are going to study the transient behavior ofthe velocity during a step-change in applied voltage. Open the SIMULINK

model template2 which has been prepared such that it will generate a se-ries of steps in requested voltage u(t ) from 0V to 4.5V, which will lead to aseries of steps in applied voltage uA(t ) following your previously developedtable. The approximate angular velocity is sent to MATLAB and recorded ina variable data in the MATLAB workspace.

Task 9 (Collect step-response data) Download and run the modified model.You should see a sequence of steps being performed on the motor. Let it per-form a couple of those, and then stop the code (preferably when no voltage isapplied).

Task 10 (Study step-response data) Plot the step-responses (slightly smoothedto make it easier to read values) in MATLAB by running

plot(data.time,smooth(data.signals.values))

19

Study the plot of the steps (zoom in on a single step!). What is the steady-state value of ω(t ) in the steps? What was the applied steady-state voltageuss on the motor when requesting 4.5V according to earlier experiments? (ofcourse, the steady-state angular velocity should coincide with the value inthe table also). Based on this, what is the experimentally derived static gainfrom applied voltage uA(t ) = uss to angular velocity ω(t )?

Task 11 Based on the plot of the step-response of the motor, what is the ex-perimentally derived time-constant?

Task 12 Based on the experimentally derived time-constant and previouslyderived physical parameters, what is the value of J?

Task 13 To summarize, what does the model look like (with numerical val-ues) if you write it as a standard first-order model in the form used in prepa-ration 2 and 7.

20

Comments on the model

A lot of effort has been placed in this lab on experimentally identifying thephysical parameters J, R, f , kv and ka . However, in the end, these 5 pa-rameters are used in a first-order system which just as well can be defineddirectly from the experimentally obtained time-constant and static gain.In many situations, this modeling approach is just as useful, as it com-pletely describes the input-output behavior of the system. A simple step-response experiment, and we have a sufficiently precise model to simulatethe system, design controllers, and analyze performance. Performing step-responses on system to quickly derive models is extremely common prac-tice, and often leads to sufficiently good models to be used for control.

The first-order model derived in this lab is used for analysis in forthcom-ing labs, and is part of a complete model of the MinSeg, required for thedevelopment of a balance controller.

21

3.2 Summary and reflections

Summarize and reflect on concepts in this lab.

Questions Answers

1. The MinSeg DC-motor is ä a model

ä a system

ä a signal

2. The differential equationdescribing the MinSegDC-motor is

ä a model

ä a system

ä a signal

ä a parameter

3. The time-constantdescribes

ä How fast the system reacts tochanging inputs

ä Which constant value the outputwill converge to

4. The static gain Kdescribes

ä The ratio between the output andinput amplitudes in steady-state

ä The amplitude of the output

5. The final value of theoutput depends on

ä The time-constant

ä The input amplitude

ä The static gain

6. A first-order lineardifferential equation is

ä Uniquely defined by a time-constant and static gain

ä Is not uniquely defined by time-constant and static gain

Most unclear to me is still: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

22