You are on page 1of 6

MAE 106 Laboratory Exercise #6 Position Control of a Motor using LabView and Arduino

University of California, Irvine Department of Mechanical and Aerospace Engineering

RE !"RE# PAR$% Switching current amplifier Bread oard Small Motor !a "iew Data Ac#uisition System $ires

1 "ntroduction
%ote& 'here is no (solution) for this la * you should e a le to follow along with +ust this document, 'he purpose of this la oratory e-ercise is to learn how to use a computer .or microcontroller/ to control a motor, In previous la s, you used operational amplifiers to control motors, 0p amps are ine-pensive and respond #uic1ly, ut re#uire changing resistors and capacitors to change the control gains, Another common way to implement a control law is to use a computer, 0ne of the ma+or enefits of using a computer is that you can e-press the control law and control gains in software, 'hen, changing the control law or control parameters +ust involves typing in new software code, 'his will e really useful for your final pro+ect, 'he asic idea of computer2 ased control is to& 3, electronically measure the system performance .e,g, the motor shaft4s position with a pot/ 5, read this measurement into the computer using an analog2to2digital .A6D/ converter 7, calculate an appropriate control law in a program running on the computer, 8, generate a voltage output to the motor with a digital2to2analog .D6A/ converter 9or this la , you will first use !a "iew software on a :C connected to a %ational Instruments data ac#uisition system .DA;/ for the analog2to2digital conversion .reading the motor shaft position in/, and for the digital2to2analog conversion .sending a voltage command to the current amplifier6motor/, !a "iew is a sophisticated graphical coding program, and can e used with many different types of DA;s, 9or A6D and D6A conversion we are using a %I USB2<==> which has ? channels for single ended analog inputs .or 8 channels for differential inputs/ up to @3= "olts for input and = to A volts output, with input differential 38 its resolution and 37 its single2 ended and is capa le of converting up to 8?B samples per second,

:icture from& Ch, ? Data Ac#uisition, Introduction to Mechatronics and Measurement Systems, 5nd Edition, David C, Alciatore and Michael B, Distand, McCraw2Dill 5==7

During the second part of the la , you will use an Arduino microcontroller to control the motor, 'he Arduino uses a C2 ased programming language, can read in analog signals using a uilt in analog2to2digital converter, and can output analog signals using :ulse $idth Modulation .:$M/,

& LabView 'asics


Every !a "iew program has two main windows, 'he first is the front panel, 'he front panel is set up so programmers can easily create a user friendly graphical user interface .gui/, Dere you can create various switches, dials, scopes, and tuning parameters that allow users to view or alter different aspects of operation efore and during use, $hen you place a new item on the front panel it also creates a loc1 in the second window called the loc1 diagram, 'he loc1 diagram consists of loc1s connected y wires, Bloc1s have input ports and output ports, By connecting various loc1s in a logical se#uence, you can ma1e a wide variety of programs, Some asic types of loc1s are varia les, constants, math operations, logical operations, data type conversions, case structures, se#uences, and loops, $hen you create a constant or varia le in !a "iew, you generally have to declare it4s data type .Boolean .true6false/, dou le6single floating point precision, integer .and how many its/, unsigned integer, etc,/, Many loc1s re#uire specific data types at their input ports and output specific data types, Eou can generally use data type conversion loc1s to ma1e the output signal of one loc1 compati le with the input signal of another, F Case structures perform a desired operation determined y a (switch) signal, 'he switch can e Boolean, integer, or string, If one of the cases matches the switch, it will perform the code in the loc1 under that case, F Se#uences are used to specify an order of events, $hile !a "iew has its own order of events, sometimes you may want to deviate from the default order y using se#uences, F 'here are 5 main types of loops& 9or loops and $hile loops, A 9or loop operates for a specified num er of iterations efore returning to the governing process, A $hile loop operates until a specific condition has een met, !a "iew must always complete the innermost loops efore the outer loops continues, .e,g, If you want a $hile loop to repeat every 3=ms ut it contains a 9or loop that ta1es 5=ms to process, the $hile loop will e at est half as fast as desired,/ !oops use Shift Gegisters to remem er data from one iteration to the ne-t, A helpful tool to get familiar with most !a view loc1s is the (Conte-t Delp) option .availa le under the (Delp) menu/, which descri es what a loc1 does when you hover the mouse over it,

