230 likes | 317 Views
Quiz Preparation. Quiz 4 sheet provided. Fill in your Name, etc. Date is 9/11/12 Answer questions during lecture. Lego Car Project. Wirelessly driven Lego car Left and right channels/motors for steering Goal is to navigate and finish course as quickly as possible
E N D
Quiz Preparation • Quiz 4 sheet provided. • Fill in your Name, etc. • Date is 9/11/12 • Answer questions during lecture.
Lego Car Project • Wirelessly driven Lego car • Left and right channels/motors for steering • Goal is to navigate and finish course as quickly as possible • Penalty of 1 second for each 0.5 V over 10V in voltage regulator output
Lego Car Overview PWM R1, R2 PPM Receiver PWM
Optional Gates (+5 sec. penalty if missed) Push block across finish line or incur a +30 sec. penalty START/FINISH BLOCK Required Gates Each floor tile is 1 foot × 1 foot square
Penalties • Penalties are a way to introduce “cost” into the design and cause the team to make tradeoff decisions. • Incurring a penalty should not be considered unethical or “wrong” in any sense. • 5 second penalty for missing an optional gate • 30 second penalty if the block is not pushed across the finish line • Penalty of 1 second for each 0.5 V over 10V in voltage regulator output (Vo). Voltages rounded to nearest 0.1 V. • Vo ≤10.0V = no penalty • 10.0V < Vo ≤10.5V = 1 second penalty • 10.5V < Vo ≤11.0V = 2 second penalty • etc.
Competition Grading • Fastest time = 100 points • Fastest time ever (Spring 11) was 7 sec. =“World Record” • 30 seconds = 75 points • Other times linearly interpolated between fastest time and 30 sec. • Maximum time is 60 seconds
Preliminary Design Report • Due week of Lab 10, in lab. • Describe design decisions • Output voltage • Power supply • Wheel size/gears, etc. • Justify your decisions. • Explain any disadvantages, and why you’ll tolerate them. • Include supporting drawings, figures, and tables if needed.
Lego Car Design • Output voltage • Higher output voltage increases speed • Penalties apply above 10V • Power supply (batteries) • One 9V battery (light, but less than 10V) • Two 9V batteries (≥10V, but heavy) • Watch batteries (very light, but drain quickly) • Wheel size and gears • Torque vs. speed tradeoff • Drive strategy • Front wheel vs. rear wheel drive • Course path • Passing through all gates vs. missing gates • Pushing block vs. not pushing block • Body • Light vs. heavy
Today’s Topics • Introduction to MATLAB • MATLAB graphics • Image processing
MATLAB • MATLAB® allows us to work with large amounts of data easily. • The basic data structure in MATLAB is a vector. • A vector is a convenient way to store a sequence or array of numbers, such as sensor readings. • We can also manipulate sounds and images from within MATLAB.
MATLAB Basics • Assign a value to a variable >> a=3 a = 3 >> a=3; >> a a = 3 >> Semicolon suppresses echo Typing a variable name displays the value Be careful!!
MATLAB Basics Comma delimits columns • Vectors >> v=[1,3] v = 1 3 >> v=[1;3] v = 1 3 >> v' ans = 1 3 >> v=1:0.5:3 v = 1.0000 1.5000 2.0000 2.5000 3.0000 Semicolon delimits rows Apostrophe means transpose (turn rows into columns and vice versa) start value : increment : end value
Generating Sine Waves • Sine wave: • is the frequency of the sine wave. • Sample the waveform every T seconds. • Let • We get a sequence • Let n=0,…,N to get sequence corresponding to a duration of NT seconds.
MATLAB start value : end value (assumes increment of 1) >> f0=100; >> T=.0008; >> n=0:62; >> x=sin(2*pi*f0*T*n); >> stem(n,x) stem(n,x) plot(n,x)
MATLAB vs. C • C code to create a sine wave: #include <stdio.h> #include <math.h> main(argc,argv) int argc; char *argv[]; { int i,n; double *sv, f0; n=5000; f0=100; sv = (char *) calloc(n, double); for (i = 0; i < 50000; i++) { sv(i) = sin(2*3.1415927*f0*I/44100); } }
Other MATLAB Abilities • Many built-in functions • Can easily add your own functions • Immediate results without compiling • Can solve systems of equations easily • All kinds of plotting methods • Simulink • Maple Symbolic Math Toolbox
Example – Large Array • M file “multiplies.m” creates a 1000 x 1000 array, and then computes inverse. • Performs order of one billion FLOPS in a few seconds.
Example – 3D Plots • M-file “surfaces.m” creates a 3D “landscape” using the function z=cos(.05*x).*sin(.1*y) • This can be rotated in 3D with the mouse.
Example – Image Processing • Start with photo “office.jpg” • Convert to grayscale image • Detect edges
Image processing commands • i=imread('office.jpg'); % convert to MATLAB format • igray=i(:,:,1); % keep only one color channel • bw=edge(igray,'canny'); % perform Canny edge detection
Playing Sounds in MATLAB • Can play sounds directly from MATLAB: • sound(x,44100) • x is the sequence of values in a vector • 44100 is the output sampling rate • soundsc(x,44100) • Same as sound() but auto-levels before playing • Each sound played at the same level
Playing Sounds in MATLAB • Can read or write WAV files: • y = wavread(‘fast.wav’); • y is the sound sequence read in as a vector • fast.wav is the name of the file to be read. • wavwrite(y,44100,’fast.wav’)
Stereo in MATLAB • If x is an Nx2 vector, the left column will be played as the left channel, and the right column will be played as the right channel. • fl=200; • fr=300; • t=[0:1/44100:8]; • xl = sin(2*pi*fl*t); • xr = sin(2*pi*fr*t); • sound([xl’ xr’],44100)