1. Trang chủ
  2. » Giáo án - Bài giảng

Bai 1 thuc hanh thiet ke mo phong he thong DKTD

33 435 3

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 33
Dung lượng 1,25 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

'THUC SU MUON THOAT?','Yes','No','No'; function edit6_CallbackhObject, eventdata, handles % hObject handle to edit6 see GCBO % eventdata reserved - to be defined in a future version of M

Trang 1

Bài 1 XÂY DỰNG MÔ HÌNH HÓA MÔ PHỎNG HÊ THỐNG ĐIỀU KHIỂN TỰ ĐỘNG TRÊN CÔNG CỤ

GUIDE CỦA PHẦN MỀM MATLAB

I Mục đích

- Giúp sinh viên hiểu phương pháp xây dựng mô hình hóa mô phỏng một hệ thống điều khiển tự động

- Thu thập và phân tích các bảng dữ liệu của hệ thống

- Đánh giá được kết quả mô phỏng, so sánh độ tương đồng giữa kết quả mô phỏng của mô hình với các tính chất của đối tượng thực

- Đưa ra kết luận và các phương án điều chỉnh cho đối tượng thực dựa trên kết quả mô phỏng sau khi phân tích chúng

II Yêu cầu thực hành

- Máy vi tính cài đặt sẵn phần mềm Matlab với đầy đủ các ứng dụng của Math Work cung cấp

- Yêu cầu sinh viên được trang bị phần lý thuyết môn Tin học chuyên ngành, hết chương 3 môn Mô hình hóa

- Tuân thủ mọi nội quy, quy định khi thực hành tại phòng thí nghiệm

III Nội dung thực hành

3.1 Bài toán yêu cầu

Cho hệ điều khiển tự động có sơ đồ cấu trúc và các tham số như sau:

Với U(t) = 1(t); K1 = 100; K2 = 0.5; T1 = 0.01; T2 = 0.02; Chu kỳ lấy mẫu T = 0.001

y(t)

Trang 2

Hãy tìm phương trình sai phân và mô hình hóa hệ trên máy tính với các yêu cầu:

Bước 1 Tìm phương trình sai phân của hệ

- Từ sơ đồ cấu trúc ta có hàm truyền hệ kín như sau:

Thay vào phương trình ta sẽ có hàm truyền gián đoạn của hệ như sau:

Trang 3

Hay:

Sử dụng tính chất dịch gốc của biến đổi Z ta tìm được phương trình sai phân như sau:

Vì tín hiệu đầu vào là hàm u(t) = 1(t) do đó ta có U[k+3]=U[k+2]=U[k+1]=U[k]=1

Ta có phương trình sai phân như sau:

Trang 4

Bước 2 Xây dựng giao diện mô phỏng hệ thống điều khiển tự động

(1) Khởi tạo guide trong phần mềm Matlab

Trang 5

(2) Thiết lập bảng điều khiển trên giao diện

- Chọn công cụ Panel

Trang 6

- Thay đổi tên cho Panel bằng cách kích đúp vào Panel và thay tên trong phần Title của nó từ tên

- Panel sang tên “Bang dieu khien”

-

Trang 7

- Chọn công cụ Push Button để khai báo nút khảo sát hệ thống

Trang 8

Đổi tên PushButton trong String ở Inspector của nút sang tên mới là khảo sát hệ thống

Trang 9

+ Kết quả thu được

Trang 10

+ Tương tự như vậy ta lấy nút có tên gọi là “Thoát khỏi hệ thống”

Trang 11

- Chọn công cụ Panel để khai báo bảng nhập giá trị

Trang 12

- Chọn công cụ Static Text để định nghĩa các ô nhập giá trị từ bàn phím

Trang 13

+ Kích đúp vào Static Text để thay đổi tên Static Text trong String sang tên “Nhap gia tri K1 =”

Trang 14

+Tương tự như vậy ta khai báo nhập giá trị cho K2, T1, T2, T

Trang 15

- Chọn công cụ Edit Text để khai báo ô nhập và xuất giá trị trên màn hình

Trang 16

+ Kích đúp vào Edit1 để khai báo giá trị mặc định trong phần String từ chuỗi ký tự “ Edit Text” sang số 100

Trang 17

+ Làm tương tự chọn Edit2, Edit3, Edit4, Edit5 cho các biến K2, T1, T2, T, với mặc định K2 = 0.5; T1 = 0.01; T2 = 0.02

và T = 0.001

Trang 18

+ Tương tự ta lập bảng xuất giá trị tính toán ra:

> Giá trị cực đại xuất ra Edit6

> Thời gian ổn định xuất ra Edit7

> Độ quá điều chỉnh xuất ra Edit8

Trang 20

Bước 3 Viết Code cho các nút điều khiển

(1) Nút thoát khỏi hệ thống

Nhấn chuột phải vào Nút “ Thoat khoi he thong” chọn View callBacks/Callback

Trang 21

+ Ta lập trình như sau:

hoi=questdlg('Ban muon thoat khoi chuong trinh?',

'THUC SU MUON THOAT?','Yes','No','No');

