使用matlab连接irobot与笔记本电脑

时间:2013-11-06 13:50:08

标签: matlab

我是BCA学生的最后一年。我尝试使用matlab将笔记本电脑连接到iRobot Create。但是,机器人没有按照预期的方式做出响应。我使用的代码是:

function [serPort] = RoombaInit(my_COM);

global td
td = 0.015;

Contrl = 132;

warning off

comm = strcat('COM', num2str(my_COM));


a = instrfind('port',comm);
if ~isempty(a)
            disp('That com port is in use.   Closing it.')
            fclose(a);
            pause(1)
            delete(a);
            pause(1)
end

disp('Establishing connection to Roomba...');

serPort = serial(comm,'BaudRate', 57600);
set(serPort,'Terminator','LF')
set(serPort,'InputBufferSize',100)
set(serPort, 'Timeout', 1)
set(serPort, 'ByteOrder','bigEndian');
set(serPort, 'Tag', 'Roomba')

disp('Opening connection to Roomba...');
fopen(serPort);

disp('Setting Roomba to Control Mode...');

Start=[128];
fwrite(serPort,Start);
pause(.1)

fwrite(serPort,Contrl);
pause(.1)

fwrite(serPort,[139 25 0 128]);


fwrite(serPort, [140 1 1 48 20]);
pause(0.05)

fwrite(serPort, [141 1])

disp('I am alive if my two outboard lights came on')

confirmation = (fread(serPort,4))
pause(.1)

请帮帮我...

0 个答案:

没有答案