Introduction: Garden Helper Roomba Bot

Kiara Myers, Ahmad Alghadeer, and Madison Tippet

Purpose:

This instructable will teach you how to program a Roomba Bot, using MATLAB, to navigate through a garden, detecting circular-shaped fruits/vegetables that are ripe enough to be picked based on their size. This robot also sends you an email, alerting you how many fruit are ready to be picked and the path in which it traveled.

Features:

  • Uses light sensors to detect walls and turn slightly in order to avoid hitting them
  • Uses bump sensors in order to break the program when it hits the rock at the end of the garden
  • Uses image processing to detect a circle in the garden and then determine its radius
  • Uses cliff sensors to detect a colored tape that indicates the presence of a fruit

Step 1: Materials and Supplies:

  • One Laptop
  • MATLAB 2017
  • Roomba Vaccum Cleaner
  • Raspberry Pi
  • Wood Blocks
  • White Paper
  • Black Paper
  • Colored tape/thin strip of colored paper
  • Large Rock

Step 2:

Step 3: Assembling Your "Garden"

  1. Take your black paper and cut circles of various sizes
  2. Tape these black circles onto a large white paper
    • This contrast will be necessary when detecting a fruit
  3. Use your woodblocks to construct a maze-like garden path for your robot to navigate
    • We chose a U-shaped path as pictured above
  4. At the end of your garden add a rock or door or another object for your robot to know it is done
  5. Tape your white paper with the circle onto the walls of the garden
    • We used buckets to tape it to because our walls were too short for the camera
  6. Put colored tape/thin strip of colored paper on the ground in front of the fruit

Step 4: Writing the Code

Navigating the Garden

Using Bump Sensors: To run the program, we place the coding in a while statement that loops through various if statements until the code is broken. If any of the bumpers are hit, it will result in their value equaling true (which in Boolean is a value of 1). An if statement is used to break the code when one of their values equals 1.

Using Cliff Sensors: Within the while statement, we use an if statement to tell the Roomba when it has arrived at the location of a plant. The Roomba detects the colored tape on the floor by examining the threshold of red that the cliff sensors pick up. If the left or right cliff sensor detects a color with a greater threshold than that of the ground, then it will stop the robot for 2 seconds (using pause command). During these 2 seconds, the Roomba will take and display an image of the fruit. Using the imfindcircles built in command, set a range for your circles' radii, and your Roomba will find your so-called fruit.

Using Image Processing: Within the if statement, we embed another if statement that says: if the radius detected,radii3, is greater than or equal to our minimum requirement of a ripe fruit, r1 (you decide this), then count and display on the Roomba how many fruit are ready and turn to continue through the garden. If not, the turn to continue through the garden. Note: you may need to adjust the angle that you turn because every Roomba is different

Using Light Bumpers: In another if statement, the light bumpers are analyzed to be sure none of them become greater than our determined threshold. If either the left, right, left center, right center, left front, or right front light bumper goes above the threshold, then the Roomba will turn slightly in the appropriate angle to avoid hitting a wall. Hence, navigating the maze.

The rest of the code is used to plot the path taken by the Roomba and then send the results to your email

Step 5: Copy the Code

% Purpose: Based on their sizes the roomba will go through a garden and distinguish vegetables/fruits that are ready to be picked up. % Inputs: Lightbump sensors, Cliff sensors, Bump sensors, image from camera % Outputs: Whenever light sensors are greater than threshold the roomba will turn and take an image, beeps if the radius of % vegetables/fruits is between a specific range. The code breaks when roomba bumps into % an object, sends the astronaut an email about how many fruits are ready to be % picked up and a mapping of the roomba's movement. % Usage: If and while statements, plotting commands,email code from MATLAB

k=0

tic

timerVal=tic

while true

v=.2; % velocity r.setDriveVelocity(v,v);%roomba go forward L=r.getLightBumpers ; LC=L.leftCenter ; Rr=L.right ; Lf=L.left ; RC=L.rightCenter ; LF=L.leftFront; RF=L.rightFront; Q= 75 ; % threshold. RTH=30; %High red threshold RTL=10; %Low red threshold B=r.getBumpers S=r.getCliffSensors; r1=24; r3=10; PL1=1800; if S.leftFront > PL1 || S.rightFront > PL1 %detects if the color on the ground is above the threshold r.stop pause(2) elapsedTime=toc(timerVal-2) tic timerVal=tic % pause for 2 seconds img = r.getImage; %take image imshow(img)%display image [centers3, radii3] = imfindcircles(img,[30 50],'ObjectPolarity','dark','Sensitivity',0.9); h = viscircles(centers3,radii3); %look for circles of radii w/in specified range in image if radii3>=r1 T=1 k=k+1 dist1=0.2.*elapsedTime %If radius detected is greater than or equal to the minimum %requirement of a ripe fruit, then the Roomba counts this fruit elseif radii3<=r3 T=0 else T=0 dist2=0.2.*elapsedTime %If not, then it does not count the fruit end

if T==1 r.setLEDDigits(num2str(k)) r.beep r.beep r.beep r.turnAngle(78) %If a fruit was detected, then display the number on Roomba, %make a noise, and turn elseif T==2 r.turnAngle(78) %If 2 fruits are detected, then turn to continue through the %garden else r.turnAngle(78) %If no fruits are detected, then turn to continue through the %garden end end if LC >Q r.stop r.turnAngle(-7) elseif RC >Q r.stop r.turnAngle(7) elseif LF >Q r.stop r.turnAngle(-7) elseif RF >Q r.stop r.turnAngle(7) elseif Lf > Q r.stop r.turnAngle(-7) elseif Rr >Q r.stop r.turnAngle(7) end %If any of the light bumpers' values goes above the threshold, then %the Roomba will turn slightly in the appropriate direction to avoid %hitting a wall

if B.right ==1 || B.left==1 || B.front==1 dist3=0.2.*elapsedTime r.stop r.beep('F#*2,F#*2,c,F#*2,F#*2') r.turnAngle(360) %If any of the bumbers are hit, then the roomba plays sound, spins around, %and breaks the code

break end

end scatter(0.533,0,'^') hold on scatter(0.533,dist1,'<') hold on scatter(-dist2,dist1,'v') hold on scatter(-dist2,0,'d') saveas(gcf,'Movement.png')

kmsg=num2str(k) mail= 'sara.enani@gmail.com' password='Srsora123#' host='smtp.gmail.com' port='465'

setpref('Internet','E_mail',mail); setpref('Internet','SMTP_Server', host) props = java.lang.System.getProperties; props.setProperty( 'mail.smtp.user', mail ); props.setProperty( 'mail.smtp.host', host ); props.setProperty( 'mail.smtp.port', port ); props.setProperty( 'mail.smtp.starttls.enable', 'true' ); props.setProperty( 'mail.smtp.debug', 'true' ); props.setProperty( 'mail.smtp.auth', 'true' ); props.setProperty( 'mail.smtp.socketFactory.port', port ); props.setProperty( 'mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory' ); props.setProperty( 'mail.smtp.socketFactory.fallback', 'false' ); sendmail(mail, 'Hello Astronaut! There are this many fruits in the garden',kmsg,{'movement.png'})

Step 6: Results (email)

Step 7: Results (plot of Movement)

Step 8: Results (movement)