Trang 23

(2) Nút “Khao sat he thong”

Nhấn chuột phải vào Nút “Khao sat he thong” chọn View callBacks/Callback

Trang 24

+ Ta lập trình:

function varargout = Bai1(varargin)

% BAI1 MATLAB code for Bai1.fig

% BAI1, by itself, creates a new BAI1 or raises the existing

% singleton*

%

% H = BAI1 returns the handle to a new BAI1 or the handle to

% the existing singleton*

%

% BAI1('CALLBACK',hObject,eventData,handles, ) calls the local

% function named CALLBACK in BAI1.M with the given input arguments

%

% BAI1('Property','Value', ) creates a new BAI1 or raises the

% existing singleton* Starting from the left, property value pairs are

% applied to the GUI before Bai1_OpeningFcn gets called An

% unrecognized property name or invalid value makes property application

% stop All inputs are passed to Bai1_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 Bai1

% Last Modified by GUIDE v2.5 05-Mar-2013 21:24:22

% Begin initialization code - DO NOT EDIT

Trang 25

% - Executes just before Bai1 is made visible.

function Bai1_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 Bai1 (see VARARGIN)

% Choose default command line output for Bai1

% - Outputs from this function are returned to the command line

function varargout = Bai1_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 pushbutton1

function pushbutton1_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Ch??ng trình ví du 3.1 v? v? ?? th? c?a h? th?ng ?i?u khi?n t? ??ng

disp('MO PHONG HE THONG DIEU KHIEN TU DONG - THM')

clc;

% Khai bao bien

syms a b c d max k1 k2 t1 t2 tm tod xichma gd gm km ky

y = ones(1,1000);%Khai bao y la mot ma tran 1 hang 1000 cot

k1 = get(handles.edit1,'String');% Nh?n chu?i ký t? ? edit1 gán cho k1

k1 = str2num(k1); %Chuy?n ??i t? chu?i ký t? sang d?ng s?

k2 = get(handles.edit2,'String');% Nh?n chu?i ký t? ? edit2 gán cho k2

Trang 26

k2 = str2num(k2); %Chuy?n ??i t? chu?i ký t? sang d?ng s?

t1 = get(handles.edit3,'String');% Nh?n chu?i ký t? ? edit3 gán cho t1

t1 = str2num(t1); %Chuy?n ??i t? chu?i ký t? sang d?ng s?

t2 = get(handles.edit4,'String');% Nh?n chu?i ký t? ? edit4 gán cho t2

t2 = str2num(t2); %Chuy?n ??i t? chu?i ký t? sang d?ng s?

t = get(handles.edit5,'String');% Nh?n chu?i ký t? ? edit1 gán cho t

t = str2num(t); %Chuy?n ??i t? chu?i ký t? sang d?ng s?

y(1,1)=0; % Khai bao phan tu y(1) = 0

y(1,2)=0; % Khai bao phan tu y(2) = 0

y(1,3)=0; % Khai bao phan tu y(3) = 0

% Ch??ng trình ví du 3.1 v? v? ?? th? c?a h? th?ng ?i?u khi?n t? ??ng

% Tim gia tri lon nhat

set(handles.edit7,'String',tod);

% Ch??ng trình ví du 3.1 v? v? ?? th? c?a h? th?ng ?i?u khi?n t? ??ng

Trang 27

% - Executes on button press in pushbutton2.

function pushbutton2_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton2 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

hoi=questdlg('Ban muon thoat khoi chuong trinh?',

'THUC SU MUON THOAT?','Yes','No','No');

function 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

% - 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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');

end

Trang 28

function edit7_Callback(hObject, eventdata, handles)

% hObject handle to edit7 (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 edit7 as text

% str2double(get(hObject,'String')) returns contents of edit7 as a double

% - Executes during object creation, after setting all properties

function edit7_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit7 (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 edit8_Callback(hObject, eventdata, handles)

% hObject handle to edit8 (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 edit8 as text

% str2double(get(hObject,'String')) returns contents of edit8 as a double

% - Executes during object creation, after setting all properties

function edit8_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit8 (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

Trang 29

function edit1_Callback(hObject, eventdata, handles)

% hObject handle to edit1 (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 edit1 as text

% str2double(get(hObject,'String')) returns contents of edit1 as a double

% - Executes during object creation, after setting all properties

function edit1_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit1 (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 edit2_Callback(hObject, eventdata, handles)

% hObject handle to edit2 (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 edit2 as text

% str2double(get(hObject,'String')) returns contents of edit2 as a double

% - Executes during object creation, after setting all properties

function edit2_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit2 (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

Trang 30

function 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 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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');

end

function 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 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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');

Trang 31

function 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 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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');

end

function edit11_Callback(hObject, eventdata, handles)

% hObject handle to edit11 (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 edit11 as text

% str2double(get(hObject,'String')) returns contents of edit11 as a double

% - Executes during object creation, after setting all properties

function edit11_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit11 (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'))

Ngày đăng: 10/06/2016, 19:08

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w