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

📄 dawu.m

📁 小车位移的模拟仿真实现,分为带PID和不带PID的仿真,并用GUI予以直观表达,平台matlab6.5,欢迎大家下载交流
💻 M
📖 第 1 页 / 共 2 页
字号:
% 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 edit2 as text%        str2double(get(hObject,'String')) returns contents of edit2 as a double% --- Executes during object creation, after setting all properties.function edit3_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit3 (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    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit3_Callback(hObject, eventdata, handles)% hObject    handle to edit3 (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 edit3 as text%        str2double(get(hObject,'String')) returns contents of edit3 as a double% --- Executes during object creation, after setting all properties.function edit4_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit4 (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    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit4_Callback(hObject, eventdata, handles)% hObject    handle to edit4 (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 edit4 as text%        str2double(get(hObject,'String')) returns contents of edit4 as a double% --- Executes during object creation, after setting all properties.function edit5_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit5 (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    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit5_Callback(hObject, eventdata, handles)% hObject    handle to edit5 (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 edit5 as text%        str2double(get(hObject,'String')) returns contents of edit5 as a double% --- Executes during object creation, after setting all properties.function edit6_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit6 (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    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit6_Callback(hObject, eventdata, handles)% hObject    handle to edit6 (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 edit6 as text%        str2double(get(hObject,'String')) returns contents of edit6 as a double% --------------------------------------------------------------------function select_Callback(hObject, eventdata, handles)% hObject    handle to select (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function pidoff_Callback(hObject, eventdata, handles)% hObject    handle to pidoff (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)pinoff_Callback(hObject, eventdata, handles);
% --------------------------------------------------------------------function exit_Callback(hObject, eventdata, handles)% hObject    handle to exit (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)close;% --------------------------------------------------------------------function gridc_Callback(hObject, eventdata, handles)% hObject    handle to gridc (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function x_grid_Callback(hObject, eventdata, handles)% hObject    handle to x_grid (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)
xg=get(handles.xgrid,'value');
if xg==1
    set(handles.xgrid,'value',0);
else
    set(handles.xgrid,'value',1);
endxgrid_Callback(hObject, eventdata, handles);% --------------------------------------------------------------------function y_grid_Callback(hObject, eventdata, handles)% hObject    handle to y_grid (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)
yg=get(handles.ygrid,'value');
if yg==1
    set(handles.ygrid,'value',0);
else
    set(handles.ygrid,'value',1);
endygrid_Callback(hObject, eventdata, handles)% --------------------------------------------------------------------function instructions_Callback(hObject, eventdata, handles)% hObject    handle to instructions (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)hf=figure('Menubar','none','Name','系统介绍','NumberTitle','off',...
    'Position',[100,200,400,200]);
uicontrol(hf,'Style','Text','Position',[5,180,400,20],...
    'String',' 小车模拟位移模拟系统');
uicontrol(hf,'Style','Text','Position',[5,160,400,20],'Horizontal','left',...
    'String','        初始状态下,质量为m的小车静止在地面上,弹簧处于松弛状态。');
uicontrol(hf,'Style','Text','Position',[5,140,400,20],'Horizontal','left',...
    'String','        现给小车施加一恒定水平向右的力F,此时,小车受到弹簧弹力f1,f2');
uicontrol(hf,'Style','Text','Position',[5,120,400,20],'Horizontal','left',...
    'String','和摩擦力f作用,产生位移  X(t)和加速度a。设水平向右为正方向。');uicontrol(hf,'Style','Text','Position',[5,100,400,20],'Horizontal','left',...
    'String','        现对小车位移X(t)进行仿真,仿真时间120秒。另构造PID控制器仿真');
uicontrol(hf,'Style','Text','Position',[5,80,400,20],'Horizontal','left',...
    'String','模型, Kp、Ki、Kd三个系数可以通过参数设置窗口设定。仿真时间120秒');
uicontrol(hf,'Style','Text','Position',[5,40,400,20],'Horizontal','left',...
    'String','        要求:上升时间:<5 Sec ,   超调量:<10% ,    稳态误差:<2%');

% --- Executes on button press in both.function both_Callback(hObject, eventdata, handles)% hObject    handle to both (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)
[t,x,y]=sim('pidoff',[25]);
plot(t,y);
hold on;
[t,x,y]=sim('pidon');
kp=get(handles.edit1,'string');                             
set_param('pidon/Subsystem/Gain','gain',kp);
ki=get(handles.edit2,'string');                             
set_param('pidon/Subsystem/Gain1','gain',ki);
kd=get(handles.edit3,'string');                             
set_param('pidon/Subsystem/Gain2','gain',kd);

[t,x,y]=sim('pidon');
plot(t,y);
hold off;

xg=get(handles.xgrid,'value');
if xg==1
    set(handles.axes1,'XGrid','on');
else
    set(handles.axes1,'XGrid','off');
end
yg=get(handles.ygrid,'value');
if yg==1
    set(handles.axes1,'YGrid','on');
else
    set(handles.axes1,'YGrid','off');
end

set(handles.edit4,'string','0.000');
set(handles.edit5,'string','0.000');
set(handles.edit6,'string','0.000');

title('当前模式:同时显示');
xlabel('time/sec');
ylabel('X(t)/m');

⌨️ 快捷键说明

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