Introduction: Rescue Rover (Creating a Remote Controlled Roomba)
Introduction:
Since the Roomba is intended to function like a rover on Mars, it is important that it is equipped to handle the Martian environment. To prepare your rover for its trip to space you should include inputs such as cliff sensors, light sensors, image reading and bump sensors in your code. Shown below are step-by-step instructions for creating a remote controlled Roomba using MATLAB.
Step 1: Parts and Materials
The first part you will need for the project is an iRobot Create. This is a robot that looks like a Roomba, but can be freely programmed. Next, you will need the newest version of MATLAB on your desktop or laptop, as well as the mobile version. You will also need a Raspberry Pi microcomputer, preprogrammed so you can use MATLAB as your only coding program. Finally, you will need a compatible Camera Module for the Raspberry Pi.
Optional: If you have access to a 3D printer, you can print a model Astronaut that you can save from the troubles of Mars! If not, a toy astronaut or other figure works just as well!
In order to connect to the iRobot, you will need to run a series of code that will download toolboxes necessary for the project. You can find this code on the following website:
https://ef.engr.utk.edu/ef230-2017-08/projects/roomba-s/setup-roomba-instructable.php
Step 2: Connecting Your Phone
The first code you will need to run is in order to connect your phone to MATLAB, and have it use the phone's sensors to control the iRobot. To connect phone, use the command "connector on" in the command window and follow the instructions giving on the mobile MATLAB app.
Run the following code in order to orient the iRobot to your phones sensors.
%Get data from mobile device orientation and seperate the datainto seperate
%variables
m=mobiledev %final step in connecting phone
pause(.5)
PhoneData=m.Orientation;
Azi=PhoneData(1);
Pitch=PhoneData(2);
Side=PhoneData(3);
%cause an output based on the side to side orientation
if Side>130 || Side<-130 %if the phone is flipped face down stop the roomba and exit loop
r.setLEDDigits('SAFE')
break
elseif Side>25 && Side<40 %if the phone is turned sideways between 25 and 40 deg turn left 5 deg
r.turnAngle(-5);
elseif Side>40 %if the phone is turned sideways over 40 deg turn left 45 deg
r.turnAngle(-45)
elseif Side<-25 && Side>-40 %if the phone is turned sideways between -25 and -40 deg turn right 5 deg
r.turnAngle(5);
elseif Side<-40 %if the phone is turned sideways less than -40 deg turn left 45 deg
r.turnAngle(45)
end
You will need to share the phone's sensors from the MATLAB app. Once you press "start", MATLAB will be able to your phone sensors to control your robot.
Step 3: Getting Light Sensors
The Light sensors help the iRobot to prevent from bumping into anything on its path to save the astronaut. The following code will get access to the light sensors, and move the iRobot out of the path of any object in its way.
zz=getLightBumpers(r) % light sensors
lights=cell2mat(struct2cell(zz))
if lights(1,1) > 20
r.setLEDCenterColor(255)
r.turnAngle(-40)
r.moveDistance(0.4)
r.turnAngle(40)
elseif lights(2,1) > 20
r.setLEDCenterColor(255)
r.turnAngle(-40)
r.moveDistance(0.4)
r.turnAngle(40)
elseif lights(4,1) > 20
r.setLEDCenterColor(255)
r.turnAngle(40)
r.moveDistance(0.4)
r.turnAngle(-40)
elseif lights(3,1) > 20
r.setLEDCenterColor(255)
r.turnAngle(40)
r.moveDistance(0.4)
r.turnAngle(-40)
end %end light sensors
Step 4: Getting Bump Sensors
Bump sensors on the iRobot are meant to move the robot out of the way of anything it bumps into. For the rover, the bump sensors will help let us know if it is under attack from extraterrestrial beings, and warn our astronaut to get to cover. The following code will display a distress signal and a message "HELP" on the iRobot's LEDs if something hits into it.
abc=getBumpers(r) %physical bump sensors
bumps= cell2mat(struct2cell(abc))
if bumps(1,1) ~=0
r.setLEDDigits('HELP')
r.turnAngle(300)
r.songPlay('T400,C,D,E,F,G,A,B,C^')
elseif bumps(2,1) ~=0
r.setLEDDigits('HELP')
r.turnAngle(300)
r.songPlay('T400,C,D,E,F,G,A,B,C^')
elseif bumps(3,1) ~=0
r.setLEDDigits('HELP')
r.turnAngle(300)
r.songPlay('T400,C,D,E,F,G,A,B,C^')
elseif bumps(4,1) ~=0
r.setLEDDigits('HELP')
r.turnAngle(300)
r.songPlay('T400,C,D,E,F,G,A,B,C^')
elseif bumps(5,1) ~=0
r.setLEDDigits('HELP')
r.turnAngle(300)
r.songPlay('T400,C,D,E,F,G,A,B,C^')
end %end bump sensors
Step 5: Getting Cliff Sensors
Cliff sensors prevent the iRobot from falling down stairs or any other drop off in its way. For our Mars Rover, the cliff sensors will help make sure the Rover doesn't fall into any craters or sand pits. The following code will stop the iRobot from falling off of a surface, and will move it out of the way of the obstacle.
x=getCliffSensors(r) %cliff sensors
cliffs=cell2mat(struct2cell(x))
if cliffs(2,1) > 1500
r.beep
r.beep
r.beep
r.moveDistance(-0.4)
r.turnAngle(70)
r.moveDistance(0.8)
r.turnAngle(-70)
elseif cliffs(3,1) > 1500
r.beep
r.beep
r.beep
r.moveDistance(-0.4)
r.turnAngle(70)
r.moveDistance(0.4)
r.turnAngle(-70)
elseif cliffs (1,1) > 1500
r.beep
r.beep
r.beep
r.moveDistance(-0.4)
r.turnAngle(-40)
r.moveDistance(0.4)
r.turnAngle(40)
elseif cliffs (4,1) > 1500
r.beep
r.beep
r.beep
r.turnAngle(40)
r.moveDistance(0.4)
r.turnAngle(-40)
end %end cliff sensors
Step 6: Seeing a Distress Signal
Using the camera, the iRobot will be able to see and analyze text based sign in order to jump into action. For our purpose, the code below will have the camera will read a sign "HELP", and will display a live feed of the camera as your "control center" and a warning message for the operator.
while 1==1
img=r.getImage;
txt=ocr(img)
if strcmpi(txt.Words,'HELP') == 1
r.showCamera
f=msgbox('Help! Someone is in trouble!')
break
end
Step 7: Full Code
The following code is a full script, putting all the previous coding together with while loops, so the iRobot can run continuously. Have fun with your new Rescue Rover!
while 1==1
img=r.getImage;
txt=ocr(img)
if strcmpi(txt.Words,'HELP') == 1
r.showCamera
f=msgbox('Help! Someone is in trouble!')
break
end
while 0==0
%Get data from mobile device orientation and seperate the datainto seperate
%variables
pause(.5)
PhoneData=m.Orientation;
Azi=PhoneData(1);
Pitch=PhoneData(2);
Side=PhoneData(3);
%cause an output based on the side to side orientation
if Side>130 || Side<-130 %if the phone is flipped face down stop the roomba and exit loop
r.setLEDDigits('SAFE')
break
elseif Side>25 && Side<40 %if the phone is turned sideways between 25 and 40 deg turn left 5 deg
r.turnAngle(-5);
elseif Side>40 %if the phone is turned sideways over 40 deg turn left 45 deg
r.turnAngle(-45)
elseif Side<-25 && Side>-40 %if the phone is turned sideways between -25 and -40 deg turn right 5 deg
r.turnAngle(5);
elseif Side<-40 %if the phone is turned sideways less than -40 deg turn left 45 deg
r.turnAngle(45)
end
%move forward and backward based on the front and back orientation
if Pitch>15 && Pitch<35 %if pitch between 15 and 35 deg move forward short distance
r.moveDistance(.03)
elseif Pitch>35 %if pitch greater 35 deg move forward longer distance
r.moveDistance(.03)
elseif Pitch<-15 && Pitch>-35 %if pitch between -15 and -35 deg move back short distance
r.moveDistance(-.03);
elseif Pitch<-35 && Pitch>-60 %if pitch between -35 and -60 deg move back longer distance
r.moveDistance(-.03)
end
abc=getBumpers(r) %physical bump sensors
bumps= cell2mat(struct2cell(abc))
if bumps(1,1) ~=0
r.setLEDDigits('HELP')
r.turnAngle(300)
r.songPlay('T400,C,D,E,F,G,A,B,C^')
elseif bumps(2,1) ~=0
r.setLEDDigits('HELP')
r.turnAngle(300)
r.songPlay('T400,C,D,E,F,G,A,B,C^')
elseif bumps(3,1) ~=0
r.setLEDDigits('HELP')
r.turnAngle(300)
r.songPlay('T400,C,D,E,F,G,A,B,C^')
elseif bumps(4,1) ~=0
r.setLEDDigits('HELP')
r.turnAngle(300)
r.songPlay('T400,C,D,E,F,G,A,B,C^')
elseif bumps(5,1) ~=0
r.setLEDDigits('HELP')
r.turnAngle(300)
r.songPlay('T400,C,D,E,F,G,A,B,C^')
end %end bump sensors
zz=getLightBumpers(r) % light sensors
lights=cell2mat(struct2cell(zz))
if lights(1,1) > 20
r.setLEDCenterColor(255)
r.turnAngle(-40)
r.moveDistance(0.4)
r.turnAngle(40)
elseif lights(2,1) > 20
r.setLEDCenterColor(255)
r.turnAngle(-40)
r.moveDistance(0.4)
r.turnAngle(40)
elseif lights(4,1) > 20
r.setLEDCenterColor(255)
r.turnAngle(40)
r.moveDistance(0.4)
r.turnAngle(-40)
elseif lights(3,1) > 20
r.setLEDCenterColor(255)
r.turnAngle(40)
r.moveDistance(0.4)
r.turnAngle(-40)
elseif lights(4,1) > 20
end %end light sensors
x=getCliffSensors(r) %cliff sensors
cliffs=cell2mat(struct2cell(x))
if cliffs(2,1) > 1500
r.beep
r.beep
r.beep
r.moveDistance(-0.4)
r.turnAngle(70)
r.moveDistance(0.8)
r.turnAngle(-70)
elseif cliffs(3,1) > 1500
r.beep
r.beep
r.beep
r.moveDistance(-0.4)
r.turnAngle(70)
r.moveDistance(0.4)
r.turnAngle(-70)
elseif cliffs (1,1) > 1500
r.beep
r.beep
r.beep
r.moveDistance(-0.4)
r.turnAngle(-40)
r.moveDistance(0.4)
r.turnAngle(40)
elseif cliffs (4,1) > 1500
r.beep
r.beep
r.beep
r.turnAngle(40)
r.moveDistance(0.4)
r.turnAngle(-40)
end %end cliff sensors
end
end



