1

I am a final year BCA student. I tried to connect my laptop with an iRobot Create using matlab. But, the robot is not responding in the expected way.The code I used was:

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)

Please help me with this...

4

0 に答える 0