( Co)*uter Control of t+e Motor


9or this part of this la , you will use a !a "iew program to implement a feed ac1 controller for the motor, 'o provide power to the motor, you will use a low2cost current amplifier, 'his current amplifier is conceptually very similar to the one you used previously, Eou apply a low2power voltage .= to A volts/ to the amplifier, and it provides a high2power current .=27 amps, 352AA "olts depending on the supply voltage/ for the motor that is proportional to the voltage, Eour system should already e wired as follows&

'here are a couple of details a out the current amplifier that are different, however, from the one you used in previous la s, 9irst, the amplifier is a switching type amplifier, 'his means that it creates the desired current y rapidly switching on and off at an appropriate rate, 'he switching rate for switching amplifiers is typically more than 3= BDH, 'he advantage of a switching type amplifier is that it consumes less power ecause the power transistors inside it don4t heat up much when they are fully off .so I I = and :ower I I" I =/, or when they are fully on .so G I = and :II5GI=/, 'he other common type of amplifier that you used previously, a linear amplifier, iases power transistors etween fully (off) and fully (on) .=JGJinifinity/, and thus the transistors heat up, 'he disadvantage of a switching amplifier is that the rapid switching adds electrical noise .and sometimes audi le noise * try to listen to see if you can hear the amplifier switching fre#uency, if you have decent hearing it shouldn4t e too hard to hear/, 0pen the !a "iew program called MAE3=<K<==>,vi, Copy it over to your directory, 'his program implements a :ID .proportional2integral2derivative/ position feed ac1 controller, It reads in the pot signal, calculates the control law, and then sends out the control signal to the motor amplifier, !oo1 at the loc1 diagram and try to figure out how it wor1s,

'he e#uation descri ing a :ID controller is& $here e I error I d I actual motor angular position d I desired motor angular position Bp I position error gain Bd I derivative gain Bi I integral gain I desired motor tor#ue .this is the command you send to the motor amplifier/ Set the sampling rate to 5== DH and run the program .remem er the sampling rate can only e changed while the program is stopped, ut the other values can e changed while the program is running/, If the motor moves all the way to one e-treme, then you pro a ly have implemented positive feed ac1, Eou can correct this y changing the sign of the gains in the program, 1, E-periment with different gains and see how they affect the response of the controller to different waveforms, $hat happens when you decrease and increase the : gainL $hat happens when you decrease and increase the D gainL $hat happens when you decrease or increase the I gainL $hen you first start the program, it will give you an option to save the data from the waveform chart, Eou will need this data for your write2up for at least two different gain settings, PRAC$"CAL E-AM 1, #e)onstrate to t+e $A t+at your )otor is under control. %+ow t+e $A t+at you can c+ange t+e gains/ and t+en 0erbally *redict +ow t+e )otor will be+a0e wit+ t+e new gains. #e)onstrate t+at your *rediction )atc+es t+e actually be+a0ior of t+e )otor.

& K i edt = K pe Kd e

1 Analog2to2#igital Con0ersion
In this part of the la , you will learn how to use !a "iew to read in a voltage waveform, Geplace the wire from the potentiometer in the analog input channel .AI/ on the device %I USB2<==> with the wire from the function generator from the trainer 1it .9GE;/, Ma1e sure the ground from the trainer 1it is still wired to the ground of the USB2<==>, %ow set all of your gains to HeroM this will stop the program from trying to control the motor, Since you are no longer using this program as a controller, we can turn off the desired angle plot on the front panel so we only see the measured angle, Do this y right clic1ing here, and un2chec1ing (:lot "isi le)&

