Using MATLAB to control the iRobot Create 2 over Wi-Fi


Developed by Professor Will Schleter at the University of Tennessee
For more information contact wschlete@utk.edu or abiegals@utk.edu
Based on the Create1 MATLAB toolbox developed by Professor Joel Esposito at the United States Naval Academy.

MATLAB code to obtain MATLAB Roomba Toolbox from University of Tenneessee Engineering Fundamentals Server

% Installation program for EF 230 Roomba Project
% Last update: September 13, 2017 (Fixed security issues associated with https server and removed file delete warning if errors occured)
function roombaInstall
clc;
% list of files to install
files = {'roomba.m','roombaSim.m','roombaSimGUI.m','roombaSimGUI.fig'};
% location to install from
options = weboptions('CertificateFilename',''); % tell it to ignore certificate requirements
server = 'https://ef.engr.utk.edu/ef230/projects/roomba-f2016/install/';
dlgTitle = 'Roomba Install/Update';
% display purpose and get confirmation
prompt = {
    'This program will download these EF 230 Roomba files:'
    ''
    strjoin(files,' ')
    ''
    'to this folder:'
    ''
    cd
    ''
    'Do you want to continue? '
    };
beep;
yn = questdlg(prompt, ...
    dlgTitle, ...
    'Yes','No','Yes');

if ~strcmp(yn,'Yes'), return; end

% get list of files that exist
existing_files = files( cellfun(@exist,files) > 0 );
if ~isempty(existing_files)
    % make sure it is really ok to replace them
    prompt = {'You are replacing these file(s): '
            ''
            strjoin(existing_files,' ')
            ''
            'OK to replace?'
            };
    beep;
    yn = questdlg(prompt, ...
        dlgTitle, ...
        'Yes','No','Yes');
    if ~strcmp(yn,'Yes'), return; end
end

% download the files
cnt = 0;
for i=1:length(files)
    f=files{i};
    disp(['Downloading ' f]);
    try
        url = [server f];
        websave(f,url,options);  % added options to avoid security errors
        cnt = cnt + 1;
    catch
        disp(['Error downloading ' f]);
        dummy = [f '.html'];
        if exist(dummy,'file')==2
            delete(dummy)
        end
    end
end

if cnt == length(files)
    msg = 'Installation Successful';
    waitfor(msgbox(msg,dlgTitle));
else
    msg = 'Installation Error - see command window for details';
    waitfor(errordlg(msg,dlgTitle));
end

end %roombaInstall

Networking

Configure robots to connect to a local wifi router with NAT addresses. Setup wifi router to assign consistent IP addresses and port forwarding.

files in /home/pi

  • start-command-daemon
  • command-daemon
  • roomba-server- network to serial port hardcoded in. Must be /dev/ttyAMA0 for custom cable, /dev/ttyUSB0 for standard cable

Modify /etc/rc.local - add these lines near bottom before return

# Commands to start the MATLAB/Create 2 interface programs
/home/pi/start-command-daemon
/home/pi/start-roomba-server

Pi/Create Connection

Uses standard Create com cable, Pi power connected to Create battery via UBEC.