⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tracker.m

📁 此程序使用声音来定位物体的位置
💻 M
字号:
function varargout = tracker(varargin)
%TRACKER     Demonstration acoustic tracker system
%See Acoustic Tracker.doc for an explanation of this
%  demo and details on how to set up and run.
%
%Main files to look out for:
% tracker.m                   Starts the tracker GUI.  This is a simple GUI which ties everything together
% configurewhereisit.m        Configures (calibrates) the acoustic tracker.
% whereisit.m                 The acoustic tracker itself.
% whereisitconfiguration.mat  Configuration data file
% makeasound.m                Utility to easily send a signal out of the windows sound card
%
%TRACKER Application M-file for tracker.fig
%    FIG = TRACKER launch tracker GUI.
%    TRACKER('callback_name', ...) invoke the named callback.
%
% See also CONFIGUREWHEREISIT, WHEREISIT, MAKEASOUND
% Last Modified by GUIDE v2.0 25-Sep-2001 15:13:29
% Last Modified by scott v1.0 26-Sep-2001 14:32:19 + a little bit

%The authors of this demo are :
% Loren Dean - The orignal whereisit.m acoustic tracker demo
% Scott Hirsch - Various "enhancements", prettifications, etc...
%

%Typical GUIDE stuff ...
if nargin == 0  % LAUNCH GUI
    
    %Check which toolboxes the user has
    has.vr = ~isempty(ver('vr'));
    has.cfit = ~isempty(ver('curvefit'));
    has.signal = ~isempty(ver('signal'));
    has.daq = ~isempty(ver('daq'));

    if ~has.daq
        errordlg('Sorry, but this demo can not be run without the Data Acquisition Toolbox');
        return
    end;
    
    if (~has.cfit | ~has.signal | ~has.vr)
        warndlg({'To enjoy this demo in it''s full splendor, you should get ', ...
                'the Virtual Reality, Curve Fit, and Signal Processing Toolboxes.'});
    end;
    
    
    fig = openfig(mfilename,'reuse');
    
    % Generate a structure of handles to pass to callbacks, and store it. 
    handles = guihandles(fig);

    handles.has = has;          %Store which toolboxes we have
    guidata(fig, handles);
    
    
    %Disable VR if no VR toolbox
    if ~has.vr
        set(handles.VR_Checkbox,'enable','off', ...
            'ToolTipString','Please get the VR Toolbox!');
    end;
    
    
    %If configuration file is missing, out of date,or at the wrong frequency,
    % gray out Run button.
    %Out of date is defined as recorded before today
    config_file = which('whereisitconfiguration.mat');
    canrun = 0;
    
    if ~isempty(config_file)    %File exists.  Check date
        d = dir(config_file);
        file_saved = floor(datenum(d.date));
        if file_saved == today
            canrun=1;
        end;
    end;
    
    if canrun,
        set(handles.RunButton,'Enable','on', ...
            'ToolTipString','');
    end;
    
    if nargout > 0
        varargout{1} = fig;
    end
    
elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK
    
    try
        if (nargout)
            [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
        else
            feval(varargin{:}); % FEVAL switchyard
        end
    catch
        disp(lasterr);
    end
    
end

%Callbacks
%  String         Tag            Description
%Source Frame
%  Single Tone    ToneButton       Select Single Tone source
%  Wav File       FileButton       Select wave file source
%  <500>          FrequencyEdit    Specify Single tone frequency. NO CALLBACK
%  Browse         BrowseButton     Pick .wav file
%  <comanche.wav> FileEdit         Specify .wav file.  NO CALLBACK
%  Shhh           ShhhButton       Mute sound
%
%Bottom of figure
%  Configure      ConfigureButton  Launch configurewhereisit
%  Run            RunButton        Launch whereisit
%  VR             VR_Checkbox      Include Virtual Reality visualization. NO CALLBACK
%  Fcn Generator  FcnButton        Open daqfcngen

% --------------------------------------------------------------------
function varargout = ToneButton_Callback(h, eventdata, handles, varargin)
%  Single Tone    ToneButton       Select Single Tone source

%Mutually exclusive with FileButton.
%Additional dependencies: 
%  FrequencyEdit, FrequencyText are visisble
%  FileEdit, BrowseButton are not visisble
val = get(h,'Value');
if val
    set(handles.FileButton,'Value',0);
    set([handles.FrequencyText handles.FrequencyEdit], ...
        'Enable','on', ...
        'Visible','on');
    set([handles.FileEdit handles.BrowseButton], ...
        'Enable','off', ...
        'Visible','off');
end;


% --------------------------------------------------------------------
function varargout = FileButton_Callback(h, eventdata, handles, varargin)

%Mutually exclusive with ToneButton.
%Additional dependencies: 
%  FrequencyEdit, FrequencyText are not visisble
%  FileEdit, BrowseButton are visisble

val = get(h,'Value');
if val
    set(handles.ToneButton,'Value',0);
    set([handles.FrequencyText handles.FrequencyEdit], ...
        'Enable','off', ...
        'Visible','off');
    set([handles.FileEdit handles.BrowseButton], ...
        'Enable','on', ...
        'Visible','on');
end;

% --------------------------------------------------------------------
function varargout = BrowseButton_Callback(h, eventdata, handles, varargin)
%Select .wav file

[filename pathname]=uigetfile('*.wav','Pick a .wav file');
fullname = [pathname filename];

if exist(fullname,'file')
    set(handles.FileEdit,'String',fullname);
else
    warndlg([fullname ' not found']);
end;

% --------------------------------------------------------------------
function varargout = ShhhButton_Callback(h, eventdata, handles, varargin)
%Mute/Restart sound

val = get(h,'Value');                         %1-Mute, 0-Resume
tone = get(handles.ToneButton,'Value');       %1-Tone, 0-File

if val
    makeasound stop
    set(h,'String','Resume');
else
    if tone
        fo = str2num(get(handles.FrequencyEdit,'String'));
        if isempty(fo) | fo<100 | fo>5000
            fo=500;
            set(handles.FrequencyEdit,'String',num2str(fo));
        end;
    else
        fo = get(handles.FileEdit,'string');
        if ~exist(fo,'file')
            errordlg([fo ' not found']);
        end;
    end;
    
    makeasound(fo);     %help makeasound to understand the input
    set(h,'String','Shhh');
end;


% --------------------------------------------------------------------
function varargout = ConfigureButton_Callback(h, eventdata, handles, varargin)
%Run configurewhereisit

tone = get(handles.ToneButton,'Value');       %1-Tone, 0-File

%Define fo
%If single tone mode, fo is the tone frequency
%If file, fo is the filename.  configurewhereisit will know what to do with it.
if tone
    fo = str2num(get(handles.FrequencyEdit,'String'));
    if isempty(fo) | fo<100 | fo>5000
        fo=500;
        set(handles.FrequencyEdit,'String',num2str(fo));
    end;
else
    fo = get(handles.FileEdit,'string');
    if ~exist(fo,'file')
        errordlg([fo ' not found']);
    end;
end;

configurewhereisit(fo)

%Assume that we have calibrated succesfully, so we enable the Run button.
set(handles.RunButton,'Enable','on', ...
    'ToolTipString','');


% --------------------------------------------------------------------
function varargout = RunButton_Callback(h, eventdata, handles, varargin)
%Run whereisit.m

set(handles.ShhhButton,'Enable','on');

vr = get(handles.VR_Checkbox,'Value');
if vr
    whereisit('vr')
else
    whereisit
end;

% --------------------------------------------------------------------
function varargout = FcnButton_Callback(h, eventdata, handles, varargin)
daqfcngen   %'Nuff said

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -