Difference between revisions of "Roomba project"

From AIRWiki
Jump to: navigation, search
(Wall following algorithm)
(Pyro: download and installation)
Line 29: Line 29:
 
  makefile
 
  makefile
  
If you have python version 2.6 or higher, you need to modify the file:
+
If you have python version 2.6 or higher, you need to modify the following file in the pyrobot folder:
  /usr/lib/python2.6/dist-packages/pyrobot/bin/pyrobot
+
  /pyrobot/bin/pyrobot
  
changing the words "site-packages" with "dist-packages" wherever it appears. This modification must not be done if you have earlier python versions. From now on, we will refer to python version 2.6.
+
changing the words "site-packages" with "dist-packages" wherever it appears. Attention: this modification must not be done if you have earlier python versions. From now on, we will refer to python version 2.6.
 +
 
 +
Then you should move the pyrobot folder you have downloaded (after the installation) to the folder
 +
/usr/lib/python2.6/dist-packages
  
 
Now you can run the program writing from terminal:
 
Now you can run the program writing from terminal:

Revision as of 16:47, 17 August 2010

Roomba Analysis and Modification
Image of the project Roomba project
Short Description: Roomba's control system study and modification
Coordinator: GiuseppinaGini (gini@elet.polimi.it)
Tutor: ThomasFerrari (tferrari@elet.polimi.it)
Collaborator:
Students: AndreaScalise (andrea.scalise@aol.it), NiccoloTenti (nicotenti@libero.it)
Research Area: Robotics
Research Topic: Robot development
Start: 2010/05/10
End: 2010/09/25
Status: Active
Level: Ms
Type: Course

This project is about studying the vacuum cleaner Roomba's brain, in order to modify and add new behaviours to it: in particular a wall-following algorithm will be implemented and tested. The interfacing with the robot will be provided by Pyro, a library, environment, graphical user interface to explore AI and robotics using the Python language.

Interfacing with Pyro

Pyro is a powerful software written in Python, used to provide a high level interface to many types of robots, regardless of their hardware structure. Here the main steps to configure properly the Pyro environment and to interface it with a Roomba. For the project a Roomba 535 will be used (the one shown in the photo).

Pyro: download and installation

First of all, you need to download the latest version of Pyro. You can choose between different versions and operative systems from this website: http://pyrorobotics.org/download/. Since the project will be developed under Linux, we will refer to Linux Ubuntu OS, using the Pyro version 5.0.0. Then, you need to install it, open a terminal, move to the pyrobot folder, write the following commands and follow the instructions:

./configure.py
make
makefile

If you have python version 2.6 or higher, you need to modify the following file in the pyrobot folder:

/pyrobot/bin/pyrobot

changing the words "site-packages" with "dist-packages" wherever it appears. Attention: this modification must not be done if you have earlier python versions. From now on, we will refer to python version 2.6.

Then you should move the pyrobot folder you have downloaded (after the installation) to the folder

/usr/lib/python2.6/dist-packages

Now you can run the program writing from terminal:

cd /usr/lib/python2.6/dist-packages/pyrobot/bin/
./pyrobot

You can also copy the file executable file in your home folder, and write from terminal:

./pyrobot

Roomba's Pyro files configuration

Before starting to use pyrobot with the Roomba, you must modify some settings in the Roomba robot files; these modifications are needed because the interfacing with Roomba that Pyro provides it's general, so there might be different behaviours according to your Roomba model (in this documentation we refer to Roomba 535).

First of all, you need to open the following file, as administrator:

/usr/lib/python2.6/dist-packages/pyrobot/robot/roomba.py

At line 459, you will find the code

dev.sendMsg('\x89\x00\x80\x00\x00')

You should change the last '0' with a '1'. This piece of code represents the bytes sent to the Roomba to force the rotation anticlockwise, but with the final zero, it represents a translation forward.

At line 316, you can find the code which transforms the value related to the rotation angle got by the sensors in radians. You should replace the value '258' with '38.5':

self.sensorData['angleInRadians'] = (2.0 * self.sensorData['rawAngle']) / 258

This depends on how the Roomba sensors process the information, and probably it worked for another model of Roomba. The value 38.5 was obtained by proportions.

At line 318, you have to substitute the value '0.001' with '0.01' in the following line, since the distance run by the Roomba is in centimeters:

d = self.sensorData['distance'] * 0.001

In the end, at line 319, a '-' is needed instead of the '+'

self.x += math.cos(a) * d
self.y += math.sin(a) * d

Wall following algorithm

from pyrobot.brain import Brain
from pyrobot.brain.behaviors import State, FSMBrain
from pyrobot.geometry import *   # import distance function
import time, math
  
class findWall (State):

   def onActivate(self): 
       print "Inizio"

   def update(self):
       self.left = self.robot.getSensor("leftBump")
       self.right = self.robot.getSensor("rightBump")

       self.robot.move(0.3,0)   
		
       if ((self.right == 1) or (self.left == 1)) :
          self.goto('turnSx')


class turnSx (State):
 
   def onActivate(self): 
       print "Stato turnSx"
	
   def update(self):
       self.left = self.robot.getSensor("leftBump")
       self.right = self.robot.getSensor("rightBump")

       self.robot.move(0,0.3)  

       if ((self.right == 0) and (self.left == 0)): 
          self.goto('correctDx')

     
class correctDx (State):

   def onActivate(self):
       print "Stato correctDx"

   def update(self):
       self.left = self.robot.getSensor("leftBump")
       self.right = self.robot.getSensor("rightBump")
       self.wall = self.robot.getSensor("wallSensor")
 
       self.move(0.25,-0.37)
	
       if ((self.right == 1) or (self.left == 1)) :
          self.goto('turnSx')

       if (self.wall == 1): 
          self.goto('correctSx')


class correctSx (State):
 
   def onActivate(self):
       print "Stato correctSx"
        
   def update(self):
       self.left = self.robot.getSensor("leftBump")
       self.right = self.robot.getSensor("rightBump")
       self.wall = self.robot.getSensor("wallSensor")
        
       self.move(0.3, 0.15)

       if ((self.right == 1) or (self.left == 1)) : 
          self.goto('turnSx')

       if (self.wall == 0): 
          self.goto('correctDx')
        

def INIT(engine): 
       brain = FSMBrain("Wall Following Brain", engine)
       # add states:
       brain.add(findWall(1))
       brain.add(turnSx())
       brain.add(correctDx())
       brain.add(correctSx())
	
       return brain