Eou have now essentially turned your program into an oscilloscope, Set the sampling rate to 5== DH and set the 9unction Cenerator to an appro-imately @5", 3= DH sinusoid .use the oscilloscope to chec1 it * the amplitude and fre#uency don4t need to e e-act/, %ow read in the voltage with !a "iew y pressing the Gun arrow in the upper left corner of the 9ront :anel, It will as1 you where you want to save the data, Eou can save it to your USB drive, or +ust hit cancel to not save it, Data is saved in a ,lvm file which is a ta delimited te-t file with columns .sig, 3 time, sig, 3 data, sig, 5 time, sig, 5 data,N/,

( 'he sampling rate is limited ecause it ta1es time to process data in the A6D converter, the USB port, and the !a "iew program, !oo1ing at the loop e-ecution time, what sampling rate did the program actually achieveL Stop the program, increase the sampling rate to 3=== DH, and start it again, Does it still achieve the desired sample rateL 'he sampling rate is an important parameter ecause it determines what the ma-imum fre#uency is that can e read accurately, 9or e-ample, imagine that you are reading data from an accelerometer that is measuring ground movement due to an earth#ua1e, If you read in the data too slowly .say at 3 DH/, you would miss some of the oscillations of the earth#ua1e, Set the sampling rate to 5= DH, $hat is the fastest sine wave that you can read in from the function generator and still get a reasona le representation when you plot the voltageL Use $i1ipedia to loo1 up the term %y#uist rate, If you put in a sinusoid at A= DH, what sampling fre#uency should you use to accurately capture the signal without aliasing .answer& the %y#uist rate for the signal, which is 5OA=DH I 3== DH, Eou must sample at 3== DH/, Aliasing refers to a higher fre#uency signal passing itself off as a lower fre#uency signal, after the original sample is sampled at too low a rate .at a rate elow the %y#uist rate/, 'ry to generate an e-ample of aliasing, PRAC$"CAL E-AM &, #e)onstrate to t+e $A t+at you can deter)ine t+e 3y4uist rate for a sinusoidal in*ut t+at t+e $A sets. #e)onstrate aliasing to t+e $A.

5 Arduino Control 6!sed in 7inal Pro8ect9


9or this part of this la , you will use an Arduino to control the motor, Eou will use the same motor, amplifier, and potentiometer you used efore, however you will wire them up to the Arduino oard instead of the %ational Instruments DA;, Eour system should already e wired as follows&

'he wiper from the potentiometer should e wired to pin A= on the Arduino, and the : and D terminals should e wired to digital pins > and P, respectively,

If the Arduino development environment is not currently installed on your computer, follow the instructions here& http&66arduino,cc6en6Cuide6$indows up to ste* #5 to set it up, 0pen the Arduino s1etch called MAE3=<KArduino,ino, 'his program again implements a :ID .proportional2integral2derivative/ position feed ac1 controller, It reads in the pot signal, calculates the control law, and then sends out the control signal to the motor amplifier, !oo1 at the loc1 diagram and read through the code and try to figure out how it wor1s, 9or de ugging purposes, it is often helpful to output strings to the serial port of a computer while the Arduino is running, 0pen the Serial Monitor from the Arduino environment .tools2Qserial monitor/, $hen the code is running, you should see a read out of the current position of the motor .as read y the potentiometer/, E-amine the code to see if you could change the current value that is eing displayed, P1, Copy the values displayed in the Serial Monitor for at least 3= seconds of operation, :aste them into E-cel and plot the values over time, Eou should see the motor moving etween two fi-ed points at a fre#uency of R3DH, PRAC$"CAL E-AM (, #e)onstrate to t+e $A t+at you +a0e control of your )otor using t+e Arduino board. :ou will also be as;ed to describe w+at any gi0en line of t+e code is doing. Eou may use this code as a starting point for your final pro+ect code, 'his code simply moves the motor ac1 and forth etween two points, however in your code you will want to control the motor to turn your ro ot in a different direction, 'ry to thin1 a out how you would modify the code in order to do this, <R"$E2!P 3, 'urn in a write up that succinctly answers ;3 .ma-imum 5 pages/, Eou write up should contain at least two plots made in Matla of a step response of the motor with different gains, Also include a rief written description of what happens when you change the :, I, and D gains, 5, 'urn in your plot from :3 .re2done in Matla /,

You might also like