root/trunk/publishing/MATLABCentral/Example_6_NextGenerationUltrasound.m @ 701

Revision 701, 1.7 KB (checked in by behrens, 4 years ago)
  • update MATLAB Central documents
Line 
1%% Example 5: Next Generation Ultrasound
2% This script demonstrates the results of the ultrasound "snapshot mode"!
3% Interpretation of the results however is difficult.
4%
5% Just connect an NXT to the USB port, adjust the US port (or connect it to
6% SENSOR_2), and see what's happening. The script will exit after 200
7% measurements...
8%
9% Signature
10%   Author: Linus Atorf, Alexander Behrens
11%   Date: 2009/07/17
12%   RWTH - Mindstorms NXT Toolbox: http://www.mindstorms.rwth-aachen.de
13
14%% Clean up
15% Close previous handles (if existing)
16COM_CloseNXT all
17
18%% Set up Matlab
19clear all
20close all
21format compact
22
23
24%% Set up ports
25portUS      = SENSOR_2;
26
27
28%% Get USB handle
29COM_CloseNXT all
30h = COM_OpenNXT();
31COM_SetDefaultNXT(h);
32
33
34%% Lets go then!
35figure('name', 'Next Generation Ultrasound')
36set(gca, 'Color', 'black');
37hold on
38
39
40OpenUltrasonic(portUS, 'snapshot')
41
42n          = 8;         % bytes the US sensor received
43count      = 200;       % how many readings until end?
44plotcols   = 8;         % how many out of n echos to plot?
45outOfRange = 160;       % setting for out of range readings
46
47colors = flipud(hot(8));
48
49data = zeros(1, n);
50allX = (1:count+1)';
51
52
53for i = 1 : count
54    USMakeSnapshot(portUS)
55    pause(0.05);            % wait for the sound to travel
56    echos = USGetSnapshotResults(portUS);
57
58    echos(echos == 255) = outOfRange;
59
60    echos = [echos(1); diff(echos)];
61
62    data = vertcat(data, echos');
63    x = allX(1:i+1);
64   
65    clf
66    hold on
67    set(gca, 'Color', 'black');
68   
69    axis([0 count 0 outOfRange])
70
71    for j = plotcols : -1 : 1
72        area(x, data(:, j) , 'FaceColor', colors(j, :))
73    end
74   
75end%for
76
77
78%% Clean up
79CloseSensor(portUS)
80COM_CloseNXT(h);
Note: See TracBrowser for help on using the browser.