Tải bản đầy đủ - 0 (trang)
PHỤ LỤC 8: Code phần mềm điều khiển trên máy tính.

PHỤ LỤC 8: Code phần mềm điều khiển trên máy tính.

Tải bản đầy đủ - 0trang

global Point ;

Point = zeros(MaxPoint);

global hang;

global cot;

hang = 1;

cot = 1;

global b ;

b = Bluetooth('HC-05',1);

b.Terminator = ',';

b.BytesAvailableFcnMode = 'terminator';

b.BytesAvailableFcn = {@ReceiveEvent,handles} ;

function varargout = DATN_OutputFcn(hObject, eventdata, handles)

varargout{1} = handles.output;

function Stop_Callback(hObject, eventdata, handles)

global b;

fprintf(b,'Stop');

set(handles.Stop,'Enable','off');

set(handles.Continue,'Visible','on');

set(handles.Stop,'Visible','off');

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

function Start_Callback(hObject, eventdata, handles)

global b;

fprintf(b,'Start');

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

set(handles.Start,'Enable','off');

function Mapmo_Callback(hObject, eventdata, handles)

set(handles.Mapmo,'Enable','off');

global Point;

x = 0:1:5; % gia tri x

y = 0:1:5;

z = Point; % 6 hang 6 cot vi phan giai 1/2 => 5*2 = 10 diem

xi = linspace(0,5,200);

yi = linspace(0,5,200);

[xxi,yyi] = meshgrid(xi,yi);

zzi = interp2(x,y,z,xxi,yyi,'cubic');

mesh(handles.Bieudo,xxi,yyi,zzi)

hold on

[xx,yy] = meshgrid(x,y);

plot3(handles.Bieudo,xx,yy,z,'.')

hold off

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

85



function BCoordinates_Callback(hObject, eventdata, handles)

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

set(handles.BCoordinates,'Enable','off');

function COM_CreateFcn(hObject, eventdata, handles)

if

ispc

&&

isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

function Connect_Callback(hObject, eventdata, handles)

global b;

if (b~=0)

fopen(b);

end

set(handles.Connect,'Enable','off');

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

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

function Disconnect_Callback(hObject, eventdata, handles)

global b;

if(~(strcmp(get(b,{'Status'}),'closed')))

fprintf(b,'Exit');

fclose(b);

end

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

set(handles.Disconnect,'Enable','off');

set(handles.Mapmo,'Enable','off');

set(handles.Start,'Enable','off');

set(handles.Stop,'Enable','off');

function ReceiveEvent(hObject, eventdata, handles)

global DataReceive ;

global b;

global Point chieucao;

global hang cot;

global Data ;

global xpoint ypoint ;

global countEvent;

DataReceive = fscanf(b);

switch DataReceive(1)

case 'P'

countEvent = countEvent+1;

cot = str2double(DataReceive(2)); % x is cot , y is hang

hang = str2double(DataReceive(3));

Data = DataReceive(4:end-1); % get char 2

86



chieucao = str2double(Data);

Point(hang+1,cot+1) = chieucao;

xpoint(countEvent) = cot ;

ypoint(countEvent) = hang ;

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

plot(handles.Toado,xpoint,ypoint);

xlim(handles.Toado,[0 5])

ylim(handles.Toado,[0 5])

case 'C'

fprintf(b,DataReceive(2:end-1));

case 'S'

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

set(handles.Stop,'Enable','off');

otherwise

flushinput(b);

end

function Exit_Callback(hObject, eventdata, handles)

global b;

if(~(strcmp(get(b,{'Status'}),'closed')))

fprintf(b,'Exit');

fclose(b);

end

close ;

function Continue_Callback(hObject, eventdata, handles)

global b;

set(handles.Continue,'Visible','off');

set(handles.Stop,'Visible','on');

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

fprintf(b,'Start');

function Rotate_Callback(hObject, eventdata, handles)

rotate3d(handles.Bieudo,'on');

set(handles.Rotate,'Enable','off');

function About_Callback(hObject, eventdata, handles)

open('About.htm');

function Help_Callback(hObject, eventdata, handles)

open('Help.htm');



87



PHỤ LỤC 9: Tập lệnh AT để giao tiếp Bluetooth.

Cú pháp

AT

AT+RESET

AT+VERSION?

AT+ORGL

AT+ADDR?

AT+NAME=



Giá trị trả về

OK

OK

+VERSION: OK

OK

+ADDR: OK

OK



AT+NAME?



+NAME:OK

(/FAIL)

AT+RNAME? 1. +NAME: OK

2. FAIL

AT+CLASS=

OK

AT+ CLASS?

1. +CLASS: OK

2. FAIL

AT+IAC=

1.OK 2. FAIL

AT+INQM=,

,

AT+ INQM?



1.OK 2. FAIL



AT+PSWD=



+INQM,

, OK

OK



AT+ PSWD?



+ PSWD : OK



AT+UART=,

,

AT+UART?



OK



AT+CMODE=



OK



AT+ CMODE?



+ CMODE: OK



AT+BIND=



OK



+UART=,

, OK



88



Tham số

Param : firmware version

address of Bluetooth module

Param: Bluetooth module

name (Default :HC-05)

Param: Bluetooth module

name (Default :HC-05)

Param1,Param 2 : the address

of Bluetooth device

Param: Device Class

Param: Device Class

Param: GIAC (Default :

9e8b33)





Param: PIN code (Default

1234)

Param: PIN code (Default

1234)

Param1: Baud Param2: Stop

bit Param3: Parity

Param1: Baud

Param 2: Stop bit

Param3: Parity

Param: 0 - connect fixed

address 1 - connect any

address 2 - slave-Loop

Param: 0 - connect fixed

address 1 - connect any

address 2 - slave-Loop

Param: Fixed address

(Default 00:00:00:00:00:00)



PHỤ LỤC 10: Hình ảnh khảo nghiệm đo đạc độ mấp mơ mặt đồng.



Hình PL 1: Sơ đồ layout mạch cảm biến laser



Hình PL 2: Mạch cảm biến tia laser.



89



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

PHỤ LỤC 8: Code phần mềm điều khiển trên máy tính.

Tải bản đầy đủ ngay(0 tr)

×