⛄一、打靶仿真系统简介
1 课题描述
2 课题建模过程
a)第一,获取武器的各个参数,并且由这些参数计算武器在方向和高低上的响应公算偏差;
b)第二,射击过程中方向和高低上的偏差呈正态分布。在matlab中取normrnd函数实现改功能(其中,标准差为共算误差);
c)第三,根据计算值,在靶上作出击中点:靶子的10环半径是0.75m,9环半径是1.75m,以此类推,6环半径是4.75m,6环之外均记为0环,输出每次射击的成绩;
d)第四,计算总环数、平均环数和命中率,命中率为6环以上占10枪的比例。
三、课题实现出现的关键难点
a)刚开始做的时候入手难
由于上课听课不认真,说实话,一开始做程序没法入手,完全不知道该如何进展。
在这种情况下,我先买了一本参考书,并对参考书中仅有的一个实例进行了试验。虽然是完全照抄,但过程中也碰到了不少麻烦,书中有几个对象的tag前后不一致,使得程序无法运行。看了一下书,仔细琢磨后,修改了程序,并成功运行。在这过程中,开始对程序有所了解。
看完GUI那一章,基本上开始有头绪了,然后就开始选定课题,动手设计界面,进行功能上的分析。
选课题的时候也纠结了一下,最后选择了一个4星的题目,确实是因为时间安排上的问题,因为周末还要上双学位的课,平常有什么课也不舍得翘。
b)程序上碰到的问题
因为选题还是蛮简单的,程序上做下来一直很顺利,做图形的时候温习了书中图形的部分,写回调函数的时候温习matlab程序上的一些特点,因为学过c语言,感觉除了matlab有一些特殊的用法,像脚本文件、函数文件,还有几个流程控制语句,其他的都很相似。程序上很快就能上手。
其中碰到几个想实现的功能,如隐去坐标轴、弹出对话框等几个功能,都是上网搜的,经过试验,最后写到了程序当中。
c)声音的添加
这个算是我碰到的比较大的麻烦,加它的时候还以为自己很有创意呢,后来我发现也有同学加了那个功能,但是我在这个过程中确实遇到了很大麻烦。
先有这个想法的时候在网上搜能不能添加背景音乐,发现可以wavread函数,然后在网上找了一段ak47的枪声,没想到这段枪声折腾了我好久。
当然,我知道只能添加.wav格式的音频文件,下载的这段枪声也是.wav格式的,但是怎么也添加不进去。进行调试的时候,进入到wavread函数中,发现了报错跳出来的地方,但是也看不懂。把那一段复制粘贴之后,发现了百度上的一个问题正是关于它的。里面提到有些.wav格式不是标准的格式,可能不能输入到matlab中。我搜索了.wav的内容,确认了这个想法,并下载了转换格式的软件,将这段音频转了n多遍却还是不行。
最后,也是巧合,我在看网页的时候发现windows自带的录音机能够产生标准.wav格式,这就成了我最后的希望。如果这个再不行,我觉得放弃掉加载声音了。当然,最后是成功了。
⛄二、部分源代码
function varargout = target(varargin)
% TARGET M-file for target.fig
% TARGET, by itself, creates a new TARGET or raises the existing
% singleton*.
%
% H = TARGET returns the handle to a new TARGET or the handle to
% the existing singleton*.
%
% TARGET(‘CALLBACK’,hObject,eventData,handles,…) calls the local
% function named CALLBACK in TARGET.M with the given input arguments.
%
% TARGET(‘Property’,‘Value’,…) creates a new TARGET or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before target_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to target_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE’s Tools menu. Choose “GUI allows only one
% instance to run (singleton)”.
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help target
% Last Modified by GUIDE v2.5 08-Jue-2021 23:48:24
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct(‘gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @target_OpeningFcn, …
‘gui_OutputFcn’, @target_OutputFcn, …
‘gui_LayoutFcn’, [] , …
‘gui_Callback’, []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% — Executes just before target is made visible.
function target_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to target (see VARARGIN)
%画靶子
draw;
% Choose default command line output for target
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes target wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% — Outputs from this function are returned to the command line.
function varargout = target_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% — Executes on button press in close.
function close_Callback(hObject, eventdata, handles)
% hObject handle to close (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close;
function uh_input_Callback(hObject, eventdata, handles)
% hObject handle to uh_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,‘String’) returns contents of uh_input as text
% str2double(get(hObject,‘String’)) returns contents of uh_input as a double
% — Executes during object creation, after setting all properties.
function uh_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to uh_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end
function vh_input_Callback(hObject, eventdata, handles)
% hObject handle to vh_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,‘String’) returns contents of vh_input as text
% str2double(get(hObject,‘String’)) returns contents of vh_input as a double
% — Executes during object creation, after setting all properties.
function vh_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to vh_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end
function vr_input_Callback(hObject, eventdata, handles)
% hObject handle to vr_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,‘String’) returns contents of vr_input as text
% str2double(get(hObject,‘String’)) returns contents of vr_input as a double
% — Executes during object creation, after setting all properties.
function vr_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to vr_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end
function ur_input_Callback(hObject, eventdata, handles)
% hObject handle to ur_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,‘String’) returns contents of ur_input as text
% str2double(get(hObject,‘String’)) returns contents of ur_input as a double
% — Executes during object creation, after setting all properties.
function ur_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to ur_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end
function ah_input_Callback(hObject, eventdata, handles)
% hObject handle to ah_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,‘String’) returns contents of ah_input as text
% str2double(get(hObject,‘String’)) returns contents of ah_input as a double
% — Executes during object creation, after setting all properties.
function ah_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to ah_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end
function ar_input_Callback(hObject, eventdata, handles)
% hObject handle to ar_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,‘String’) returns contents of ar_input as text
% str2double(get(hObject,‘String’)) returns contents of ar_input as a double
% — Executes during object creation, after setting all properties.
function ar_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to ar_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end
function bh_input_Callback(hObject, eventdata, handles)
% hObject handle to bh_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,‘String’) returns contents of bh_input as text
% str2double(get(hObject,‘String’)) returns contents of bh_input as a double
% — Executes during object creation, after setting all properties.
function bh_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to bh_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end
⛄三、运行结果
⛄四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1]魏丽芬,陈文印.军事打靶虚拟仿真系统开发研究[J].福建电脑. 2022,38(11)
3 备注
简介此部分摘自互联网,仅供参考,若侵权,联系删除