Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Aguiar <alanjas@hotmail.com>2012-10-06 05:47:25 (GMT)
committer Alan Aguiar <alanjas@hotmail.com>2012-10-06 05:47:25 (GMT)
commitb58a5f064239a3000f750f480ad3dd736473ab4c (patch)
tree59d297bf0f9c47aa82d459833a2651463f09ca7f
parentddb03afe9fef0f3f46ee2ad14e514982a22c1c1f (diff)
separate robot class from followme
-rwxr-xr-xfollowme.py104
-rwxr-xr-xrobot.py137
2 files changed, 137 insertions, 104 deletions
diff --git a/followme.py b/followme.py
index 5ff0a22..bba9df4 100755
--- a/followme.py
+++ b/followme.py
@@ -201,111 +201,7 @@ class Captura(object):
self.display.fill((84, 185, 72))
-class Robot(object):
-
- def __init__(self):
- self.z1 = tamanioc[0] / 15.0
- self.z2 = tamanioc[1] / 3.0
- self.vel_anterior = (0, 0, 0, 0)
- self.butia = None
- self.bobot = None
- self.bobot_launch()
-
- def bobot_launch(self):
-
- print 'Initialising butia...'
- output = commands.getoutput('ps -ax | grep lua')
- if 'bobot-server' in output:
- print 'bobot is alive!'
- else:
- try:
- print 'creating bobot'
- self.bobot = subprocess.Popen(['./lua', 'bobot-server.lua'], cwd='./lib/butia_support')
- except:
- print 'ERROR creating bobot'
-
- time.sleep(1)
- self.butia = butiaAPI.robot()
-
- self.modules = self.butia.get_modules_list()
-
- if (self.modules != []):
- print self.modules
- else:
- print _('Butia robot was not detected')
-
- def move_robot(self, pos):
-
- x,y = pos
-
- vel_actual = (0, 0, 0, 0)
-
- if (x >= 0) and (x <= (2*self.z1)):
- if (y >= 0) and (y <= self.z2) :
- vel_actual = (1, 900, 1, 600)
- elif (y > self.z2) and (y < 2*self.z2):
- vel_actual = (0, 900, 1, 900)
- elif (y >= 2*self.z2):
- vel_actual = (0, 900, 0, 600)
-
- elif (x > (2*self.z1)) and (x <= (4*self.z1)):
- if (y >= 0) and (y <= self.z2) :
- vel_actual = (1, 600, 1, 300)
- elif (y > self.z2) and (y < 2*self.z2):
- vel_actual = (0, 600, 1, 600)
- elif (y >= 2*self.z2):
- vel_actual = (0, 600, 0, 600)
-
-
- elif (x > (4*self.z1)) and (x <= (6*self.z1)):
- if (y >= 0) and (y <= self.z2) :
- vel_actual = (1, 300, 1, 0)
- elif (y > self.z2) and (y < 2*self.z2):
- vel_actual = (0, 300, 1, 300)
- elif (y >= 2*self.z2):
- vel_actual = (0, 300, 0, 0)
-
- elif (x > 6*self.z1) and (x < 9*self.z1):
- if (y >= 0) and (y <= self.z2) :
- vel_actual = (1, 300, 1, 300)
- elif (y > self.z2) and (y < 2*self.z2):
- vel_actual = (0, 0, 0, 0)
- elif (y >= 2*self.z2):
- vel_actual = (0, 300, 0, 300)
-
-
- elif (x >= (9*self.z1)) and (x < (11*self.z1)):
- if (y >= 0) and (y <= self.z2) :
- vel_actual = (1, 0, 1, 300)
- elif (y > self.z2) and (y < 2*self.z2):
- vel_actual = (0, 300, 1, 300)
- elif (y >= 2*self.z2):
- vel_actual = (0, 0, 0, 300)
-
-
- elif (x >= 11*self.z1) and (x < 13*self.z1):
- if (y >= 0) and (y <= self.z2) :
- vel_actual = (1, 300, 1, 600)
- elif (y > self.z2) and (y < 2*self.z2):
- vel_actual = (0, 600, 1, 600)
- elif (y >= 2*self.z2):
- vel_actual = (0, 300, 0, 600)
-
-
- elif (x >= (13*self.z1)):
- if (y >= 0) and (y <= self.z2) :
- vel_actual = (1, 600, 1, 900)
- elif (y > self.z2) and (y < 2*self.z2):
- vel_actual = (0, 900, 1, 900)
- elif (y >= 2*self.z2):
- vel_actual = (0, 600, 0, 900)
-
-
- # para evitar envios de velocidad innecesarios al robot
- if not(vel_actual == self.vel_anterior):
- self.vel_anterior = vel_actual
- self.butia.set2MotorSpeed(str(vel_actual[0]), str(vel_actual[1]), str(vel_actual[2]), str(vel_actual[3]))
class FollowMe:
diff --git a/robot.py b/robot.py
new file mode 100755
index 0000000..d4a6a61
--- /dev/null
+++ b/robot.py
@@ -0,0 +1,137 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# FollowMe Butia - Robot
+# Copyright (C) 2010, 2011, 2012
+# This program was created to use with the robot Butia.
+# Butia is a project from Facultad de Ingenieria - Uruguay
+# Facultad de Ingenieria web site: <http://www.fing.edu.uy/>
+# Butia project web site: <http://www.fing.edu.uy/inco/proyectos/butia/>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Contact information:
+# Alan Aguiar <alanjas@gmail.com>
+# Aylen Ricca <ar18_90@hotmail.com>
+# Rodrigo Dearmas <piegrande46@hotmail.com>
+
+
+
+class Robot(object):
+
+ def __init__(self, tamanioc):
+ self.z1 = tamanioc[0] / 15.0
+ self.z2 = tamanioc[1] / 3.0
+ self.vel_anterior = (0, 0, 0, 0)
+ self.butia = None
+ self.bobot = None
+ self.bobot_launch()
+
+ def bobot_launch(self):
+
+ print 'Initialising butia...'
+ output = commands.getoutput('ps -ax | grep lua')
+ if 'bobot-server' in output:
+ print 'bobot is alive!'
+ else:
+ try:
+ print 'creating bobot'
+ self.bobot = subprocess.Popen(['./lua', 'bobot-server.lua'], cwd='./lib/butia_support')
+ except:
+ print 'ERROR creating bobot'
+
+ time.sleep(1)
+
+ self.butia = butiaAPI.robot()
+
+ self.modules = self.butia.get_modules_list()
+
+ if (self.modules != []):
+ print self.modules
+ else:
+ print _('Butia robot was not detected')
+
+ def move_robot(self, pos):
+
+ x,y = pos
+
+ vel_actual = (0, 0, 0, 0)
+
+ if (x >= 0) and (x <= (2*self.z1)):
+ if (y >= 0) and (y <= self.z2) :
+ vel_actual = (1, 900, 1, 600)
+ elif (y > self.z2) and (y < 2*self.z2):
+ vel_actual = (0, 900, 1, 900)
+ elif (y >= 2*self.z2):
+ vel_actual = (0, 900, 0, 600)
+
+ elif (x > (2*self.z1)) and (x <= (4*self.z1)):
+ if (y >= 0) and (y <= self.z2) :
+ vel_actual = (1, 600, 1, 300)
+ elif (y > self.z2) and (y < 2*self.z2):
+ vel_actual = (0, 600, 1, 600)
+ elif (y >= 2*self.z2):
+ vel_actual = (0, 600, 0, 600)
+
+
+ elif (x > (4*self.z1)) and (x <= (6*self.z1)):
+ if (y >= 0) and (y <= self.z2) :
+ vel_actual = (1, 300, 1, 0)
+ elif (y > self.z2) and (y < 2*self.z2):
+ vel_actual = (0, 300, 1, 300)
+ elif (y >= 2*self.z2):
+ vel_actual = (0, 300, 0, 0)
+
+ elif (x > 6*self.z1) and (x < 9*self.z1):
+ if (y >= 0) and (y <= self.z2) :
+ vel_actual = (1, 300, 1, 300)
+ elif (y > self.z2) and (y < 2*self.z2):
+ vel_actual = (0, 0, 0, 0)
+ elif (y >= 2*self.z2):
+ vel_actual = (0, 300, 0, 300)
+
+
+ elif (x >= (9*self.z1)) and (x < (11*self.z1)):
+ if (y >= 0) and (y <= self.z2) :
+ vel_actual = (1, 0, 1, 300)
+ elif (y > self.z2) and (y < 2*self.z2):
+ vel_actual = (0, 300, 1, 300)
+ elif (y >= 2*self.z2):
+ vel_actual = (0, 0, 0, 300)
+
+
+ elif (x >= 11*self.z1) and (x < 13*self.z1):
+ if (y >= 0) and (y <= self.z2) :
+ vel_actual = (1, 300, 1, 600)
+ elif (y > self.z2) and (y < 2*self.z2):
+ vel_actual = (0, 600, 1, 600)
+ elif (y >= 2*self.z2):
+ vel_actual = (0, 300, 0, 600)
+
+
+ elif (x >= (13*self.z1)):
+ if (y >= 0) and (y <= self.z2) :
+ vel_actual = (1, 600, 1, 900)
+ elif (y > self.z2) and (y < 2*self.z2):
+ vel_actual = (0, 900, 1, 900)
+ elif (y >= 2*self.z2):
+ vel_actual = (0, 600, 0, 900)
+
+
+ # para evitar envios de velocidad innecesarios al robot
+ if not(vel_actual == self.vel_anterior):
+ self.vel_anterior = vel_actual
+ self.butia.set2MotorSpeed(str(vel_actual[0]), str(vel_actual[1]), str(vel_actual[2]), str(vel_actual[3]))
+
+