Picture this: Earth has finally colonized Mars after years of planning and hard work, only to realize that the new colony is infested with hostile Alien life. Disputes over land and resources has led to a full scale Alien invasion of Earth's new colony, and tension is in the air. Alien forces are pouring into the colony and the colonists are being attacked left and right. Times are tough and people no longer feel safe enough to go outside. Thankfully, there is hope for this deeply-rattled colony, as top engineers and scientists have come together to create a revolutionary line of defense: the Martian Life Exterminator 2000 (MLE-2000).
The robot is able to move and act on its on thanks to expert programming (more on that later) and is able to navigate the tricky Martian terrain with ease. Its imaging software is able to detect and identify Martian life forms based on their distinct green coloration. Once the robot has identified the Martian, it springs into action by attacking the life form head on as well as sounding an alarm which alerts the owner to the Alien invader. The robot's patrol area is easily programmable as well, and the variable speed function of the robot allows it to cover a lot of ground in a short amount of time. The robot can be stopped at any time with the push of a button, which can mean the difference between life and extermination for any poor soul that might be caught wearing green in front of it. This robot is affordable and readily available due to advancements in Earthly technology, and is the answer to all of Earth's Martian problems.
In theory, it sounds like a dream come true; now it's time to examine the design of this product.
Step 1: Materials and Requirements
Materials needed include:
-Customized Roomba Robot with the vacuum removed or the iRobot Create Programmable Robot
-Raspberry Pi camera attachment
-Raspberry Pi mount
-Python code for the Raspberry Pi (will paste in later)
-Most recent version of MatLab
-Matlab Roomba Toolbox (from the University of Tennessee EF 230 class)
-Anything green to serve as an alien
-Masking tape to set a patrol region
-Weapon like a rusty screwdriver to tape to the front of the roomba
These are all the materials it takes to be able to create your own MLE-2000. This simple yet brilliant machine will be the difference between life and death for future colonization attempts on Mars. The MLE-2000 is programmed to be able to read between four sensors and respond correctly to each. This is where the most recent download of MatLab is needed. To be able to set the boundaries that the MLE-2000 is to patrol, certain restraints must be set via MatLab to ensure the MLE-2000 stays within its search area. Once these are set then the Robot can be free to carry out its primary function of protecting citizens of Mars. The MatLab code can become pretty extensive however which is why we will now examine the MatLab coding.
To get the Matlab Roomba Toolbox, copy the program linked into Matlab and run it to install the toolbox. This toolbox includes Matlab functions that allows your computer to communicate with the robot, read sensors, and drive its wheels.
Step 2: Code and Logic
Track Alien Camera Function
You will want to create a function used to take pictures of the roomba’s surroundings and identify green Martians hiding around it. You will want to output variables that you will need for later programs and functions.
function [img,bw,xm,ym] = trackalien(r)
Activate the getImage function included in the roomba toolbox and extract the color components of the image taken. Three 2D matrices corresponding to red, green, and blue components of the image are made.
img=r.getImage; image(img) red = img(:,:,1); green = img(:,:,2); blue = img(:,:,3);
Calculate the intensity of green component.
justGreen = green - red/2 - blue/2;
Find the regions of the image that are considered by the robot to be green enough to be an alien.
bw = justGreen > 40; image(bw);
Find the center of the green region. The else component of the if statement is used to fill variables that would otherwise be empty if no green was detected, and affect later code.
[x, y] = find(bw);<br>if ~isempty(x) && ~isempty(y) xm = round(mean(x)); ym = round(mean(y)); xx = max(1, xm-5):min(xm+5, size(bw, 1)); yy = max(1, ym-5):min(ym+5, size(bw, 2)); bwbw = zeros(size(bw), 'uint8'); bwbw(xx, yy) = 255; else xm=0; ym=0; bw=0; bwbw=0; end
Display the final image with the green regions highlighted and a marker at the center of the region
image(justGreen + bwbw); end
This function was made with the assistance of the example on the Mathworks website ,"Tracking a Green Ball."
Obstacle Avoidance Function
The Martian landscape is rife with obstacles, and your roomba robot will need to be able to avoid them. You will want to make an object avoidance function that keeps your bot in its patrol area while moving around rocks and other hazards.
You will want to get sensor readings from the cliff, bumper, and light bumper sensors in the roomba by calling the following functions from your roomba toolbox and storing the results.
cliffSensors = r.getCliffSensors; bumpers = r.getBumpers; lightBumpers = r.getLightBumpers;
Make the roomba turn once it reaches the edge of its patrol area, detected by the cliff sensor, or when it encounters and obstacle detected by the bump or light sensor. Some objects will not be detected by the light sensor, such as short rocks, but will be counted by the bumper sensors. The roomba will need to turn more the closer to the center of the front it detects something (for example, the roomba in the code will only turn 30 degrees if its rightmost light bumper detects a hazard, but will need to turn 60 degrees if it detects a danger right in front of it with its right-center light bumper).
if bumpers.right == 1 r.turnAngle(30) elseif bumpers.left == 1 r.turnAngle(-30) elseif bumpers.front == 1 r.turnAngle(60) elseif cliffSensors.left > 1200 r.turnAngle(-45) elseif cliffSensors.leftFront > 1200 r.turnAngle(-60) elseif cliffSensors.right > 1200 r.turnAngle(45) elseif cliffSensors.rightFront > 1200 r.turnAngle(60) elseif lightBumpers.left > 400 r.turnAngle(-45) elseif lightBumpers.leftCenter > 400 r.turnAngle(-60) elseif lightBumpers.right > 400 r.turnAngle(30) elseif lightBumpers.rightFront > 400 r.turnAngle(45) elseif lightBumpers.rightCenter > 400 r.turnAngle(60) end end
Alien Confrontation Function
You will now want to make a function that will dictate what the roomba will do once it detects an alien.
Call the trackalien function created earlier and store the bw value that represents the green image.
[~,bw,~,~] = trackalien(r);
Determine if the amount of green detected by the camera is enough for it to be a Martian threat. The alien needs to know your roomba means business, so have its LEDs display "DIE."
You will want to be looping the next part of code while the roomba still sees the alien, so throw in a while loop. Have the robot beep to raise the alarm for nearby colonists, and have it move forward to deal with the alien.
if nnz(bw) > 4000 r.setLEDDigits('DIE'); while nnz(bw)> 4000 r.beep r.setDriveVelocity(0.2)<br>
Take another picture to check if the alien is still in the center of the roomba's cross-hairs. If it is not, turn the robot to accommodate for the agility of the alien. You can check this by evaluating if the y-mean is in the center half of the picture.
[~,bw,~,ym] = trackalien(r); if ym<150 elseif ym>350 r.turnAngle(-1) end
Check the values of the light bumpers of the roomba to make sure it doesn't get held up by any obstacle while it confronts the alien. Turn to avoid any obstacle, but not too much so as not to lose the alien.
lightBumpers = r.getLightBumpers; if lightBumpers.left > 400 || lightBumpers.leftFront > 400 || lightBumpers.leftCenter > 400 r.turnAngle(-10) elseif lightBumpers.right > 400 || lightBumpers.rightFront > 400 || lightBumpers.rightCenter > 400 r.turnAngle(10) end
Your roomba will want to know when it reaches the alien. Check if the bumpers registers hitting an object in front of the roomba, and if the object is primarily green to see if its a dirty Martian. If it is, ram it repeatedly by moving back and forth until it drops. Return back to the patrol area after dealing with the alien by retreating backwards.
bumpers = r.getBumpers; if bumpers.front == 1 && nnz(bw) > 25000 <br> r.setDriveVelocity(0) r.moveDistance(-0.01) r.moveDistance(0.01,0.2) r.moveDistance(-0.01) r.moveDistance(0.01,0.2) pause(0.5) r.moveDistance(-0.75) r.turnAngle(-90) end
Deal with some "loose ends" to finish the function. The function will loop until it loses the alien and the green readings drop below a certain threshold.
end end end
Finally, a patrol code is needed to bring all these useful function together to make those Martian scumbags wish they were never born (or cloned, it's unsure how they actually reproduce). First, set up a while loop for the patrol code to run constantly. Start a timer with the tic command; it will be used to time intervals between landscape scans. The LED display on the roomba should also be set to show "MLE" (Martian Life Exterminator), so that the "DIE" message is not constantly displayed. "MMLE" is used in the code, because of the limitations of the display screen.
i=0; while i<1 tic r.setLEDDigits('MMLE');
For 7.5 seconds, make the roomba move along its patrol route with the setDriveVelocity command from the roomba toolbox. The toc command checks the time elapsed since the timer was started. Now is the time to call the obstacle avoidance and alien confrontation function; they will keep the roomba from hitting dangerous hazards while looking out for scheming aliens. If it encounters an obstacle, it will turn away from it, and if it sees an alien, it will move to eliminate it.
while toc < 7.5 r.setDriveVelocity(0.2) ob_avoid(r) green_id(r) end
After the 7.5 seconds is up, reset the timer. Make the roomba do an area scan by stopping it and turning it at a constant speed while looking out for aliens with the alien confrontation function. The setTurnVelocity from the roomba toolbox can be used to constantly turn the robot until it is told otherwise. Finally, end the code and let the roomba out on patrol.
tic while toc < 7.5 r.setDriveVelocity(0) r.setTurnVelocity green_id(r) end end
Step 3: Conclusions and Results
After numerous test trials and hours of work, we believe that we have made a marketable and complete product. The robot is able to utilize its light, bump, and cliff sensors without fail and its imaging component allows it to detect Martian invaders at nearly any distance. This product, using the aforementioned features, is able to navigate the Martian landscape all on its on without any additional user inputs, and is able to stay within its patrol area. We believe that our robot has gone above and beyond the requirements for this project, as it not only meets all of the grading criteria, but also has a few unique features.
First of all the bump sensors aren't used for landscape navigation nearly as much as they are for Martian annihilation. This is shown by the robot hitting the Martian, backing up, and then proceeding to repeat until the invader is exterminated. Additionally, our robot is able to more accurately aim for Martian vital spots with the use of the green ID function and a few parameters. This parameters include relative amount of green pixels found in the camera, and the fact that the robot is lined up carefully with the Martian by utilizing the centroid of the green image as a target. If the centroid of the target is not in line with the camera (and thus the robot as well) then the robot will adjust its angle of approach to ensure a swift death. Additionally, our Roomba is able to accurately find the centroid of the green object thanks to imaging data and looping conditionals. A final noteworthy feature might be the use of the light bumpers, as we attempted to use those to help the robot navigate the landscape. However, we were also able to vary the angle at which the robot turned depending on whether or not it had a Martian in its sights. This effectively means that the robot will be able to maintain its focus on the Martian while at the same time avoiding any obstacles in its way.
In conclusion, Earth's colonies on Mars can rest easy knowing that they have an ever present enforcer on their side: the MLE-2000.