hacking a roomba: part three [funsies]
Now it's time to make the Roomba be controlled by an Arduino so we can get the system to work autonomously in a room. Step one is to wire it up. Connect all the ground to the Arduino ground ports. Connect the signal wire of the ESC of the right motor to port 12, the left one to port 11. Connect the forward or IN1 input on the L298N motor controller to the pin9 of the Arduino and the IN2 to pin10 even though we are only driving the pump forward and therefore won't be using pin10 for much.
It might be a good idea to secure the Arduino and the wires with zip-ties or something. You can also mount the Arduino to the robot in whatever way makes the most sense.
Now it's time to get to some test code... We need to start with setup code like this. We basically create the pin variables to store the locations of where the motors are plugged in. And we write the initialization. The pump will be controlled by a simple digitalWrite on the two pins, the first pin controls on/off by writing HIGH/LOW respectively, the second pin is always LOW because we never spin the pump in reverse. The drive motors need a 1500ms PWM signal written to them for about one second through startup for them to be enabled.
Turns out when we turn on the motors, the motor for the RIGHT WHEEL is reversed. So we're just going to write a function that takes two inputs and controls the speed of the motors on -100 to 100 because that's a lot easier than accounting for the reversed motor each time.
Before we get to the pump, let's determine the navigation algorithm the Roomba will use to get around. We want the Roomba to bounce around the room cleaning. Basically, the Roomba will drive straight until it hits a wall, turn an amount, drive straight, turn, and etc. So we need sensors that detect wall distance.
We mounted three IR distance sensors to the Roomba, one on the front, two on the sides. These are 10cm short range sensors, and when we detect anything with the sensor the value will change from LOW to HIGH or HIGH to LOW. We will digital read this sensor and it will act like a button almost.