Hi everybody,
I very much like the mouse control of the robot, and it works using the input data stream from the mouse.
(see code below).
Then I tried to combine it with the ultrasonic sensor, i.e. if sth is in the way, the robo should stop.
My Problem is that reading the mouse stream halts the program until an input from the mouse is delivered
before proceeding the program, so I can’t read the distance to objects if the mouse is not used - but
robo might be still running and the wall is getting closer
Any idea how I can e.g. timeout the buf = file.read(3)
, so I can do an ultrasonic measurement and
then ask for mouse input again (idea: listen 0.5 sec to mouse, 0.5. sec to ultrasonic and so on) or
any other solution?
Thanks a lot for your help,
Chris
#Open the stream of data coming from the mouse
file = open( "/dev/input/mice", "rb" );
speed=150
debug = 0 #Print raw values when debugging
#Parse through the fata coming from mouse
#Returns: [left button pressed,
# middle button pressed,
# right button pressed,
# change of position in x-axis,
# change of position in y-axis]
def getMouseEvent():
buf = file.read(3)
button = ord( buf[0] )
bLeft = button & 0x1
bMiddle = ( button & 0x4 ) > 0
bRight = ( button & 0x2 ) > 0
x,y = struct.unpack( "bb", buf[1:] )
if debug:
print ("L:%d, M: %d, R: %d, x: %d, y: %d\n" % (bLeft,bMiddle,bRight, x, y) )
return [bLeft,bMiddle,bRight,x,y]