Roomba Parking Pal

This project uses an iRobot Create programmable roomba, MATLAB r2018a, and MATLAB mobile. In using these three mediums and our knowledge of coding, we programmed the iRobot Create to interpret colors and use on-board sensors to complete tasks. This projects depends on the Raspberry Pi and MATLAB communication to perform these tasks.

Step 1: Materials

1. iRobot Create Robot

2. MATLAB r2018a

3. Raspberry Pi

4. Camera Module

5. 3-D printed Camera Stabilizer Stand

6. Smartphone with MATLAB mobile installed

7. Laptop/Computer with MATLAB installed

Step 2: Connection

This step is about connecting the Raspberry Pi to the robot, secondly connecting the robot to your computer, and connecting the smartphone to the computer.

The easiest part of this process is connecting the Raspberry Pi to your robot, since the Raspberry Pi is mounted to the top of the robot. There is a cord from the robot that all you have to do is plug into the side of the Raspberry Pi.

The next step is connecting the robot to your computer so that you can run commands for the robot to perform. The first thing that you must do is connect your computer to the wireless network that your roomba is creating. Now, it is recommended that you use the Set Path icon in MATLAB to set the path so that you can use the functions in the Roomba toolbox from MATLAB. Every time you are beginning and ending use with the robot, you must do a "Two-Finger Salute" hard resetting the robot, which means that you hold down the dock and spot buttons for ten seconds until the light dims indicating to release. You were successful with this hard reset if you hear the robot play a short scale. Next you must connect to the roomba using a line of code like this "r=roomba(x)" where 'x' is the number designated to the robot that you have.

Lastly, you need to download MATLAB mobile on whatever mobile device that you will be using for this project, and this application is available on both Android and Apple devices. Once the application is installed, you will have to login using you credentials. Then you must connect this device to your computer, using the tab labeled "More" -> then click "settings' -> then click "Add a computer" this should bring up the screen shown in the pictures above. After you see this the next step that you must go through is just plugging and chugging the information that it requests. Once you are successfully connected, you will be able to call functions that you define on your computer on your phone to control your robot.

Step 3: Logically Creating a MATLAB Code to Use Sensors

The code will be easiest to create when a majority of it is within on while loop, so that the roomba can constantly update valid values it is looking at. If there is an error, MATLAB will display an error and where it appears in the code, making troubleshooting relatively simple.

Designed in r2018a MATLAB, this code makes use of the standard toolboxes, the iRobot Create toolbox, as well as the MATLAB mobile toolbox. The roomba used in this example is designated as 26, and the r=roomba(26) need only be run once to fully communicate with the roomba.

Code:

function parkassist(x)
if x==1

r=roomba(26) % connects to roomba

while true

r.setDriveVelocity(.05,.05) % sets roomba to a slower driving speed

bump=r.getBumpers % gets the data from the bump sensors

cliff=r.getCliffSensors % gets the data from the cliff sensors

light=r.getLightBumpers % gets the data from the light bump sensors

img=r.getImage;% reads the camera off of the robot

red_mean = mean(mean(img(:,:,1))) % reads the mean amount of red pixels

green_mean = mean(mean(img(:,:,2))) % reads the mean amount of green pixels

blue_mean = mean(mean(img(:,:,3))) % reads the mean amount of blue pixels

if bump.front == 1 %reads front bump sensors

r.stop %stops roomba

msgbox('Path Obscured!','Parking Assistant Message') %displays message saying the path is obscured break % ends the loop

elseif green_mean >150

r.stop %stops roomba

cont = questdlg('Continue?', 'Path Completed') %displays question box asking to continue

if cont == 'Yes'

parkassist(1) %restarts the code

else

end

break % ends the loop

elseif red_mean > 140

r.turnAngle(45) %turns the roomba 45 degrees

r.timeStart %starts a time counter

while true

r.setDriveVelocity(.05,.05) %sets speed of the roomba

time=r.timeGet %assigns the time to a variable

bump=r.getBumpers % gets the data from the bump sensors

cliff=r.getCliffSensors % gets the data from the cliff sensors

light=r.getLightBumpers % gets the data from the light bump sensors

img=r.getImage;% reads the camera off of the robot

red_mean = mean(mean(img(:,:,1))) % reads the mean amount of red pixels

green_mean = mean(mean(img(:,:,2))) % reads the mean amount of green pixels

blue_mean = mean(mean(img(:,:,3))) % reads the mean amount of blue pixels

if blue_mean > 120

r.moveDistance(-0.01) %moves the roomba backwards a set distance songPlay(r,'T400,C,D,E,F,G,A,B,C^','true') % plays a rising musical scale

msgbox('Water Found!', 'Parking Assistant Message') % displays a message saying water has been found r.turnAngle(-80) %rotates roomba 80 degrees

break % ends current loop

elseif light.rightFront > 25 || light.leftFront > 25 %reads light bump sensors

r.moveDistance(-0.01) % moves the roomba backwards a set distance

r.turnAngle(-35) % rotates the roomba 35 degrees

break %ends current loop

elseif cliff.rightFront < 2500 && cliff.leftFront < 2500 %reads both cliff sensors

r.moveDistance(-0.1) % moves roomba backwards a set distance

r.turnAngle(-80) %rotates roomba 80 degrees

break % ends current loop

elseif time >= 3

r.stop %stops roomba

contin=questdlg('Station Free, Continue?', 'Parking Assistant Message') %asks if the roomba should continue if contin == 'Yes'

r.turnAngle(-90) % rotates the roomba 90 degrees

parkassist(1) %restarts the function

else

r.stop % stops the roomba

end

else

end

end

elseif cliff.rightFront < 2500 && cliff.leftFront < 2500 %reads both cliff sensors

r.moveDistance(-0.1) %moves roomba backwards a set distance

r.turnAngle(-90) %rotates roomba 90 degrees

elseif cliff.rightFront < 2500 %reads the right cliff sensor

r.turnAngle(-5) %slightly turns the roomba in the opposite direction of the cliff sensor

elseif cliff.leftFront < 2500 %reads the left cliff sensor

r.turnAngle(5) %slightly turns the roomba in the opposite direction of the cliff sensor

else

end

end

end

Step 4: Testing the Code and Robot

After the code was developed, the next step was to test the code and the robot. Since there is a lot of different adjustments that can be made in the code, such as the angle the robot turns, the speed it moves, and the thresholds for each color, the best way to figure these values out for your robot is to test them and change as you go. For each workday we had, we were constantly changing these values since some of them rely on the environment that your robot is operating in. The best way that we found was to place the roomba on the path you want it to follow, and to have a barrier high enough so that the camera can not detect colors that you do not want it to. The next step is let it run and show it the colors you want, when you want it to complete that task. As you go, if you see an issue the best thing to do is to push the front bumper in, making it stop, then change the parameter that you had trouble with.

Step 5: Recognition of Error

With every project done completed, there are always sources of error. For us, we experienced error with the simple fact that the robot is not precise with the angle at which it turns, so if you tell it to turn 45 degrees its not going to be exact. Another source of error for us was that sometimes the robot malfunctions, and you have hard reset it before it works again. The main last source of error for us was that the same code will not have the same effect on different robots, so you may have to be patient with it and adjust accordingly.

Step 6: Conclusion

Now you have all the tools to play around with your roomba, which means that you can manipulate the code in anyway you want to achieve the goals you wish. This should be the best part of your day, so have fun and drive safely!

Share

    Recommendations

    • Tape Contest

      Tape Contest
    • Arduino Contest 2019

      Arduino Contest 2019
    • Trash to Treasure

      Trash to Treasure

    Discussions