• aditya mehrotra.

hacking a Roomba: idk what part this is anymore, the next one [funsies]

So today, we're going to try to finish this adventure by programming in the wall-bouncing sensors, which in our case is a single, forward-facing IR distance sensor. We will see if this works when testing it in a room and if it does not we will add the other two wall bouncing sensors. But the algorithm will be kind of like this. The Roomba will drive forward till it "hits a wall" (when the IR sensor says it sees something), then the Roomba will turn a random amount, and then repeat this until it gets shut off and the floor seems mostly clean.






The first things we did were write the code for the IR_PIN input and to constantly read and print the sensor value. We're using the digitalRead even though this sensor is analog because the IR Sensor we are using, the range is 10cm, and if anything comes within 10cm of the robot, we might as well have hit it. So we're just using it as a button "on/off" for "hit/no-hit." We're going to run the above code and move our finger close to and away from the sensor to see if the "HIGH" values or the "LOW" values are "hits" or "clears."


So this above code didn't work because it was printing digital values we couldn't understand so we changed the code to this.







The above code now prints TRUE when the sensor reads a HIGH value and FALSE when it reads a LOW value. When I put my finger close to the sensor it reads FALSE. Therefore we are looking for the LOW value in the code.


DON'T delete the above code segment, it's time to start coding the Roomba's movements and we will use it. Inside the IF statement we used to see the HIGH values, we will be asking the Roomba to drive forward. In the ELSE statement, we will generate a random number between 0 and 5000 (representing a time-delay in milliseconds), and we will generate a random number 0 or 1 (representing right or left turn). We will then ask the Roomba to turn for that amount of time in that direction.


OKAY SO THIS WORKS!!! We're going to solder a battery onto this Roomba and test the wall bouncing code and etc before we go to the pump and other functionality.


Wried in the battery, turned it on, the Roomba went super fast hit into a wall and now I'm back at my desk. So few things, one the trajectory was CURVED, so we will need to make the right motor run a bit slower than the left motor (maybe by 10% or so?) and then we need to slow the speeds WAYYYY down.


So when we slowed the speeds to 25%, it works REALLY well!! We will likely need to add the other two sensors because the range of this IR sensor is very small and the bot tends to get stuck on things. The other thing is we dropped the time random to 2000 ms max because 5 seconds is ALOT of seconds to be turning.


Now, let's get the other three IR Sensors working. All we're going to do is add the other two IRs, and if any IR fires then the robot will execute the turning commands sequence.


Here is the final code. Video coming later.


0 views0 comments
© copyright 2019 | aditya mehrotra