1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# FollowMe Butia - Main
# Copyright (C) 2010-2013
# 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>
import gtk
import pygame
from robot import Robot
from followme import FollowMe
class Main:
def __init__(self, parent):
self.parent = parent
self.clock = pygame.time.Clock()
self.calibrating = True
self.show_size = (960.0, 720.0)
self.r = None
self.c = None
def mode_calibrating(self, calibrating):
self.calibrating = calibrating
if self.calibrating:
if (self.r != None and self.r.modules != []):
self.r.stop_robot()
def put_threshold(self, threshold):
self.threshold = threshold
def put_colorC(self, colorC):
if (self.calibrating == False):
self.colorC = colorC
def put_pixels(self, pixels):
self.pixels = pixels
def put_show_size(self, show_size):
self.show_size = show_size
self.c.calc(self.show_size)
def put_grid(self, grid):
self.c.show_grid = grid
def put_color_mode(self, mode):
self.mode = mode
self.c.get_camera(self.mode)
def put_threshold_view(self, view):
self.c.use_threshold_view = view
def put_outline_view(self, outline):
self.c.use_outline_view = outline
def put_rects_view(self, rects):
self.c.use_rects_view = rects
def put_brightness(self, brightness):
self.c.brightness = brightness
self.c.set_camera_flags()
def run(self):
self.r = Robot((320, 240))
self.threshold = (25, 25, 25)
self.colorC = (255, 255, 255)
self.pixels = 10
self.show_size = (960, 720)
self.mode = 'RGB'
self.c = FollowMe(self.parent)
if (self.c.cam == None):
while gtk.events_pending():
gtk.main_iteration()
for event in pygame.event.get():
if event.type == pygame.QUIT:
break
else:
run = True
while run:
while gtk.events_pending():
gtk.main_iteration()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if (self.calibrating):
self.colorC = self.c.calibrate()
if self.parent:
self.parent.put_color(self.colorC)
else:
mask, pos = self.c.get_position(self.colorC, self.threshold, self.pixels)
self.c.generate_capture_to_show()
self.c.show_centroid_position(pos)
if self.c.use_outline_view:
self.c.show_outline(mask)
if self.c.use_rects_view:
self.c.show_rects(mask)
self.c.show_in_screen(self.colorC)
if (self.r != None and self.r.modules != []):
self.r.move_robot(pos)
pygame.display.flip()
self.clock.tick(10)
self.c.stop_camera()
if self.r:
if self.r.butia:
self.r.butia.close()
self.r.butia.closeService()
if self.r.bobot:
self.r.bobot.kill()
|