Wednesday, February 21, 2007

Problems with PyHook and Tk

Hamsterbot requires that we convert mouse motion into differential drive motion.
Both the pyHook and Tkinter provide ways of monitoring cursor movements, so by modifying our pyRoomba code, we can now get an updated position of the cursor (such that the origin at the center of the map, and only when the mouse is over the map with no other windows between them) at each loop. There are many different ways we could use this information to adjust our linear and angular velocities, but I think one of the following should be both simple and effective for a first try:

1. Start the cursor position at the center of the screen. Keep track of the previous cursor position. Upon detecting movement, get the new cursor position.
"Draw" a ray from the previous position to the new position and a vertical line through the previous position. If the angle between the line and the ray is within some (possibly large) tolerance of 0, go straight forward. Within tolerance of 180: go backwards. Otherwise circle forwards or backwards and left or right based on which way the ray points.

Problem with 1: The cursor position is bound within the map. We cannot make the robot go forward for an arbitrary distance using the physical mouse because the cursor effectively encounters a wall at the edge of the map. Also, if the cursor moves off the map some distance, it has to be moved back that distance before the robot will pick up the motion again. We can solve this last problem by maximizing the map, but then we are still bound within the screen. However, we might be able to scale our screen to an arbitrarily large (or small) physical area by slowing the cursor speed via the OS. In fact, increasing the cursor speed should confine hamsterbot to a smaller area, like putting up an invisible fence.

2. Start the cursor at the center of the screen. Upon detecting movement, get the new position and do as in #1, but then reset the mouse position to the center of the screen. That way we never run out of screen. (At least one or both pyHook and Tk offer ways of checking if a mouse move was 'injected' by a program rather than coming from the actual device, so we won't count the resetting of the positiong as a movement.)

Problem with 2: Neither pyHook nor Tk nor any other package I can find seems to offer a way of injecting Windows mouse events in python.

Wednesday, February 7, 2007

Programs, Python and Photographs



Today Lilia and I successfully wrote a simulator for our dear Roomba which navigates a small room and seeks out a goal. This program is written in Python and runs on my laptop, which communicates the proper movements to the Roomba via a Bluetooth radio, which is the chip seen in the picture.


Indeed, we tried to test this program out on our Roomba. Unfortunately, we discovered that Roombas tend to not work so well when you don't have them charged. As a result, the only video of our progress so far is this one. Just wait, better things will come very soon!



Until we get some cool videos up, you will have to be content with the ever-fearsome, Snakes on Roombas!

Friday, February 2, 2007

Remote Control Roomba

Today we got the pyRoomba python code working on Scott's laptop. We also obtained a bluetooth radio for our roomba so that it can be controlled remotely through python scripts or the command prompt.

Our next objective is to capture some images and/or video of the roomba in action. We are also trying to think of an alternate name for our roomba, to distinguish it from other roombas...

We will also start working on the next step towards Hamsterbot: writing Python code to capture wireless optical mouse data and convert it into pyRoomba commands.